Skip to content

Commit

Permalink
remove fast-stable-stringify (#5154)
Browse files Browse the repository at this point in the history
closes #5152
  • Loading branch information
mourner authored and willwhite committed Sep 9, 2017
1 parent daea811 commit d0fac91
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
37 changes: 30 additions & 7 deletions src/style-spec/group_by_layout.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
'use strict';

const refProperties = require('./util/ref_properties'),
stringify = require('fast-stable-stringify');
const refProperties = require('./util/ref_properties');

function key(layer) {
return stringify(refProperties.map((k) => {
return layer[k];
}));
function stringify(obj) {
const type = typeof obj;
if (type === 'number' || type === 'string' || obj === undefined || obj === null)
return JSON.stringify(obj);

if (Array.isArray(obj)) {
let str = '[';
for (const val of obj) {
str += `${stringify(val)},`;
}
return `${str}]`;
}

const keys = Object.keys(obj).sort();

let str = '{';
for (let i = 0; i < keys.length; i++) {
str += `${JSON.stringify(keys[i])}:${stringify(obj[keys[i]])},`;
}
return `${str}}`;
}

function getKey(layer) {
let key = '';
for (const k of refProperties) {
key += `/${stringify(layer[k])}`;
}
return key;
}

module.exports = groupByLayout;
Expand All @@ -29,7 +52,7 @@ function groupByLayout(layers) {
const groups = {};

for (let i = 0; i < layers.length; i++) {
const k = key(layers[i]);
const k = getKey(layers[i]);
let group = groups[k];
if (!group) {
group = groups[k] = [];
Expand Down
1 change: 0 additions & 1 deletion src/style-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"dependencies": {
"csscolorparser": "~1.0.2",
"fast-stable-stringify": "^0.1.1",
"jsonlint-lines-primitives": "~1.6.0",
"lodash.isequal": "^3.0.4",
"minimist": "0.0.8",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2682,7 +2682,7 @@ glob-stream@^5.3.2:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^5.0.3:
glob@^5.0.14, glob@^5.0.3:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
dependencies:
Expand Down

0 comments on commit d0fac91

Please sign in to comment.