|
| 1 | +<br> |
| 2 | +<div align="center"> |
| 3 | + |
| 4 | +<p align="center">Deeply extend JSON-safe objects ~300B</p> |
| 5 | + |
| 6 | +<p align="center"> |
| 7 | + <a aria-label="overview" href="https://github.com/techor-dev/techor"> |
| 8 | + <picture> |
| 9 | + <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=212022&style=for-the-badge"> |
| 10 | + <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=f6f7f8&style=for-the-badge"> |
| 11 | + <img alt="NPM Version" src="https://img.shields.io/badge/%E2%AC%85%20back-%20?color=f6f7f8&style=for-the-badge"> |
| 12 | + </picture> |
| 13 | + </a> |
| 14 | + <a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/techor-dev/techor/releases"> |
| 15 | + <picture> |
| 16 | + <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/v/release/techor-dev/techor?include_prereleases&color=212022&label=&style=for-the-badge&logo=github&logoColor=fff"> |
| 17 | + <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/v/release/techor-dev/techor?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github&logoColor=%23000"> |
| 18 | + <img alt="NPM Version" src="https://img.shields.io/github/v/release/techor-dev/techor?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github"> |
| 19 | + </picture> |
| 20 | + </a> |
| 21 | + <a aria-label="NPM Package" href="https://www.npmjs.com/package/json-safe-extend"> |
| 22 | + <picture> |
| 23 | + <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/json-safe-extend?color=212022&label=%20&logo=npm&style=for-the-badge"> |
| 24 | + <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dm/json-safe-extend?color=f6f7f8&label=%20&logo=npm&style=for-the-badge"> |
| 25 | + <img alt="NPM package ( download / month )" src="https://img.shields.io/npm/dm/json-safe-extend?color=f6f7f8&label=%20&logo=npm&style=for-the-badge"> |
| 26 | + </picture> |
| 27 | + </a> |
| 28 | + <a aria-label="Follow @aron1tw" href="https://twitter.com/aron1tw"> |
| 29 | + <picture> |
| 30 | + <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=212022&logo=twitter&style=for-the-badge"> |
| 31 | + <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge"> |
| 32 | + <img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge"> |
| 33 | + </picture> |
| 34 | + </a> |
| 35 | + <a aria-label="Github Actions" href="https://github.com/techor-dev/techor/actions/workflows/release.yml"> |
| 36 | + <picture> |
| 37 | + <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/techor-dev/techor/release.yml?branch=main&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge"> |
| 38 | + <source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/techor-dev/techor/release.yml?branch=main&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000"> |
| 39 | + <img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/techor-dev/techor/release.yml?branch=main&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000"> |
| 40 | + </picture> |
| 41 | + </a> |
| 42 | +</p> |
| 43 | + |
| 44 | +</div> |
| 45 | + |
| 46 | +<br> |
| 47 | + |
| 48 | +- Deeply extend |
| 49 | +- JSON-safe |
| 50 | +- Supports `Symbol` |
| 51 | + |
| 52 | +<br> |
| 53 | + |
| 54 | +## Getting Started |
| 55 | + |
| 56 | +```bash |
| 57 | +npm install json-safe-extend |
| 58 | +``` |
| 59 | + |
| 60 | +## Usage |
| 61 | +```js |
| 62 | +import extend from 'json-safe-extend' |
| 63 | + |
| 64 | +extend({ a: 1, b:2 }, { b: null, c:3 }) |
| 65 | +// { a:1, b: null, c:3 } |
| 66 | +``` |
| 67 | + |
| 68 | +## Overview |
| 69 | +```js |
| 70 | +expect( |
| 71 | + extend( |
| 72 | + { |
| 73 | + a: 1, |
| 74 | + b: 2, |
| 75 | + d: { |
| 76 | + a: 1, |
| 77 | + b: [], |
| 78 | + c: { test1: 123, test2: 321 } |
| 79 | + }, |
| 80 | + f: 5, |
| 81 | + g: 123, |
| 82 | + i: 321, |
| 83 | + j: [1, 2] |
| 84 | + }, |
| 85 | + { |
| 86 | + b: 3, |
| 87 | + c: 5, |
| 88 | + d: { |
| 89 | + b: { first: 'one', second: 'two' }, |
| 90 | + c: { test2: 222 } |
| 91 | + }, |
| 92 | + e: { one: 1, two: 2 }, |
| 93 | + f: [], |
| 94 | + g: (void 0), |
| 95 | + i: null, |
| 96 | + j: [3, 4] |
| 97 | + } |
| 98 | + ) |
| 99 | +) |
| 100 | + .toEqual({ |
| 101 | + a: 1, |
| 102 | + b: 3, |
| 103 | + d: |
| 104 | + { |
| 105 | + a: 1, |
| 106 | + b: { first: 'one', second: 'two' }, |
| 107 | + c: { test1: 123, test2: 222 } |
| 108 | + }, |
| 109 | + f: [], |
| 110 | + g: undefined, |
| 111 | + c: 5, |
| 112 | + e: { one: 1, two: 2 }, |
| 113 | + i: null, |
| 114 | + j: [3, 4] |
| 115 | + }) |
| 116 | +``` |
0 commit comments