1
头图

github address: musk-clone

npm address: musk-clone

musk-clone

Generates simulated shadow clones with the same data structure at the same speed as Elon Musk.

Tesla CEO Elon Musk has 9 children, says he's doing his part to increase U.S. fertility

Why use musk-clone?

When you want to make a new simulation project with the same data structure as an existing one, you have to copy --> modify one by one --> paste , which takes a lot of time.

Now you can use musk-clone to save your time!

characteristic

According to the incoming data, quickly generate a data of the same data structure, which is used to quickly construct mock data in the development stage

  • source mainly supports the two most common types, object types and array types, and supports deep nesting
  • Converts only the basic types string, number, boolean, the rest return the original value with the new memory address

Install

 yarn add -D musk-clone

use

basic use

 import muskClone from 'musk-clone'

const src = ["foo", 1, true]
const target = muskClone(src);
console.log(target); 
// ["foo-0v3DrX7hoOqIFaQeMDDaF", 71, true],

Common scenarios

 import muskClone from 'musk-clone'

const src = [
  { foo: "str", bar: 1, val: true },
  { foo: "str1", bar: 2, val: false },
]
const target = muskClone(src);
console.log(target); 
// [
//   { foo: "str-jHGKjWz3kz0ome5-tl6MS", bar: 36, val: false },
//   { foo: "str1-LqOPbB5xXYKXV8hmBB_Q6", bar: 2, val: true }
// ]

API

muskClone(source)

source

  • {[key: string]: any} | Array<{[key: string]: any}>

Example

array

 ["foo", 1, true]
=>

["foo-0v3DrX7hoOqIFaQeMDDaF", 71, false]

object

 { 
  foo: "str", 
  bar: 1, 
  val: true 
}
=>

{
  foo: "str-I5s0VjK7209eBqV6QYUeJ",
  bar: 68,
  val: true
}

array of objects

 [
  { 
    foo: "str", 
    bar: 1, 
    val: true 
  }
]
=>
[
  {
    foo: "str-eALWWUK2tsA6sn_aSAB3I",
    bar: 38,
    val: false
  }
]

complex nested data structures

 [
  { 
    foo: "str", 
    bar: 1, 
    val: true, 
    nest: [
      { 
        baz: 2 
      }
    ] 
  }
]
=>
[
  {
    foo: "str-67nhBc5A9cDZl3dQ7L48c",
    bar: 42,
    val: true,
    nest: [
      {
        baz: 74
      }
    ]
  }
]

other

Welcome to submit PR and issue

License

MIT .


趁你还年轻
4.1k 声望4.1k 粉丝