clone-rename
Deep clone your object and rename the key.
Get start
> npm install clone-rename
Usage
Used when the data returned by the back end is inconsistent with the property name used by the front end.
Example
The current backend separation assumes that the item information is displayed when you use the goodsID and goodsName properties and the backend provides the id and name
just use clone-rename to change the attribute name
Array
; const res = id: '001' name: 'apple' id: '002' name: 'banana' const filter = id:'goodsID' // Rename all attribute id to goodsID. name: 'goodsName' // Rename all attribute name to goodsName. const result = // deep copy /*result:[ { goodsID: '001', goodsName: 'apple' }, { goodsID: '002', goodsName: 'banana' }]*/
Object
It also can change the object。
; let project = name:'JavaScript' let obj = name:'PsChina' age:'25' like:project const filter = name:'babel' // Rename all key name to Babel. const result1 = // default deepCopy & deepRename both true/*result1:{ babel:'PsChina', age:'25', like:[{babel:'JavaScript'}]}*/result1like0 === project // false
Shallow copy
const result2 = /*result2:{ babel:'PsChina', age:'25', like:[{name:'JavaScript'}]}*/ result2like0 === project // true
Shallow rename
const result3 = /*result3:{ babel:'PsChina', age:'25', like:[{name:'JavaScript'}]}*/result3like0 === project // false
Copy
It also helps you copy objects that contain Date RegExp and Function objects.
Date
let time = ; let sameTime = ; console;// <currentTime> <currentTime> false
Function
{ return a + b;}; let sameSum = ; ;//3 ;//3 console;//false
RgeExp
let numberRegObj = reg:/[0-9]/; let newRegObj = ; console;// {reg:/[0-9]/} {reg:/[0-9]/} false