rfc6902-ordered
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "rfc6902-ordered", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "https://github.com/chbrown/rfc6902 plus object key ordering", | ||
@@ -32,6 +32,6 @@ "main": "src/index.js", | ||
"eslint": "^4.6.1", | ||
"eslint-config-sane": "^0.1.0", | ||
"eslint-config-sane": "^0.2.0", | ||
"eslint-plugin-mocha": "^4.11.0", | ||
"mocha": "^3.5.1" | ||
"mocha": "^4.0.0" | ||
} | ||
} |
'use strict'; | ||
const rfc6902 = require('rfc6902'); | ||
const addToObjectAtIndex = require('./add-to-object-at-index'); | ||
const _applyPatch = rfc6902.applyPatch; | ||
module.exports = rfc6902; | ||
function addToObjectAtIndex(obj, key, value, index) { | ||
let result = {}; | ||
let keys = Object.keys(obj); | ||
for (let i = 0; i < keys.length; i++) { | ||
if (i === index) { | ||
result[key] = value; | ||
} | ||
let k = keys[i]; | ||
result[k] = obj[k]; | ||
} | ||
if (index === keys.length) { | ||
result[key] = value; | ||
} | ||
// mutate the original object because it we like that | ||
// it is already linked somewhere in the package.json tree | ||
for (let key in obj) { | ||
delete obj[key]; | ||
} | ||
for (let key in result) { | ||
obj[key] = result[key]; | ||
} | ||
} | ||
function get(obj, parts) { | ||
@@ -42,3 +14,3 @@ return parts.reduce((total, next) => { | ||
module.exports.applyPatch = function applyPatch(myPackageJson, patch, toPackageJson) { | ||
function applyPatch(myPackageJson, patch, toPackageJson) { | ||
if (arguments.length > 2) { | ||
@@ -94,2 +66,5 @@ patch = patch.slice(); | ||
return _applyPatch.call(this, myPackageJson, patch); | ||
}; | ||
} | ||
module.exports = rfc6902; | ||
module.exports.applyPatch = applyPatch; |
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
5667
5
76