]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/object/serialize.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / node-gyp / node_modules / path-array / node_modules / array-index / node_modules / es6-symbol / node_modules / es5-ext / object / serialize.js
1 'use strict';
2
3 var toArray  = require('./to-array')
4   , isDate   = require('../date/is-date')
5   , isRegExp = require('../reg-exp/is-reg-exp')
6
7   , isArray = Array.isArray, stringify = JSON.stringify
8   , keyValueToString = function (value, key) { return stringify(key) + ':' + exports(value); };
9
10 var sparseMap = function (arr) {
11         var i, l = arr.length, result = new Array(l);
12         for (i = 0; i < l; ++i) {
13                 if (!arr.hasOwnProperty(i)) continue;
14                 result[i] = exports(arr[i]);
15         }
16         return result;
17 };
18
19 module.exports = exports = function (obj) {
20         if (obj == null) return String(obj);
21         switch (typeof obj) {
22         case 'string':
23                 return stringify(obj);
24         case 'number':
25         case 'boolean':
26         case 'function':
27                 return String(obj);
28         case 'object':
29                 if (isArray(obj)) return '[' + sparseMap(obj) + ']';
30                 if (isRegExp(obj)) return String(obj);
31                 if (isDate(obj)) return 'new Date(' + obj.valueOf() + ')';
32                 return '{' + toArray(obj, keyValueToString) + '}';
33         default:
34                 throw new TypeError("Serialization of " + String(obj) + "is unsupported");
35         }
36 };