‘首次‘
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
# Changelog
|
||||
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
Every release is documented on the Github [Releases](https://github.com/robinvdvleuten/shvl/releases) page.
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Robin van der Vleuten <robin@webstronauts.co>
|
||||
|
||||
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.
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
# shvl
|
||||
|
||||
Get and set dot-notated properties within an object.
|
||||
|
||||
<img src="https://media.giphy.com/media/3o85xLDQLoZD1rk07u/giphy-downsized.gif" width="350" />
|
||||
|
||||
<hr />
|
||||
|
||||
[](https://github.com/robinvdvleuten/shvl/actions?query=workflow%3Atest)
|
||||
[](https://www.npmjs.com/package/shvl)
|
||||
[](https://www.npmjs.com/package/shvl)
|
||||
[](https://github.com/robinvdvleuten/shvl/blob/master/LICENSE)
|
||||
|
||||
[](http://makeapullrequest.com)
|
||||
|
||||
<a href="https://webstronauts.com/">
|
||||
<img src="https://webstronauts.com/badges/sponsored-by-webstronauts.svg" alt="Sponsored by The Webstronauts" width="200" height="65">
|
||||
</a>
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install --save shvl
|
||||
```
|
||||
|
||||
The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com/shvl/dist/shvl.umd.js):
|
||||
|
||||
```
|
||||
<script src="//unpkg.com/shvl/dist/shvl.umd.js"></script>
|
||||
```
|
||||
|
||||
This exposes the shlv object as a global.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import * as shvl from 'shvl';
|
||||
|
||||
let obj = {
|
||||
a: {
|
||||
b: {
|
||||
c: 1
|
||||
d: undefined
|
||||
e: null
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Use dot notation for keys
|
||||
shvl.set(obj, 'a.b.c', 2);
|
||||
shvl.get(obj, 'a.b.c') === 2;
|
||||
|
||||
// Or use an array as key
|
||||
shvl.get(obj, ['a', 'b', 'c']) === 1;
|
||||
|
||||
// Returns undefined if the path does not exist and no default is specified
|
||||
shvl.get(obj, 'a.b.c.f') === undefined;
|
||||
```
|
||||
|
||||
## Changelog
|
||||
|
||||
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
|
||||
|
||||
## Contributors ✨
|
||||
|
||||
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- markdownlint-disable -->
|
||||
<table>
|
||||
<tr>
|
||||
<td align="center"><a href="https://robinvdvleuten.nl/"><img src="https://avatars3.githubusercontent.com/u/238295?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Robin van der Vleuten</b></sub></a><br /><a href="#question-robinvdvleuten" title="Answering Questions">💬</a> <a href="https://github.com/robinvdvleuten/shvl/commits?author=robinvdvleuten" title="Code">💻</a> <a href="https://github.com/robinvdvleuten/shvl/commits?author=robinvdvleuten" title="Documentation">📖</a> <a href="#example-robinvdvleuten" title="Examples">💡</a> <a href="#ideas-robinvdvleuten" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-robinvdvleuten" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/robinvdvleuten/shvl/pulls?q=is%3Apr+reviewed-by%3Arobinvdvleuten" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/robinvdvleuten/shvl/commits?author=robinvdvleuten" title="Tests">⚠️</a></td>
|
||||
<td align="center"><a href="https://github.com/ajenkinski"><img src="https://avatars0.githubusercontent.com/u/20757262?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ajenkinski</b></sub></a><br /><a href="https://github.com/robinvdvleuten/shvl/commits?author=ajenkinski" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- markdownlint-enable -->
|
||||
<!-- prettier-ignore-end -->
|
||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE) for more information.
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
exports.get=function(t,e,r){return void 0===(t=(e.split?e.split("."):e).reduce(function(t,e){return t&&t[e]},t))?r:t},exports.set=function(t,e,r,o){return!/^(__proto__|constructor|prototype)$/.test(e)&&((e=e.split?e.split("."):e.slice(0)).slice(0,-1).reduce(function(t,e){return t[e]=t[e]||{}},t)[e.pop()]=r),t};
|
||||
//# sourceMappingURL=shvl.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"shvl.js","sources":["../index.js"],"sourcesContent":["export function get (object, path, def) {\n return (object = (path.split ? path.split('.') : path).reduce(function (obj, p) {\n return obj && obj[p]\n }, object)) === undefined ? def : object;\n};\n\nexport function set (object, path, val, obj) {\n return !/^(__proto__|constructor|prototype)$/.test(path) && ((path = path.split ? path.split('.') : path.slice(0)).slice(0, -1).reduce(function (obj, p) {\n return obj[p] = obj[p] || {};\n }, obj = object)[path.pop()] = val), object;\n};\n"],"names":["object","path","def","undefined","split","reduce","obj","p","val","test","slice","pop"],"mappings":"qBAAqBA,EAAQC,EAAMC,GACjC,YAEgBC,KAFRH,GAAUC,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,GAAMI,OAAO,SAAUC,EAAKC,GAC3E,OAAOD,GAAOA,EAAIC,IACjBP,IAAyBE,EAAMF,wBAGdA,EAAQC,EAAMO,EAAKF,GACvC,OAAQ,sCAAsCG,KAAKR,MAAWA,EAAOA,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,EAAKS,MAAM,IAAIA,MAAM,GAAI,GAAGL,OAAO,SAAUC,EAAKC,GACpJ,OAAOD,EAAIC,GAAKD,EAAIC,IAAM,IACnBP,GAAQC,EAAKU,OAASH,GAAMR"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
function t(t,r,e){return void 0===(t=(r.split?r.split("."):r).reduce(function(t,r){return t&&t[r]},t))?e:t}function r(t,r,e,n){return!/^(__proto__|constructor|prototype)$/.test(r)&&((r=r.split?r.split("."):r.slice(0)).slice(0,-1).reduce(function(t,r){return t[r]=t[r]||{}},t)[r.pop()]=e),t}export{t as get,r as set};
|
||||
//# sourceMappingURL=shvl.mjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"shvl.mjs","sources":["../index.js"],"sourcesContent":["export function get (object, path, def) {\n return (object = (path.split ? path.split('.') : path).reduce(function (obj, p) {\n return obj && obj[p]\n }, object)) === undefined ? def : object;\n};\n\nexport function set (object, path, val, obj) {\n return !/^(__proto__|constructor|prototype)$/.test(path) && ((path = path.split ? path.split('.') : path.slice(0)).slice(0, -1).reduce(function (obj, p) {\n return obj[p] = obj[p] || {};\n }, obj = object)[path.pop()] = val), object;\n};\n"],"names":["get","object","path","def","undefined","split","reduce","obj","p","set","val","test","slice","pop"],"mappings":"SAAgBA,EAAKC,EAAQC,EAAMC,GACjC,YAEgBC,KAFRH,GAAUC,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,GAAMI,OAAO,SAAUC,EAAKC,GAC3E,OAAOD,GAAOA,EAAIC,IACjBP,IAAyBE,EAAMF,WAGpBQ,EAAMR,EAAQC,EAAMQ,EAAKH,GACvC,OAAQ,sCAAsCI,KAAKT,MAAWA,EAAOA,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,EAAKU,MAAM,IAAIA,MAAM,GAAI,GAAGN,OAAO,SAAUC,EAAKC,GACpJ,OAAOD,EAAIC,GAAKD,EAAIC,IAAM,IACnBP,GAAQC,EAAKW,OAASH,GAAMT"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
function t(t,r,e){return void 0===(t=(r.split?r.split("."):r).reduce(function(t,r){return t&&t[r]},t))?e:t}function r(t,r,e,n){return!/^(__proto__|constructor|prototype)$/.test(r)&&((r=r.split?r.split("."):r.slice(0)).slice(0,-1).reduce(function(t,r){return t[r]=t[r]||{}},t)[r.pop()]=e),t}export{t as get,r as set};
|
||||
//# sourceMappingURL=shvl.modern.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"shvl.modern.js","sources":["../index.js"],"sourcesContent":["export function get (object, path, def) {\n return (object = (path.split ? path.split('.') : path).reduce(function (obj, p) {\n return obj && obj[p]\n }, object)) === undefined ? def : object;\n};\n\nexport function set (object, path, val, obj) {\n return !/^(__proto__|constructor|prototype)$/.test(path) && ((path = path.split ? path.split('.') : path.slice(0)).slice(0, -1).reduce(function (obj, p) {\n return obj[p] = obj[p] || {};\n }, obj = object)[path.pop()] = val), object;\n};\n"],"names":["get","object","path","def","undefined","split","reduce","obj","p","set","val","test","slice","pop"],"mappings":"SAAgBA,EAAKC,EAAQC,EAAMC,GACjC,YAEgBC,KAFRH,GAAUC,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,GAAMI,OAAO,SAAUC,EAAKC,GAC3E,OAAOD,GAAOA,EAAIC,IACjBP,IAAyBE,EAAMF,WAGpBQ,EAAMR,EAAQC,EAAMQ,EAAKH,GACvC,OAAQ,sCAAsCI,KAAKT,MAAWA,EAAOA,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,EAAKU,MAAM,IAAIA,MAAM,GAAI,GAAGN,OAAO,SAAUC,EAAKC,GACpJ,OAAOD,EAAIC,GAAKD,EAAIC,IAAM,IACnBP,GAAQC,EAAKW,OAASH,GAAMT"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).shvl={})}(this,function(t){t.get=function(t,e,n){return void 0===(t=(e.split?e.split("."):e).reduce(function(t,e){return t&&t[e]},t))?n:t},t.set=function(t,e,n,o){return!/^(__proto__|constructor|prototype)$/.test(e)&&((e=e.split?e.split("."):e.slice(0)).slice(0,-1).reduce(function(t,e){return t[e]=t[e]||{}},t)[e.pop()]=n),t}});
|
||||
//# sourceMappingURL=shvl.umd.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"shvl.umd.js","sources":["../index.js"],"sourcesContent":["export function get (object, path, def) {\n return (object = (path.split ? path.split('.') : path).reduce(function (obj, p) {\n return obj && obj[p]\n }, object)) === undefined ? def : object;\n};\n\nexport function set (object, path, val, obj) {\n return !/^(__proto__|constructor|prototype)$/.test(path) && ((path = path.split ? path.split('.') : path.slice(0)).slice(0, -1).reduce(function (obj, p) {\n return obj[p] = obj[p] || {};\n }, obj = object)[path.pop()] = val), object;\n};\n"],"names":["object","path","def","undefined","split","reduce","obj","p","val","test","slice","pop"],"mappings":"mMAAqBA,EAAQC,EAAMC,GACjC,YAEgBC,KAFRH,GAAUC,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,GAAMI,OAAO,SAAUC,EAAKC,GAC3E,OAAOD,GAAOA,EAAIC,IACjBP,IAAyBE,EAAMF,kBAGdA,EAAQC,EAAMO,EAAKF,GACvC,OAAQ,sCAAsCG,KAAKR,MAAWA,EAAOA,EAAKG,MAAQH,EAAKG,MAAM,KAAOH,EAAKS,MAAM,IAAIA,MAAM,GAAI,GAAGL,OAAO,SAAUC,EAAKC,GACpJ,OAAOD,EAAIC,GAAKD,EAAIC,IAAM,IACnBP,GAAQC,EAAKU,OAASH,GAAMR"}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export function get (object: object, path: string|string[], def?: any): any;
|
||||
export function set (object: object, path: string|string[], val: any): any;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
export function get (object, path, def) {
|
||||
return (object = (path.split ? path.split('.') : path).reduce(function (obj, p) {
|
||||
return obj && obj[p]
|
||||
}, object)) === undefined ? def : object;
|
||||
};
|
||||
|
||||
export function set (object, path, val, obj) {
|
||||
return !/^(__proto__|constructor|prototype)$/.test(path) && ((path = path.split ? path.split('.') : path.slice(0)).slice(0, -1).reduce(function (obj, p) {
|
||||
return obj[p] = obj[p] || {};
|
||||
}, obj = object)[path.pop()] = val), object;
|
||||
};
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"_from": "shvl@^2.0.3",
|
||||
"_id": "shvl@2.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-V7C6S9Hlol6SzOJPnQ7qzOVEWUQImt3BNmmzh40wObhla3XOYMe4gGiYzLrJd5TFa+cI2f9LKIRJTTKZSTbWgw==",
|
||||
"_location": "/shvl",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "shvl@^2.0.3",
|
||||
"name": "shvl",
|
||||
"escapedName": "shvl",
|
||||
"rawSpec": "^2.0.3",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.3"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/vuex-persistedstate"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/shvl/-/shvl-2.0.3.tgz",
|
||||
"_shasum": "eb4bd37644f5684bba1fc52c3010c96fb5e6afd1",
|
||||
"_spec": "shvl@^2.0.3",
|
||||
"_where": "D:\\work\\云美\\legalAffairs-app\\node_modules\\vuex-persistedstate",
|
||||
"author": {
|
||||
"name": "Robin van der Vleuten",
|
||||
"email": "robin@webstronauts.co"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"@babel/preset-env"
|
||||
]
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/robinvdvleuten/shvl/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"bundlesize": [
|
||||
{
|
||||
"path": "./dist/*.js",
|
||||
"threshold": "300b"
|
||||
}
|
||||
],
|
||||
"deprecated": "older versions vulnerable to prototype pollution",
|
||||
"description": "Get and set dot-notated properties within an object",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"babel-jest": "^26.2.2",
|
||||
"bundlesize": "^0.18.0",
|
||||
"jest": "^26.5.3",
|
||||
"jest-in-case": "^1.0.2",
|
||||
"microbundle": "^0.13.0",
|
||||
"npm-run-all": "^4.1.2"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/robinvdvleuten/shvl#readme",
|
||||
"keywords": [
|
||||
"path",
|
||||
"dot notation",
|
||||
"dot"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "dist/shvl.js",
|
||||
"module": "dist/shvl.mjs",
|
||||
"name": "shvl",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/robinvdvleuten/shvl.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "microbundle",
|
||||
"prepare": "run-s build",
|
||||
"test": "run-p test:**",
|
||||
"test:jest": "jest --env=jsdom",
|
||||
"test:size": "bundlesize"
|
||||
},
|
||||
"source": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
"unpkg": "dist/shvl.umd.js",
|
||||
"version": "2.0.3"
|
||||
}
|
||||
Reference in New Issue
Block a user