Skip to content

Commit 2145eed

Browse files
skyhAndrey Ivlev
authored andcommitted
Merge pull request #1 from hola/skyh-patch-1
Add AMD support
2 parents e43ca2a + 4fe5a81 commit 2145eed

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

index.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');
2-
3-
module.exports = function (obj, opts) {
1+
define([], function(){
2+
'use strict';
3+
var json = JSON;
4+
var E = function (obj, opts) {
45
if (!opts) opts = {};
56
if (typeof opts === 'function') opts = { cmp: opts };
67
var space = opts.space || '';
@@ -35,7 +36,7 @@ module.exports = function (obj, opts) {
3536
if (typeof node !== 'object' || node === null) {
3637
return json.stringify(node);
3738
}
38-
if (isArray(node)) {
39+
if (Array.isArray(node)) {
3940
var out = [];
4041
for (var i = 0; i < node.length; i++) {
4142
var item = stringify(node, i, node[i], level+1) || json.stringify(null);
@@ -50,7 +51,7 @@ module.exports = function (obj, opts) {
5051
}
5152
else seen.push(node);
5253

53-
var keys = objectKeys(node).sort(cmp && cmp(node));
54+
var keys = Object.keys(node).sort(cmp && cmp(node));
5455
var out = [];
5556
for (var i = 0; i < keys.length; i++) {
5657
var key = keys[i];
@@ -61,7 +62,6 @@ module.exports = function (obj, opts) {
6162
var keyValue = json.stringify(key)
6263
+ colonSeparator
6364
+ value;
64-
;
6565
out.push(indent + space + keyValue);
6666
}
6767
seen.splice(seen.indexOf(node), 1);
@@ -70,15 +70,4 @@ module.exports = function (obj, opts) {
7070
})({ '': obj }, '', obj, 0);
7171
};
7272

73-
var isArray = Array.isArray || function (x) {
74-
return {}.toString.call(x) === '[object Array]';
75-
};
76-
77-
var objectKeys = Object.keys || function (obj) {
78-
var has = Object.prototype.hasOwnProperty || function () { return true };
79-
var keys = [];
80-
for (var key in obj) {
81-
if (has.call(obj, key)) keys.push(key);
82-
}
83-
return keys;
84-
};
73+
return E; });

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-stable-stringify",
3-
"version": "1.0.1",
3+
"version": "1.0.1-hola.0",
44
"description": "deterministic JSON.stringify() with custom sorting to get deterministic hashes from stringified results",
55
"main": "index.js",
66
"dependencies": {

0 commit comments

Comments
 (0)