This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="1.0.0"></a>
# [1.0.0](https://github.com/jsless/defu/compare/v0.0.4...v1.0.0) (2020-02-02)
<a name="0.0.4"></a>
## [0.0.4](https://github.com/jsless/defu/compare/v0.0.3...v0.0.4) (2020-01-01)
### Bug Fixes
* improve es5 compatibility ([#2](https://github.com/jsless/defu/issues/2), [#9](https://github.com/jsless/defu/issues/9)) ([5a6de7c](https://github.com/jsless/defu/commit/5a6de7c))
<a name="0.0.3"></a>
## [0.0.3](https://github.com/jsless/defu/compare/v0.0.1...v0.0.3) (2019-05-25)
<a name="0.0.2"></a>
## [0.0.2](https://github.com/jesless/defu/compare/v0.0.1...v0.0.2) (2019-05-25)
<a name="0.0.1"></a>
## 0.0.1 (2019-02-07)
### Bug Fixes
* imrpove non-object handlers ([f89fa28](https://github.com/jesless/defu/commit/f89fa28))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 - Pooya Parsa <pooya@pi0.ir>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+80
View File
@@ -0,0 +1,80 @@
# 🇩 defu
> Recursively assign default properties. Lightweight and Fast!
[![Standard JS][standard-src]][standard-href]
[![david dm][david-src]][david-href]
[![codecov][codecov-src]][codecov-href]
[![circleci][circleci-src]][circleci-href]
[![npm version][npm-v-src]][npm-v-href]
[![npm downloads][npm-dt-src]][npm-dt-href]
[![package phobia][packagephobia-src]][packagephobia-href]
[![bundle phobia][bundlephobia-src]][bundlephobia-href]
## Install
Install package:
```bash
npm install defu
```
OR
```bash
yarn add defu
```
## Usage
```js
const options = defu (object, defaults)
```
### Arguments
- **object (Object):** The destination object.
- **source (Object):** The source object.
```js
const defu = require('defu')
console.log(defu({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }))
// => { a: { b: 2, c: 3 } }
```
### Remarks
- `object` and `defaults` are not modified
- Assignment of `__proto__` and `constructor` keys will be skipped to prevent security issues with object pollution.
## License
MIT. Made with 💖
<!-- Refs -->
[standard-src]: https://flat.badgen.net/badge/code%20style/standard/green
[standard-href]: https://standardjs.com
[npm-v-src]: https://flat.badgen.net/npm/v/defu/latest
[npm-v-href]: https://npmjs.com/package/defu
[npm-dt-src]: https://flat.badgen.net/npm/dt/defu
[npm-dt-href]: https://npmjs.com/package/defu
[packagephobia-src]: https://flat.badgen.net/packagephobia/install/defu
[packagephobia-href]: https://packagephobia.now.sh/result?p=defu
[bundlephobia-src]: https://flat.badgen.net/bundlephobia/min/defu
[bundlephobia-href]: https://bundlephobia.com/result?p=defu
[david-src]: https://flat.badgen.net/david/dep/jsless/defu
[david-href]: https://david-dm.org/jsless/defu
[codecov-src]: https://flat.badgen.net/codecov/c/github/jsless/defu/master
[codecov-href]: https://codecov.io/gh/jsless/defu
[circleci-src]: https://flat.badgen.net/circleci/github/jsless/defu/master
[circleci-href]: https://circleci.com/gh/jsless/defu
+35
View File
@@ -0,0 +1,35 @@
function isObject (val) {
return val !== null && typeof val === 'object' && !Array.isArray(val)
}
function defu (_obj, _defaults) {
if (!isObject(_obj)) {
return defu({}, _defaults)
}
if (!isObject(_defaults)) {
return defu(_obj, {})
}
var obj = Object.assign({}, _defaults)
Object.keys(_obj).forEach(function (key) {
if (key === '__proto__' || key === 'constructor') {
return
}
var val = _obj[key]
if (val === null) {
return
}
if (isObject(val) && isObject(obj[key])) {
obj[key] = defu(val, obj[key])
} else {
obj[key] = val
}
})
return obj
}
module.exports = defu
+68
View File
@@ -0,0 +1,68 @@
{
"_args": [
[
"defu@1.0.0",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "defu@1.0.0",
"_id": "defu@1.0.0",
"_inBundle": false,
"_integrity": "sha512-1Y1KRFxiiq+LYsZ3iP7xYSR8bHfmHFOUpDunZCN1ld1fGfDJWJIvkUBtjl3apnBwPuJtL/H7cwwlLYX8xPkraQ==",
"_location": "/serve-placeholder/defu",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "defu@1.0.0",
"name": "defu",
"escapedName": "defu",
"rawSpec": "1.0.0",
"saveSpec": null,
"fetchSpec": "1.0.0"
},
"_requiredBy": [
"/serve-placeholder"
],
"_resolved": "https://registry.npmjs.org/defu/-/defu-1.0.0.tgz",
"_spec": "1.0.0",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"bugs": {
"url": "https://github.com/jsless/defu/issues"
},
"contributes": [
"Pooya Parsa <pooya@pi0.ir>"
],
"description": "Recursively assign default properties. Lightweight and Fast!",
"devDependencies": {
"codecov": "^3.1.0",
"eslint": "^5.9.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.1.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.0.0",
"standard-version": "^4.4.0"
},
"files": [
"lib"
],
"homepage": "https://github.com/jsless/defu#readme",
"license": "MIT",
"main": "lib/index.js",
"name": "defu",
"repository": {
"type": "git",
"url": "git+https://github.com/jsless/defu.git"
},
"scripts": {
"jest": "jest",
"lint": "eslint lib",
"prepare": "npm run test",
"release": "standard-version && git push --follow-tags && npm publish",
"test": "npm run lint && npm run jest"
},
"version": "1.0.0"
}