Skip to content

Add AMD support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 7 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');

module.exports = function (obj, opts) {
define([], function(){
'use strict';
var json = JSON;
var E = function (obj, opts) {
if (!opts) opts = {};
if (typeof opts === 'function') opts = { cmp: opts };
var space = opts.space || '';
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = function (obj, opts) {
if (typeof node !== 'object' || node === null) {
return json.stringify(node);
}
if (isArray(node)) {
if (Array.isArray(node)) {
var out = [];
for (var i = 0; i < node.length; i++) {
var item = stringify(node, i, node[i], level+1) || json.stringify(null);
Expand All @@ -50,7 +51,7 @@ module.exports = function (obj, opts) {
}
else seen.push(node);

var keys = objectKeys(node).sort(cmp && cmp(node));
var keys = Object.keys(node).sort(cmp && cmp(node));
var out = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
Expand All @@ -61,7 +62,6 @@ module.exports = function (obj, opts) {
var keyValue = json.stringify(key)
+ colonSeparator
+ value;
;
out.push(indent + space + keyValue);
}
seen.splice(seen.indexOf(node), 1);
Expand All @@ -70,15 +70,4 @@ module.exports = function (obj, opts) {
})({ '': obj }, '', obj, 0);
};

var isArray = Array.isArray || function (x) {
return {}.toString.call(x) === '[object Array]';
};

var objectKeys = Object.keys || function (obj) {
var has = Object.prototype.hasOwnProperty || function () { return true };
var keys = [];
for (var key in obj) {
if (has.call(obj, key)) keys.push(key);
}
return keys;
};
return E; });