Skip to content

Commit 772e8f4

Browse files
Merge pull request #29 from jonschlinkert/dev
refactor
2 parents a68f550 + 599bccc commit 772e8f4

28 files changed

+4275
-4430
lines changed

Diff for: .editorconfig

-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,3 @@ indent_size = 2
88
indent_style = space
99
insert_final_newline = true
1010
trim_trailing_whitespace = true
11-
12-
[{**/{actual,fixtures,expected,templates}/**,*.md}]
13-
trim_trailing_whitespace = false
14-
insert_final_newline = false

Diff for: .eslintrc.json

+19-25
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,17 @@
44
],
55

66
"env": {
7-
"browser": false,
8-
"es6": true,
9-
"node": true,
10-
"mocha": true
7+
"es2021": true,
8+
"node": true
119
},
1210

13-
"parserOptions":{
14-
"ecmaVersion": 9,
15-
"sourceType": "module",
16-
"ecmaFeatures": {
17-
"modules": true,
18-
"experimentalObjectRestSpread": true
19-
}
20-
},
21-
22-
"globals": {
23-
"document": false,
24-
"navigator": false,
25-
"window": false
11+
"parserOptions": {
12+
"ecmaVersion": 12
2613
},
2714

2815
"rules": {
2916
"accessor-pairs": 2,
17+
"arrow-parens": [2, "as-needed"],
3018
"arrow-spacing": [2, { "before": true, "after": true }],
3119
"block-spacing": [2, "always"],
3220
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
@@ -39,7 +27,7 @@
3927
"eol-last": 2,
4028
"eqeqeq": [2, "allow-null"],
4129
"generator-star-spacing": [2, { "before": true, "after": true }],
42-
"handle-callback-err": [2, "^(err|error)$" ],
30+
"handle-callback-err": [2, "^(err|error)$"],
4331
"indent": [2, 2, { "SwitchCase": 1 }],
4432
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
4533
"keyword-spacing": [2, { "before": true, "after": true }],
@@ -68,18 +56,20 @@
6856
"no-floating-decimal": 2,
6957
"no-func-assign": 2,
7058
"no-implied-eval": 2,
59+
"no-implicit-coercion": 2,
7160
"no-inner-declarations": [2, "functions"],
7261
"no-invalid-regexp": 2,
7362
"no-irregular-whitespace": 2,
7463
"no-iterator": 2,
7564
"no-label-var": 2,
7665
"no-labels": 2,
7766
"no-lone-blocks": 2,
67+
"no-lonely-if": 2,
7868
"no-mixed-spaces-and-tabs": 2,
79-
"no-multi-spaces": 2,
69+
"no-multi-spaces": 0,
8070
"no-multi-str": 2,
8171
"no-multiple-empty-lines": [2, { "max": 1 }],
82-
"no-native-reassign": 0,
72+
"no-native-reassign": 2,
8373
"no-negated-in-lhs": 2,
8474
"no-new": 2,
8575
"no-new-func": 2,
@@ -89,7 +79,7 @@
8979
"no-obj-calls": 2,
9080
"no-octal": 2,
9181
"no-octal-escape": 2,
92-
"no-proto": 0,
82+
"no-proto": 2,
9383
"no-redeclare": 2,
9484
"no-regex-spaces": 2,
9585
"no-return-assign": 2,
@@ -100,28 +90,32 @@
10090
"no-sparse-arrays": 2,
10191
"no-this-before-super": 2,
10292
"no-throw-literal": 2,
103-
"no-trailing-spaces": 0,
93+
"no-trailing-spaces": 2,
10494
"no-undef": 2,
10595
"no-undef-init": 2,
10696
"no-unexpected-multiline": 2,
10797
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
10898
"no-unreachable": 2,
99+
"no-unused-expressions": 2,
109100
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
110-
"no-useless-call": 0,
101+
"no-useless-call": 2,
111102
"no-with": 2,
112-
"one-var": [0, { "initialized": "never" }],
103+
"object-curly-spacing": ["error", "always", { "objectsInObjects": true }],
104+
"one-var": [2, { "initialized": "never" }],
113105
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
114106
"padded-blocks": [0, "never"],
107+
"prefer-const": [2, { "destructuring": "all", "ignoreReadBeforeAssign": false }],
115108
"quotes": [2, "single", "avoid-escape"],
116109
"radix": 2,
117110
"semi": [2, "always"],
118111
"semi-spacing": [2, { "before": false, "after": true }],
119112
"space-before-blocks": [2, "always"],
120-
"space-before-function-paren": [2, "never"],
113+
"space-before-function-paren": [2, { "anonymous": "never", "named": "never", "asyncArrow": "always" }],
121114
"space-in-parens": [2, "never"],
122115
"space-infix-ops": 2,
123116
"space-unary-ops": [2, { "words": true, "nonwords": false }],
124117
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
118+
"strict": 2,
125119
"use-isnan": 2,
126120
"valid-typeof": 2,
127121
"wrap-iife": [2, "any"],

Diff for: .github/FUNDING.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [jonschlinkert, doowb]

Diff for: .github/workflows/main.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Tests
2+
on: [push, pull_request]
3+
4+
jobs:
5+
test:
6+
name: Node.js ${{ matrix.node-version }} @ ${{ matrix.os }}
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ubuntu-latest, windows-latest, macos-latest]
12+
node-version: [11, 12, 13, 14, 15, 16]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- run: npm install
20+
- run: npm test

Diff for: .travis.yml

-14
This file was deleted.

Diff for: .verb.md

+84-23
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,31 @@
66

77
```js
88
const set = require('{%= name %}');
9-
set(object, prop, value);
9+
10+
const obj = {};
11+
set(obj, 'a.b.c', 'd');
12+
13+
console.log(obj);
14+
//=> { a: { b: { c: 'd' } } }
1015
```
1116

1217
### Params
1318

14-
- `object` **{object}**: The object to set `value` on
15-
- `prop` **{string}**: The property to set. Dot-notation may be used.
16-
- `value` **{any}**: The value to set on `object[prop]`
19+
Signature:
1720

21+
```js
22+
set(object, property_path, value[, options]);
23+
```
1824

19-
## Examples
25+
- `object` **{Object}**: The object to set `value` on
26+
- `path` **{String|Symbol|Array}**: The [path](#object-paths) of the property to set.
27+
- `value` **{any}**: The value to set on `obj[prop]`
28+
- `options` **{Object}**: See all [available options](#options)
2029

21-
Updates and returns the given object:
30+
### Object paths
31+
32+
You may pass a string, symbol, or array of strings or symbols. By default, when a string is passed this library will split the string on `.` or a [custom separator](#options-separator) It's useful to pass an array
2233

23-
```js
24-
const obj = {};
25-
set(obj, 'a.b.c', 'd');
26-
console.log(obj);
27-
//=> { a: { b: { c: 'd' } } }
28-
```
2934

3035
### Escaping
3136

@@ -41,11 +46,67 @@ console.log(set({}, 'a\\.b\\.c', 'd'));
4146
//=> { 'a.b.c': 'd' }
4247
```
4348

44-
## Benchmarks
49+
## Options
50+
51+
### options.preservePaths
52+
53+
Do not split properties that include a `/`. By default, set-value assumes that properties with a `/` are not intended to be split. This option allows you to disable default behavior.
54+
55+
Note that this option cannot be used if `options.separator` is set to `/`.
56+
57+
**Type**: `boolean`
58+
59+
**Default**: `true`
60+
61+
**Example**
62+
63+
```js
64+
console.log(set({}, 'https://github.com', true));
65+
//=> { 'https://github.com': true }
66+
67+
console.log(set({}, 'https://github.com', true, { preservePaths: false }));
68+
//=> { 'https://github': { com: true } }
69+
```
70+
71+
### options.separator
72+
73+
Custom separator to use for splitting object paths.
74+
75+
**Type**: `string`
76+
77+
**Default**: `.`
78+
79+
**Example**
80+
81+
```js
82+
console.log(set(obj, 'auth/userpass/users/bob', '*****', { separator: '/' }));
83+
//=> { auth: { userpass: { users: { bob: '*****' } } } }
84+
```
85+
86+
### options.split
4587

46-
_(benchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3)_.
88+
Custom `.split()` function to use.
89+
90+
91+
### options.merge
92+
93+
Allows you to update plain object values, instead of overwriting them.
94+
95+
**Type**: `boolean|function` - A custom `merge` function may be defined if you need to deep merge. Otherwise, when `merge` is `true`, a shallow merge will be performed by `Object.assign()`.
96+
97+
**Default**: `undefined`
98+
99+
**Example**
100+
101+
```js
102+
const obj = { foo: { bar: { baz: 'qux' } } };
103+
set(obj, 'foo.bar.fez', 'zzz', { merge: true });
104+
//=> { foo: { bar: { baz: 'qux', fez: 'zzz' } } }
105+
```
106+
107+
## Benchmarks
47108

48-
set-value is more reliable and has more features than dot-prop, without sacrificing performance.
109+
Benchmarks were run on a MacBook Pro 2.5 GHz Intel Core i7, 16 GB 1600 MHz DDR3.
49110

50111
```
51112
{%= include("./benchmark/stats.md") %}
@@ -67,9 +128,9 @@ $ npm install && node benchmark
67128

68129
## Comparisons to other libs, or _"the list of shame"_
69130

70-
These are just a few of the duplicate libraries on NPM.
131+
These are just a few of the duplicate libraries on NPM.
71132

72-
- [bury][] fails all of the tests. I even wrapped it to have it return the object instead of the value, but with all of that work it still fails the vast majority of tests.
133+
- [bury][] fails all of the tests. I even wrapped it to have it return the object instead of the value, but with all of that work it still fails the vast majority of tests.
73134
- [deep-get-set][] fails 22 of 26 unit tests.
74135
- [deep-object][] fails 25 of 26 unit tests, completely butchered given objects.
75136
- [deep-property][] fails 17 of 26 unit tests.
@@ -89,23 +150,23 @@ These are just a few of the duplicate libraries on NPM.
89150

90151
**Others that do the same thing, but use a completely different API**
91152

92-
- [deep-set-in][]
93-
- [set-deep][]
94-
- [set-deep-prop][]
95-
- [bury][]
153+
- [deep-set-in][]
154+
- [set-deep][]
155+
- [set-deep-prop][]
156+
- [bury][]
96157
- Many dozens of others
97158

98159

99160
## History
100161

101162
### v3.0.0
102163

103-
- Added support for a custom `split` function to be passed on the options.
164+
- Added support for a custom `split` function to be passed on the options.
104165
- Removed support for splitting on brackets, since a [custom function][split-string] can be passed to do this now.
105166

106167
### v2.0.0
107168

108169
- Adds support for escaping with double or single quotes. See [escaping](#escaping) for examples.
109170
- Will no longer split inside brackets or braces. See [bracket support](#bracket-support) for examples.
110171

111-
If there are any regressions please create a [bug report](../../issues/new). Thanks!
172+
If there are any regressions please create a [bug report](../../issues/new). Thanks!

Diff for: FUNDING.yml

-2
This file was deleted.

0 commit comments

Comments
 (0)