alphabetize-object
Advanced tools
Comparing version 1.0.0 to 2.0.0
'use strict'; | ||
const alphabetizeObjectKeys = function (object, opts) { | ||
const alphabetizeObject = function (object, opts) { | ||
opts = opts || {}; | ||
@@ -24,3 +24,3 @@ const keys = []; | ||
if (typeof dest[key] === 'object') { | ||
dest[key] = alphabetizeObjectKeys(dest[key], opts); | ||
dest[key] = alphabetizeObject(dest[key], opts); | ||
} | ||
@@ -35,2 +35,2 @@ } | ||
module.exports = alphabetizeObjectKeys; | ||
module.exports = alphabetizeObject; |
{ | ||
"name": "alphabetize-object", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "alphabetize keys in an object", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
73
test.js
'use strict'; | ||
const alphabetizeObjectKeys = require('./index'); | ||
const alphabetizeObject = require('./index'); | ||
const assert = require('assert'); | ||
describe('alphabetizeObjectKeys', function () { | ||
describe('alphabetizeObject', function () { | ||
it('should sort a generic object', function () { | ||
@@ -14,3 +14,3 @@ const object = { | ||
}; | ||
const newObj = alphabetizeObjectKeys(object); | ||
const newObj = alphabetizeObject(object); | ||
assert.deepEqual(newObj, { | ||
@@ -35,3 +35,3 @@ a: 3, | ||
}; | ||
const newObj = alphabetizeObjectKeys(object, { recursive: true }); | ||
const newObj = alphabetizeObject(object, { recursive: true }); | ||
assert.deepEqual(newObj, { | ||
@@ -48,2 +48,67 @@ a: 3, | ||
}); | ||
it('should leave the original object alone', function () { | ||
const object = { | ||
b: 1, | ||
d: 2, | ||
a: 3, | ||
c: 4 | ||
}; | ||
const newObj = alphabetizeObject(object); | ||
assert.deepEqual(newObj, { | ||
b: 1, | ||
d: 2, | ||
a: 3, | ||
c: 4 | ||
}); | ||
}); | ||
it('should leave modify the original object if inPlace is true', function () { | ||
const object = { | ||
b: 1, | ||
d: 2, | ||
a: 3, | ||
c: 4 | ||
}; | ||
const newObj = alphabetizeObject(object, { inPlace: true }); | ||
assert.deepEqual(object, { | ||
a: 3, | ||
b: 1, | ||
c: 4, | ||
d: 2 | ||
}); | ||
}); | ||
it('should be case sensitive', function () { | ||
const object = { | ||
b: 1, | ||
B: 2, | ||
a: 3, | ||
A: 4 | ||
}; | ||
const newObj = alphabetizeObject(object); | ||
assert.deepEqual(newObj, { | ||
A: 4, | ||
B: 2, | ||
a: 3, | ||
b: 1 | ||
}); | ||
}); | ||
it('should be case insensitive if caseInsensitive is true', function () { | ||
const object = { | ||
B: 1, | ||
b: 2, | ||
a: 3, | ||
A: 4 | ||
}; | ||
const newObj = alphabetizeObject(object, { caseInsensitive: true }); | ||
assert.deepEqual(newObj, { | ||
A: 4, | ||
a: 3, | ||
B: 1, | ||
b: 2 | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
4987
6
135
1
22