Skip to content

Commit 7ee09ce

Browse files
committed
feat(dot-notation): add pick, parse and parseKey methods
1 parent eeaf9fa commit 7ee09ce

File tree

88 files changed

+2028
-1582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2028
-1582
lines changed

.circleci/config.yml

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@ commands:
3434
name: Running unit tests on Node.js v<< parameters.node_version >> <<# parameters.coverage >>with coverage<</ parameters.coverage >>
3535
command: yarn test<<# parameters.coverage >>:coverage<</ parameters.coverage >>
3636

37-
e2e_tests:
38-
description: "Run integration tests"
39-
steps:
40-
- run:
41-
name: Installing Cypress binaries
42-
command: npx cypress install
43-
44-
- run:
45-
name: Running E2E integration tests
46-
command: yarn cypress
47-
4837
jobs:
4938
install:
5039
<<: *build-image
@@ -99,7 +88,6 @@ jobs:
9988
- install_package_dependencies
10089
- unit_test:
10190
node_version: 10
102-
- e2e_tests
10391

10492
test_node_12:
10593
docker:
@@ -111,7 +99,6 @@ jobs:
11199
- unit_test:
112100
node_version: 12
113101
coverage: true
114-
- e2e_tests
115102

116103
test_node_14:
117104
docker:
@@ -122,21 +109,6 @@ jobs:
122109
- install_package_dependencies
123110
- unit_test:
124111
node_version: 14
125-
- e2e_tests
126-
127-
end_to_end_tests:
128-
<<: *build-image
129-
steps:
130-
- checkout
131-
- attach_workspace:
132-
at: .
133-
- e2e_tests
134-
- store_artifacts:
135-
path: cypress/videos
136-
- store_artifacts:
137-
path: cypress/screenshots
138-
- store_test_results:
139-
path: results
140112

141113
build:
142114
<<: *build-image
@@ -160,6 +132,12 @@ jobs:
160132
- checkout
161133
- attach_workspace:
162134
at: .
135+
- add_ssh_keys:
136+
fingerprints:
137+
- $GITHUB_FINGERPRINT
138+
- run:
139+
name: Set git upstream
140+
command: git branch --set-upstream-to origin/${CIRCLE_BRANCH}
163141
- run:
164142
name: Running semantic-release workflow
165143
command: npx semantic-release
@@ -180,22 +158,19 @@ workflows:
180158
- test_node_10
181159
- test_node_12
182160
- test_node_14
183-
- end_to_end_tests:
184-
requires:
185-
- install
186161
- build:
187162
requires:
188-
- end_to_end_tests
163+
- lint
189164
- test_node_10
190165
- test_node_12
191166
- test_node_14
192-
# - release:
193-
# requires:
194-
# - build
195-
# filters:
196-
# branches:
197-
# only:
198-
# - master
199-
# - next
200-
# - pre/rc
201-
# - beta
167+
- release:
168+
requires:
169+
- build
170+
filters:
171+
branches:
172+
only:
173+
- master
174+
- next
175+
- pre/rc
176+
- beta

AUTHORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### @cookbook/dot-notation is authored by:
2+
* Marcos Gonçalves <contact@themgoncalves.com>

README.md

Lines changed: 154 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @template/typescript-library
1+
# @cookbook/dot-notation
22
> Typescript Library kick-off.
33
44
[![NPM Version][npm-image]][npm-url]
@@ -11,20 +11,165 @@
1111
[![install size][install-size-image]][install-size-url]
1212
[![gzip size][gzip-size-image]][gzip-size-url]
1313

14+
![](dot-notation.png)
15+
16+
## Demo
17+
18+
Play around with _dot-notation_ and experience **the magic**!
19+
20+
[![Edit @cookbook/dot-notation](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/arg-defdot-notation-td636?fontsize=14&hidenavigation=1&theme=dark)
21+
22+
## Installation
23+
24+
```sh
25+
npm install @cookbook/dot-notation --save
26+
#or
27+
yarn add @cookbook/dot-notation
28+
```
29+
30+
## How to use
31+
32+
### Picking a value
33+
34+
```js
35+
import dot from '@cookbook/dot-notation';
36+
37+
const source = {
38+
person: {
39+
name: {
40+
firstName: 'John',
41+
lastName: 'Doe'
42+
},
43+
address: [
44+
{
45+
street: 'Infinite Loop',
46+
city: 'Cupertino',
47+
state: 'CA',
48+
postalCode: 95014,
49+
country: 'United States'
50+
},
51+
]
52+
}
53+
};
54+
55+
dot.pick(source, 'person.name');
56+
//outputs { firstName: 'John', lastName: 'Doe' }
57+
58+
dot.pick(source, 'person.address[0].street');
59+
//outputs "Infinite Loop"
60+
```
61+
62+
### Parsing an object
63+
64+
#### Conventional parsing
65+
66+
```js
67+
import dot from '@cookbook/dot-notation';
68+
69+
const source = {
70+
'person.name.firstName': 'John',
71+
'person.name.lastName': 'Doe',
72+
'person.address[].street': 'Infinite Loop',
73+
'person.address[].city': 'Cupertino',
74+
'person.address[].postalCode': 95014,
75+
};
76+
77+
dot.parse(source);
78+
79+
/* outputs
80+
{
81+
person: {
82+
name: {
83+
firstName: 'John',
84+
lastName: 'Doe',
85+
},
86+
address: [
87+
{
88+
street: 'Infinite Loop',
89+
city: 'Cupertino',
90+
postalCode: 95014,
91+
},
92+
],
93+
},
94+
}
95+
*/
96+
```
97+
98+
#### With nested array
99+
100+
> where `[n]` represents the array index position to insert the element
101+
102+
```js
103+
import dot from '@cookbook/dot-notation';
104+
105+
const source = {
106+
'[0].street': 'Infinite Loop',
107+
'[0].city': 'Cupertino',
108+
'[0].postalCode': 95014,
109+
'[1].street': '1600 Amphitheatre',
110+
'[1].city': 'Mountain View',
111+
'[1].postalCode': 94043,
112+
'[2][0]': 'hobbies',
113+
'[2][1][0]': ['coding'],
114+
'[2][1][1]': ['gaming'],
115+
};
116+
117+
dot.parse(source);
118+
119+
/* outputs
120+
[
121+
{
122+
"postalCode": 95014,
123+
"city": "Cupertino",
124+
"street": "Infinite Loop"
125+
},
126+
{
127+
"postalCode": 94043,
128+
"city": "Mountain View",
129+
"street": "1600 Amphitheatre"
130+
},
131+
[
132+
"hobbies",
133+
[["coding"],["gaming"]]
134+
]
135+
]
136+
*/
137+
```
138+
139+
### Parsing single key
140+
141+
142+
```js
143+
import dot from '@cookbook/dot-notation';
144+
145+
const path = 'person.name';
146+
const value = 'John Doe';
147+
148+
dot.parseKey(path, value);
149+
150+
/* outputs
151+
{
152+
person: {
153+
name: 'John Doe',
154+
},
155+
}
156+
*/
157+
```
158+
14159
<!-- Markdown link & img dfn's -->
15160
[npm-image]: https://img.shields.io/npm/v/{PACKAGE_NAMESPACE}.svg?style=flat-square
16161
[npm-url]: https://npmjs.org/package/{PACKAGE_NAMESPACE}
17162
[npm-downloads]: https://img.shields.io/npm/dm/{PACKAGE_NAMESPACE}.svg?style=flat-square
18-
[circleci-image]: https://circleci.com/gh/{GITHUB_REPO_URL}.svg?style=svg
19-
[circleci-url]: https://circleci.com/gh/{GITHUB_REPO_URL}
20-
[stars-image]: https://img.shields.io/github/stars/{GITHUB_REPO_URL}.svg
21-
[stars-url]: https://github.com/{GITHUB_REPO_URL}/stargazers
22-
[vulnerabilities-image]: https://snyk.io/test/github/{GITHUB_REPO_URL}/badge.svg
23-
[vulnerabilities-url]: https://snyk.io/test/github/{GITHUB_REPO_URL}
24-
[issues-image]: https://img.shields.io/github/issues/{GITHUB_REPO_URL}.svg
163+
[circleci-image]: https://circleci.com/gh/the-cookbook/dot-notation.svg?style=svg
164+
[circleci-url]: https://circleci.com/gh/the-cookbook/dot-notation
165+
[stars-image]: https://img.shields.io/github/stars/the-cookbook/dot-notation.svg
166+
[stars-url]: https://github.com/the-cookbook/dot-notation/stargazers
167+
[vulnerabilities-image]: https://snyk.io/test/github/the-cookbook/dot-notation/badge.svg
168+
[vulnerabilities-url]: https://snyk.io/test/github/the-cookbook/dot-notation
169+
[issues-image]: https://img.shields.io/github/issues/the-cookbook/dot-notation.svg
25170
[issues-url]: https://github.com/cthe-ookbook/navigator/issues
26171
[awesome-image]: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg
27-
[awesome-url]: https://github.com/{GITHUB_REPO_URL}
172+
[awesome-url]: https://github.com/the-cookbook/dot-notation
28173
[install-size-image]: https://packagephobia.now.sh/badge?p={PACKAGE_NAMESPACE}
29174
[install-size-url]: https://packagephobia.now.sh/result?p={PACKAGE_NAMESPACE}
30175
[gzip-size-image]: http://img.badgesize.io/https://unpkg.com/{PACKAGE_NAMESPACE}/lib/navigator.min.js?compression=gzip

configurations/babel/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = function (api) {
2828
plugins: ['dynamic-import-node'],
2929
},
3030
production: {
31+
comments: false,
3132
plugins: [
3233
[
3334
'transform-remove-console',

configurations/prettier/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
printWidth: 120,
33
semi: true,
44
trailingComma: 'all',
5+
arrowParens: 'always',
56
singleQuote: true,
67
tabWidth: 2,
78
jsxBracketSameLine: false,

configurations/rollup/config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const resolve = require('rollup-plugin-node-resolve');
2+
const commonjs = require('rollup-plugin-commonjs');
3+
const { terser } = require('rollup-plugin-terser');
4+
5+
const pkg = require('../../package.json');
6+
const pkgName = 'dot';
7+
const global = [...Object.keys(pkg.dependencies)];
8+
9+
module.exports.pkgName = pkgName;
10+
module.exports = {
11+
input: './lib/index.js',
12+
output: {
13+
file: `lib/${pkgName}.min.js`,
14+
format: 'umd',
15+
name: pkgName,
16+
sourcemap: true,
17+
interop: false,
18+
},
19+
plugins: [
20+
resolve({
21+
mainFields: ['module', 'main'],
22+
}),
23+
commonjs(),
24+
terser(),
25+
],
26+
external: global,
27+
};

configurations/rollup/index.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
const resolve = require('rollup-plugin-node-resolve');
2-
const commonjs = require('rollup-plugin-commonjs');
3-
const { terser } = require('rollup-plugin-terser');
4-
5-
module.exports = {
6-
input: './lib/index.js',
7-
output: {
8-
file: 'lib/navigator.min.js',
9-
format: 'umd',
10-
name: 'navigator',
11-
sourcemap: true,
12-
},
13-
plugins: [
14-
resolve({
15-
mainFields: ['module', 'main'],
16-
}),
17-
commonjs(),
18-
terser(),
19-
],
20-
};
1+
module.exports = require('./config');

configurations/semantic-release/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const pkgName = require('../rollup').pkgName;
2+
13
module.exports = {
24
branches: [
35
{ name: 'master' },
@@ -18,7 +20,7 @@ module.exports = {
1820
[
1921
'@semantic-release/github',
2022
{
21-
assets: [{ path: 'release/*.tgz' }, { path: 'lib/navigator.min.js*(.map)', label: 'UMD build minified' }],
23+
assets: [{ path: 'release/*.tgz' }, { path: `lib/${pkgName}.min.js*(.map)`, label: 'UMD build minified' }],
2224
},
2325
],
2426
[

configurations/webpack/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const merge = require('webpack-merge');
1+
const merge = require('webpack-merge').merge;
22

33
module.exports = merge([require('./setup.dev'), require('./setup.common')]);

configurations/webpack/setup.common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
extensions: ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json'],
1616
modules: [path.resolve(__dirname, '../../', appSource), 'node_modules'],
1717
alias: {
18-
'@cookbook/navigator': path.resolve(__dirname, '../../src'),
18+
'@cookbook/dot-notation': path.resolve(__dirname, '../../src'),
1919
},
2020
},
2121
target: 'web',

0 commit comments

Comments
 (0)