@eramux/rekey
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -1,4 +0,3 @@ | ||
import { RekeyObject } from "./rekey"; | ||
export declare function renameKey(object: RekeyObject, key: string, value: string): void; | ||
export declare function deleteKey(object: RekeyObject, key: string): void; | ||
export declare function renameKey(object: Object, selector: string, value: string): void; | ||
export declare function deleteKey(object: Object, selector: string): void; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,12 +5,12 @@ "use strict"; | ||
const rekey_1 = require("./rekey"); | ||
function renameKey(object, key, value) { | ||
let keys = key.split('.'); | ||
rekey_1.recursiveRename(object, keys, value); | ||
function renameKey(object, selector, value) { | ||
let selectorArray = selector.split('.'); | ||
rekey_1.recursiveRename(object, selectorArray, value); | ||
} | ||
exports.renameKey = renameKey; | ||
function deleteKey(object, key) { | ||
let keys = key.split('.'); | ||
rekey_1.recursiveDelete(object, keys); | ||
function deleteKey(object, selector) { | ||
let selectorArray = selector.split('.'); | ||
rekey_1.recursiveDelete(object, selectorArray); | ||
} | ||
exports.deleteKey = deleteKey; | ||
//# sourceMappingURL=index.js.map |
@@ -5,6 +5,6 @@ declare type KeyTraversalCallback = (workingObject: RekeyObject, currentSelector: string) => void; | ||
} | ||
export declare function recursiveRename(workingObject: RekeyObject, selector: Array<string>, value: string): void; | ||
export declare function recursiveDelete(workingObject: RekeyObject, selector: Array<string>): void; | ||
export declare function recursiveKeyTraversal(workingObject: RekeyObject, selectors: Array<string>, callback: KeyTraversalCallback): void; | ||
export declare function recursiveRename(workingObject: Object, selector: Array<string>, value: string): void; | ||
export declare function recursiveDelete(workingObject: Object, selector: Array<string>): void; | ||
export declare function recursiveKeyTraversal(workingObject: Object, selectors: Array<string>, callback: KeyTraversalCallback): void; | ||
export {}; | ||
//# sourceMappingURL=rekey.d.ts.map |
@@ -5,5 +5,8 @@ "use strict"; | ||
function recursiveRename(workingObject, selector, value) { | ||
recursiveKeyTraversal(workingObject, selector, (object, currentSelector) => { | ||
object[value] = object[currentSelector]; | ||
delete object[currentSelector]; | ||
recursiveKeyTraversal(workingObject, selector, (object, lastSelector) => { | ||
let keyValue = Object.getOwnPropertyDescriptor(object, lastSelector); | ||
if (keyValue !== undefined) { | ||
Object.defineProperty(object, value, keyValue); | ||
delete object[lastSelector]; | ||
} | ||
}); | ||
@@ -13,4 +16,4 @@ } | ||
function recursiveDelete(workingObject, selector) { | ||
recursiveKeyTraversal(workingObject, selector, (object, currentSelector) => { | ||
delete object[currentSelector]; | ||
recursiveKeyTraversal(workingObject, selector, (object, lastSelector) => { | ||
delete object[lastSelector]; | ||
}); | ||
@@ -20,3 +23,2 @@ } | ||
function recursiveKeyTraversal(workingObject, selectors, callback) { | ||
let remainingSelectors = selectors.slice(1); | ||
if (workingObject instanceof Array && workingObject !== null) { | ||
@@ -36,5 +38,3 @@ workingObject = workingObject.map((item) => { | ||
} | ||
else { | ||
recursiveKeyTraversal(workingObject[currentSelector], remainingSelectors, callback); | ||
} | ||
recursiveKeyTraversal(workingObject[currentSelector], selectors.slice(1), callback); | ||
} | ||
@@ -41,0 +41,0 @@ } |
{ | ||
"name": "@eramux/rekey", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "A simple and performant library to rename object keys", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
7335
62