dot-object 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/README.md +27 -0
- package/dist/dot-object.js +1 -1
- package/dist/dot-object.min.js +1 -1
- package/index.js +1 -1
- package/package.json +13 -10
- package/bower.json +0 -35
- package/gulpfile.js +0 -59
- package/src/dot-object.js +0 -583
- package/src/footer.tpl +0 -13
- package/src/header.tpl +0 -1
- package/test/_process.js +0 -125
- package/test/array_notation.js +0 -176
- package/test/copy.js +0 -86
- package/test/data/array_deep_bug.json +0 -30
- package/test/data/array_deep_bug2.json +0 -19
- package/test/data/empty_array.json +0 -43
- package/test/data/empty_object.json +0 -23
- package/test/data/index.js +0 -8
- package/test/data/object_deep_numeric_keys.json +0 -30
- package/test/data/object_deep_numeric_keys2.json +0 -20
- package/test/dot-json.js +0 -215
- package/test/dot.js +0 -155
- package/test/fixtures/package.json +0 -46
- package/test/merge.js +0 -96
- package/test/move.js +0 -70
- package/test/override.js +0 -93
- package/test/pick.js +0 -134
- package/test/remove.js +0 -80
- package/test/str.js +0 -63
- package/test/test_data.js +0 -42
- package/test/test_transforms.js +0 -28
- package/test/transfer.js +0 -81
- package/test/transforms/contact.json +0 -26
- package/test/transforms/twitter.json +0 -174
- package/test/useArray.js +0 -68
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
# ChangeLog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2024-04-19 Version 2.1.5
|
4
|
+
* [[`a23221d367408`](https://github.com/rhalff/dot-object/commit/a23221d367408)] - Add LICENSE property to package.json (Fixed by denniskim #54)
|
5
|
+
*
|
6
|
+
## 2020-09-10 Version 2.1.4
|
7
|
+
* [[`94b9eb8a2d`](https://github.com/rhalff/dot-object/commit/94b9eb8a2d)] - Fix parsing of array paths for non standard separators (Fixed by boidolr #58)
|
8
|
+
|
9
|
+
## 2020-02-16 Version 2.1.3
|
4
10
|
* fix possible pollution of prototype for paths containing __proto__
|
5
11
|
|
6
12
|
## 2019-11-02 Version 2.1.1
|
package/README.md
CHANGED
@@ -359,6 +359,33 @@ Result:
|
|
359
359
|
}
|
360
360
|
```
|
361
361
|
|
362
|
+
### Keep array
|
363
|
+
|
364
|
+
Set keepArray to true.
|
365
|
+
|
366
|
+
```javascript
|
367
|
+
var dot = require('dot-object');
|
368
|
+
|
369
|
+
var obj = {
|
370
|
+
id: 'my-id',
|
371
|
+
other: [1, 2, 3],
|
372
|
+
some: { array: ['A', 'B'] }
|
373
|
+
};
|
374
|
+
|
375
|
+
dot.keepArray = true;
|
376
|
+
var tgt = dot.dot(obj);
|
377
|
+
|
378
|
+
console.log(tgt);
|
379
|
+
```
|
380
|
+
Result:
|
381
|
+
```json
|
382
|
+
{
|
383
|
+
"id": "my-id",
|
384
|
+
"other": [1, 2, 3],
|
385
|
+
"some.array": ["A", "B"]
|
386
|
+
}
|
387
|
+
```
|
388
|
+
|
362
389
|
## Using a different separator
|
363
390
|
|
364
391
|
If you do not like dot notation, you are free to specify a different separator.
|
package/dist/dot-object.js
CHANGED
package/dist/dot-object.min.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
!function(t){"use strict";function s(t,r){var e,i;if("function"==typeof r)void 0!==(i=r(t))&&(t=i);else if(Array.isArray(r))for(e=0;e<r.length;e++)void 0!==(i=r[e](t))&&(t=i);return t}function p(t){return"[object Object]"===Object.prototype.toString.call(t)}function a(t){return Object(t)===t}function c(t){return 0===Object.keys(t).length}function
|
1
|
+
!function(t){"use strict";function s(t,r){var e,i;if("function"==typeof r)void 0!==(i=r(t))&&(t=i);else if(Array.isArray(r))for(e=0;e<r.length;e++)void 0!==(i=r[e](t))&&(t=i);return t}function p(t){return"[object Object]"===Object.prototype.toString.call(t)}function a(t){return Object(t)===t}function c(t){return 0===Object.keys(t).length}function e(t){return-1===r.indexOf(t)}var r=["__proto__","prototype","constructor"];function f(t,r){r=(t=0<=t.indexOf("[")?t.replace(/\[/g,r).replace(/]/g,""):t).split(r);if(r.filter(e).length!==r.length)throw Error("Refusing to update blacklisted property "+t);return r}var u=Object.prototype.hasOwnProperty;function n(t,r,e,i){if(!(this instanceof n))return new n(t,r,e,i);void 0===r&&(r=!1),void 0===e&&(e=!0),void 0===i&&(i=!0),this.separator=t||".",this.override=r,this.useArray=e,this.useBrackets=i,this.keepArray=!1,this.cleanup=[]}var i=new n(".",!1,!0,!0);function o(t){return function(){return i[t].apply(i,arguments)}}n.prototype._fill=function(t,r,e,i){var n=t.shift();if(0<t.length){if(r[n]=r[n]||(this.useArray&&/^\d+$/.test(t[0])?[]:{}),!a(r[n])){if(!this.override){if(a(e)&&c(e))return;throw new Error("Trying to redefine `"+n+"` which is a "+typeof r[n])}r[n]={}}this._fill(t,r[n],e,i)}else{if(!this.override&&a(r[n])&&!c(r[n])){if(a(e)&&c(e))return;throw new Error("Trying to redefine non-empty obj['"+n+"']")}r[n]=s(e,i)}},n.prototype.object=function(i,n){var o=this;return Object.keys(i).forEach(function(t){var r=void 0===n?null:n[t],e=f(t,o.separator).join(o.separator);-1!==e.indexOf(o.separator)?(o._fill(e.split(o.separator),i,i[t],r),delete i[t]):i[t]=s(i[t],r)}),i},n.prototype.str=function(t,r,e,i){var n=f(t,this.separator).join(this.separator);return-1!==t.indexOf(this.separator)?this._fill(n.split(this.separator),e,r,i):e[t]=s(r,i),e},n.prototype.pick=function(t,r,e,i){for(var n,o,s,a=f(t,this.separator),c=0;c<a.length;c++){if(o=a[c],s=r,s="-"===o[0]&&Array.isArray(s)&&/^-\d+$/.test(o)?s.length+parseInt(o,10):o,!(r&&"object"==typeof r&&s in r))return;if(c===a.length-1)return e?(o=r[s],i&&Array.isArray(r)?r.splice(s,1):delete r[s],Array.isArray(r)&&(n=a.slice(0,-1).join("."),-1===this.cleanup.indexOf(n))&&this.cleanup.push(n),o):r[s];r=r[s]}return r=e&&Array.isArray(r)?r.filter(function(t){return void 0!==t}):r},n.prototype.delete=function(t,r){return this.remove(t,r,!0)},n.prototype.remove=function(t,r,e){var i;if(this.cleanup=[],Array.isArray(t)){for(i=0;i<t.length;i++)this.pick(t[i],r,!0,e);return e||this._cleanup(r),r}return this.pick(t,r,!0,e)},n.prototype._cleanup=function(t){var r,e,i;if(this.cleanup.length){for(r=0;r<this.cleanup.length;r++)i=(i=(i=(e=this.cleanup[r].split(".")).splice(0,-1).join("."))?this.pick(i,t):t)[e[0]].filter(function(t){return void 0!==t}),this.set(this.cleanup[r],i,t);this.cleanup=[]}},n.prototype.del=n.prototype.remove,n.prototype.move=function(t,r,e,i,n){return"function"==typeof i||Array.isArray(i)?this.set(r,s(this.pick(t,e,!0),i),e,n):(n=i,this.set(r,this.pick(t,e,!0),e,n)),e},n.prototype.transfer=function(t,r,e,i,n,o){return"function"==typeof n||Array.isArray(n)?this.set(r,s(this.pick(t,e,!0),n),i,o):(o=n,this.set(r,this.pick(t,e,!0),i,o)),i},n.prototype.copy=function(t,r,e,i,n,o){return"function"==typeof n||Array.isArray(n)?this.set(r,s(JSON.parse(JSON.stringify(this.pick(t,e,!1))),n),i,o):(o=n,this.set(r,this.pick(t,e,!1),i,o)),i},n.prototype.set=function(t,r,e,i){var n,o,s,a;if(void 0!==r)for(s=f(t,this.separator),n=0;n<s.length;n++){if(a=s[n],n===s.length-1)if(i&&p(r)&&p(e[a]))for(o in r)u.call(r,o)&&(e[a][o]=r[o]);else if(i&&Array.isArray(e[a])&&Array.isArray(r))for(var c=0;c<r.length;c++)e[s[n]].push(r[c]);else e[a]=r;else u.call(e,a)&&(p(e[a])||Array.isArray(e[a]))||(/^\d+$/.test(s[n+1])?e[a]=[]:e[a]={});e=e[a]}return e},n.prototype.transform=function(r,e,i){return e=e||{},i=i||{},Object.keys(r).forEach(function(t){this.set(r[t],this.pick(t,e),i)}.bind(this)),i},n.prototype.dot=function(i,n,o){n=n||{},o=o||[];var s=Array.isArray(i);return Object.keys(i).forEach(function(t){var r,e=s&&this.useBrackets?"["+t+"]":t;if(a(i[t])&&(p(i[t])&&!c(i[t])||Array.isArray(i[t])&&!this.keepArray&&0!==i[t].length))return s&&this.useBrackets?(r=o[o.length-1]||"",this.dot(i[t],n,o.slice(0,-1).concat(r+e))):this.dot(i[t],n,o.concat(e));s&&this.useBrackets?n[o.join(this.separator).concat("["+t+"]")]=i[t]:n[o.concat(e).join(this.separator)]=i[t]}.bind(this)),n},n.pick=o("pick"),n.move=o("move"),n.transfer=o("transfer"),n.transform=o("transform"),n.copy=o("copy"),n.object=o("object"),n.str=o("str"),n.set=o("set"),n.delete=o("delete"),n.del=n.remove=o("remove"),n.dot=o("dot"),["override","overwrite"].forEach(function(t){Object.defineProperty(n,t,{get:function(){return i.override},set:function(t){i.override=!!t}})}),["useArray","keepArray","useBrackets"].forEach(function(r){Object.defineProperty(n,r,{get:function(){return i[r]},set:function(t){i[r]=t}})}),n._process=s,"function"==typeof define&&define.amd?define(function(){return n}):"undefined"!=typeof module&&module.exports?module.exports=n:t.DotObject=n}(this);
|
package/index.js
CHANGED
@@ -50,7 +50,7 @@ var blacklistFilter = function (part) { return blacklist.indexOf(part) === -1 }
|
|
50
50
|
|
51
51
|
function parsePath (path, sep) {
|
52
52
|
if (path.indexOf('[') >= 0) {
|
53
|
-
path = path.replace(/\[/g,
|
53
|
+
path = path.replace(/\[/g, sep).replace(/]/g, '')
|
54
54
|
}
|
55
55
|
|
56
56
|
var parts = path.split(sep)
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "dot-object",
|
3
3
|
"description": "dot-object makes it possible to transform and read (JSON) objects using dot notation.",
|
4
|
-
"version": "2.1.
|
4
|
+
"version": "2.1.5",
|
5
5
|
"author": {
|
6
6
|
"name": "Rob Halff",
|
7
7
|
"email": "rob.halff@gmail.com"
|
@@ -13,6 +13,7 @@
|
|
13
13
|
"bugs": {
|
14
14
|
"url": "https://github.com/rhalff/dot-object/issues"
|
15
15
|
},
|
16
|
+
"license": "MIT",
|
16
17
|
"main": "index",
|
17
18
|
"bin": "./bin/dot-object",
|
18
19
|
"scripts": {
|
@@ -29,10 +30,10 @@
|
|
29
30
|
]
|
30
31
|
},
|
31
32
|
"devDependencies": {
|
32
|
-
"eslint": "^
|
33
|
-
"eslint-config-standard": "^14.1.
|
34
|
-
"eslint-plugin-import": "^2.
|
35
|
-
"eslint-plugin-node": "^
|
33
|
+
"eslint": "^7.9.0",
|
34
|
+
"eslint-config-standard": "^14.1.1",
|
35
|
+
"eslint-plugin-import": "^2.22.0",
|
36
|
+
"eslint-plugin-node": "^11.1.0",
|
36
37
|
"eslint-plugin-promise": "^4.2.1",
|
37
38
|
"eslint-plugin-standard": "^4.0.1",
|
38
39
|
"gulp": "^4.0.2",
|
@@ -40,22 +41,24 @@
|
|
40
41
|
"gulp-eslint": "^6.0.0",
|
41
42
|
"gulp-headerfooter": "^1.0.3",
|
42
43
|
"gulp-mocha": "^7.0.2",
|
43
|
-
"gulp-rename": "^
|
44
|
+
"gulp-rename": "^2.0.0",
|
44
45
|
"gulp-uglify": "^3.0.2",
|
45
46
|
"gulp-util": "^3.0.8",
|
46
|
-
"mocha": "
|
47
|
+
"mocha": "8.x.x",
|
47
48
|
"should": "13.x.x",
|
48
49
|
"underscore.string": "latest"
|
49
50
|
},
|
50
51
|
"keywords": [
|
51
52
|
"json",
|
53
|
+
"object",
|
52
54
|
"filter",
|
53
55
|
"transform",
|
54
56
|
"dot notation",
|
55
57
|
"dot"
|
56
58
|
],
|
57
59
|
"dependencies": {
|
58
|
-
"commander": "^
|
59
|
-
"glob": "^7.1.
|
60
|
-
}
|
60
|
+
"commander": "^6.1.0",
|
61
|
+
"glob": "^7.1.6"
|
62
|
+
},
|
63
|
+
"packageManager": "yarn@4.1.1"
|
61
64
|
}
|
package/bower.json
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "dot-object",
|
3
|
-
"version": "2.1.3",
|
4
|
-
"description": "dot-object makes it possible to transform and read (JSON) objects using dot notation.",
|
5
|
-
"main": "dist/dot-object.js",
|
6
|
-
"authors": [
|
7
|
-
{ "name": "Rob Halff", "email": "rob.halff@gmail.com" }
|
8
|
-
],
|
9
|
-
"ignore": [
|
10
|
-
"bin",
|
11
|
-
"node_modules",
|
12
|
-
"src",
|
13
|
-
"gulpfile.js",
|
14
|
-
"index.js"
|
15
|
-
],
|
16
|
-
"keywords": [
|
17
|
-
"json",
|
18
|
-
"filter",
|
19
|
-
"transform",
|
20
|
-
"dot",
|
21
|
-
"notation",
|
22
|
-
"dot"
|
23
|
-
],
|
24
|
-
"license": "MIT",
|
25
|
-
"repository": {
|
26
|
-
"type": "git",
|
27
|
-
"url": "git://github.com/rhalff/dot-object.git"
|
28
|
-
},
|
29
|
-
"homepage": "https://github.com/rhalff/dot-object",
|
30
|
-
"moduleType": [
|
31
|
-
"amd",
|
32
|
-
"globals",
|
33
|
-
"node"
|
34
|
-
]
|
35
|
-
}
|
package/gulpfile.js
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
'use strict'
|
2
|
-
|
3
|
-
var gulp = require('gulp')
|
4
|
-
var gutil = require('gulp-util')
|
5
|
-
var mocha = require('gulp-mocha')
|
6
|
-
var hf = require('gulp-headerfooter')
|
7
|
-
var rename = require('gulp-rename')
|
8
|
-
var uglify = require('gulp-uglify')
|
9
|
-
var beautify = require('gulp-beautify')
|
10
|
-
var eslint = require('gulp-eslint')
|
11
|
-
|
12
|
-
var DEST = 'dist/'
|
13
|
-
|
14
|
-
var paths = ['gulpfile.js', 'src/dot-object.js', 'test/**/*.js']
|
15
|
-
|
16
|
-
gulp.task('lint', function (done) {
|
17
|
-
gulp.src(paths)
|
18
|
-
.pipe(eslint())
|
19
|
-
.pipe(eslint.format())
|
20
|
-
.pipe(eslint.failAfterError())
|
21
|
-
done()
|
22
|
-
})
|
23
|
-
|
24
|
-
gulp.task('mocha', function (done) {
|
25
|
-
gulp.src(['test/**/*.js'])
|
26
|
-
.pipe(mocha())
|
27
|
-
.on('error', gutil.log)
|
28
|
-
done()
|
29
|
-
})
|
30
|
-
|
31
|
-
gulp.task('watch', function () {
|
32
|
-
gulp.watch(paths, gulp.series('build-node', 'mocha'))
|
33
|
-
})
|
34
|
-
|
35
|
-
gulp.task('build-node', function (done) {
|
36
|
-
gulp.src('src/dot-object.js')
|
37
|
-
.pipe(hf.footer('\nmodule.exports = DotObject\n'))
|
38
|
-
.pipe(rename({ basename: 'index' }))
|
39
|
-
.pipe(gulp.dest('./'))
|
40
|
-
done()
|
41
|
-
})
|
42
|
-
|
43
|
-
gulp.task('build-bower', function (done) {
|
44
|
-
gulp.src('src/dot-object.js')
|
45
|
-
.pipe(hf.header('src/header.tpl'))
|
46
|
-
.pipe(hf.footer('src/footer.tpl'))
|
47
|
-
.pipe(beautify({ indentSize: 2 }))
|
48
|
-
.pipe(gulp.dest(DEST))
|
49
|
-
.pipe(uglify())
|
50
|
-
.pipe(rename({ extname: '.min.js' }))
|
51
|
-
.pipe(gulp.dest(DEST))
|
52
|
-
done()
|
53
|
-
})
|
54
|
-
|
55
|
-
gulp.task('dist', gulp.parallel('lint', 'build-node', 'mocha', 'build-bower'))
|
56
|
-
|
57
|
-
gulp.task('test', gulp.parallel('lint', 'build-node', 'mocha'))
|
58
|
-
|
59
|
-
gulp.task('default', gulp.parallel('test'))
|