Skip to content

Commit 2538187

Browse files
committed
Import nested-obj history into history/nested-obj/
2 parents 2aebf77 + fb5236b commit 2538187

File tree

16 files changed

+644
-0
lines changed

16 files changed

+644
-0
lines changed

history/nested-obj/.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

history/nested-obj/.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules/
2+
dist/
3+
main/
4+
module/
5+
coverage/

history/nested-obj/.eslintrc.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
module.exports = {
2+
plugins: ['prettier'],
3+
extends: ['eslint:recommended', 'prettier'],
4+
parser: 'esprima',
5+
parserOptions: {
6+
ecmaVersion: 11,
7+
requireConfigFile: false,
8+
sourceType: 'module',
9+
ecmaFeatures: {
10+
jsx: true
11+
}
12+
},
13+
env: {
14+
es6: true,
15+
browser: true,
16+
node: true,
17+
jest: true
18+
},
19+
rules: {
20+
'no-debugger': 2,
21+
'no-alert': 2,
22+
'no-await-in-loop': 0,
23+
'no-prototype-builtins': 0,
24+
'no-return-assign': ['error', 'except-parens'],
25+
'no-restricted-syntax': [
26+
2,
27+
'ForInStatement',
28+
'LabeledStatement',
29+
'WithStatement'
30+
],
31+
'no-unused-vars': [
32+
0,
33+
{
34+
ignoreSiblings: true,
35+
argsIgnorePattern: 'React|res|next|^_'
36+
}
37+
],
38+
'prefer-const': [
39+
'error',
40+
{
41+
destructuring: 'all'
42+
}
43+
],
44+
'no-unused-expressions': [
45+
2,
46+
{
47+
allowTaggedTemplates: true
48+
}
49+
],
50+
'no-console': 1,
51+
'comma-dangle': 2,
52+
'jsx-quotes': [2, 'prefer-double'],
53+
'linebreak-style': ['error', 'unix'],
54+
quotes: [
55+
2,
56+
'single',
57+
{
58+
avoidEscape: true,
59+
allowTemplateLiterals: true
60+
}
61+
],
62+
'prettier/prettier': [
63+
'error',
64+
{
65+
trailingComma: 'none',
66+
singleQuote: true,
67+
printWidth: 80
68+
}
69+
]
70+
}
71+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
6+
pull_request:
7+
types: [opened, reopened]
8+
9+
workflow_dispatch:
10+
11+
jobs:
12+
run-tests:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: checkout 🛎️
16+
uses: actions/checkout@v4
17+
18+
- name: node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20.9.0
22+
23+
- name: deps
24+
run: |
25+
yarn
26+
yarn build
27+
28+
- name: tests
29+
run: |
30+
yarn test

history/nested-obj/.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Runtime data
7+
pids
8+
*.pid
9+
*.seed
10+
11+
# dist
12+
main
13+
module
14+
15+
# Directory for instrumented libs generated by jscoverage/JSCover
16+
lib-cov
17+
18+
# Coverage directory used by tools like istanbul
19+
coverage
20+
21+
# nyc test coverage
22+
.nyc_output
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directories
28+
node_modules
29+
jspm_packages
30+
31+
# Optional npm cache directory
32+
.npm
33+
34+
# Optional REPL history
35+
.node_repl_history
36+
37+
# Editors
38+
.idea
39+
40+
# Lib
41+
lib
42+
43+
# npm package lock
44+
package-lock.json
45+
yarn.lock
46+
47+
# others
48+
.DS_Store

history/nested-obj/.npmignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
*.log
2+
npm-debug.log*
3+
4+
protobuf
5+
out
6+
*.proto
7+
8+
# snapshots
9+
*.snap
10+
11+
# Coverage directory used by tools like istanbul
12+
coverage
13+
.nyc_output
14+
15+
# Dependency directories
16+
node_modules
17+
18+
# npm package lock
19+
package-lock.json
20+
yarn.lock
21+
22+
# project files
23+
__snapshots__
24+
__fixtures__
25+
__tests__
26+
.editorconfig
27+
.eslintignore
28+
.eslintrc.js
29+
.gitignore
30+
.travis.yml
31+
.vscode
32+
CHANGELOG.md

history/nested-obj/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scripts-prepend-node-path=true
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"[javascriptreact]": {
4+
"editor.formatOnSave": false
5+
},
6+
"[javascript]": {
7+
"editor.formatOnSave": false
8+
},
9+
"editor.codeActionsOnSave": {
10+
"source.fixAll.eslint": "explicit"
11+
},
12+
"eslint.validate": [
13+
"javascript",
14+
"javascriptreact"
15+
],
16+
"editor.insertSpaces": true,
17+
"editor.tabSize": 2
18+
}

history/nested-obj/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Dan Lynch <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

history/nested-obj/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# nested-obj
2+
3+
<p align="center" width="100%">
4+
<a href="https://github.com/pyramation/nested-obj/actions/workflows/run-tests.yaml">
5+
<img height="20" src="https://github.com/pyramation/nested-obj/actions/workflows/run-tests.yaml/badge.svg" />
6+
</a>
7+
<a href="https://github.com/pyramation/nested-obj/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
8+
<a href="https://github.com/pyramation/nested-obj/blob/main/LICENSE-Apache"><img height="20" src="https://img.shields.io/badge/license-Apache-blue.svg"></a>
9+
</p>
10+
11+
`nested-obj` is a simple and lightweight JavaScript utility library for safely accessing and modifying nested properties in objects using string paths.
12+
13+
## Features
14+
15+
- **Get**: Safely access nested properties in an object.
16+
- **Set**: Set a value at a specific path in an object. Does not overwrite if the value is undefined.
17+
- **Has**: Check if a specific path exists within an object.
18+
19+
## Installation
20+
21+
```bash
22+
npm install nested-obj
23+
```
24+
25+
## Usage
26+
27+
### Get
28+
29+
Retrieve a nested property value from an object.
30+
31+
```ts
32+
import objectPath from 'nested-obj';
33+
34+
const obj = {
35+
user: {
36+
name: 'John Doe',
37+
address: {
38+
street: '123 Main St',
39+
city: 'Anytown'
40+
}
41+
}
42+
};
43+
44+
const userName = objectPath.get(obj, 'user.name');
45+
console.log(userName); // 'John Doe'
46+
```
47+
48+
### Set
49+
50+
Set a value at a specific path in an object. If any part of the path does not exist, it will be created.
51+
52+
```ts
53+
objectPath.set(obj, 'user.address.zip', '12345');
54+
console.log(obj.user.address.zip); // '12345'
55+
```
56+
57+
### Has
58+
59+
Check if a path exists within an object.
60+
61+
```ts
62+
const hasCity = objectPath.has(obj, 'user.address.city');
63+
console.log(hasCity); // true
64+
```
65+
66+
## Running Tests
67+
68+
To run tests, execute the following command:
69+
70+
```sh
71+
npm test
72+
```
73+
74+
or for continuous
75+
76+
```sh
77+
npm test:watch
78+
```

0 commit comments

Comments
 (0)