# clonepathwith

> ## Installation

Latest version **1.1.1** (published 2021-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install clonepathwith
pnpm add clonepathwith
yarn add clonepathwith
bun add clonepathwith
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-07-13 |
| First published | 2021-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 4.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dellord |
| Maintainers | dellord |

## Links

- npm: https://www.npmjs.com/package/clonepathwith
- Repository: https://github.com/Dellord/clonePathWith
- Homepage: https://github.com/Dellord/clonePathWith#readme
- Issues: https://github.com/Dellord/clonePathWith/issues
- npm.io page: https://npm.io/package/clonepathwith

## Dependencies (2)

- [lodash.clone](https://npm.io/package/lodash.clone.md) ^4.5.0
- [lodash.topath](https://npm.io/package/lodash.topath.md) ^4.5.2

## Recent versions

- 1.1.1 (latest) — 2021-07-13
- 1.0.1 — 2021-02-21
- 1.0.0 — 2021-02-21

## README

# clonePathWith

## Installation

Using npm:
```shell
$ npm i clonepathwith --save
```

## Usage
#### Simple clone
```js
import clonePathWith from 'clonepathwith';

let someObject = {someArray:[], innerObject: {text: 'Hello World!'}};
let clone = clonePathWith(someObject, 'innerObject.text');
console.log(clone === someObject); // false
console.log(clone.someArray === someObject.someArray); // true
console.log(clone.innerObject === someObject.innerObject); // false
```
#### Updated clone
```js
import clonePathWith from 'clonepathwith';

let helloWorldObject = {
    before: {text: 'before'},
    hello: {world: {text: 'Hello'}},
    after: {text: 'after'}
};

let clone = clonePathWith(helloWorldObject, 'hello.world.text', (text) => {
    return text + ' World!';
});

console.log(clone.before === helloWorldObject.before); // true
console.log(clone.after === helloWorldObject.after); // true

console.log(clone === helloWorldObject); // false
console.log(clone.hello === helloWorldObject.hello); // false
console.log(clone.hello.world === helloWorldObject.hello.world); // false
console.log(clone.hello.world.text); // Hello World!
console.log(helloWorldObject.hello.world.text); // Hello
```
#### Create Object
```js
let create = clonePathWith({}, 'hello.world.text', () => {
    return 'Hello World!';
});
console.log(create.hello.world.text); // Hello World!
```
#### Push to arrays
```js
let someObject = {someArray:[1]};
let push = clonePathWith(someObject, 'someArray', (someArray) => {
    return [...someArray, 2]
});
console.log(push.someArray); // [1,2]
console.log(push === someObject); // false
console.log(push.someArray === someObject.someArray); // false
```
#### Replace arrays
```js
let someObject = {someArray:[1,2,3]};
let replace = clonePathWith(someObject, 'someArray[1]', (someArray1) => {
    return someArray1 + 3;
});
console.log(replace.someArray); // [1,5,3]
console.log(replace === someObject); // false
console.log(replace.someArray === someObject.someArray); // false
```

---
_Source: https://npm.io/package/clonepathwith · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
