Skip to content

Commit

Permalink
Merge pull request #50 from hckrnews/feature/get-keys
Browse files Browse the repository at this point in the history
Feature/get keys
  • Loading branch information
w3nl authored Feb 9, 2021
2 parents b878e43 + 625db83 commit 64f3a1e
Show file tree
Hide file tree
Showing 8 changed files with 37,559 additions and 7,351 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module.exports = {
node: true,
browser: true
},
globals: {
describe: false,
it: false ,
expect: false
},
extends: ['@hckrnews/eslint-config'],
parserOptions: {
sourceType: "module",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [12.x, 14.x]

steps:
- uses: actions/checkout@v1
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist: trusty
addons:
language: node_js
node_js:
- "10"
- "12"
- "14"
before_script:
Expand Down
47 changes: 36 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ or
## Usage

Example usage:
```
```javascript
const flatter = new Obj({
a: 1,
b: 2,
Expand All @@ -30,7 +30,7 @@ const flatter = new Obj({
```

You can get the flat object by:
```
```javascript
flatter.flat

{
Expand All @@ -45,7 +45,7 @@ flatter.flat
```

You can get the object entries by:
```
```javascript
flatter.entries()

[
Expand All @@ -60,60 +60,85 @@ flatter.entries()
```

You can get the object keys by:
```
```javascript
flatter.keys()

["a", "b", "c.0", "c.1", "d.e", "d.f", "g.h.i"]
```

You can get the object values by:
```
```javascript
flatter.values()

[1, 2, 3, 4, 5, 6, 7]
```

You can get the object length by:
```
```javascript
flatter.length

7
```

You can get by key by:
```
```javascript
flatter.getByKey("g.h.i")

7
```

Or set a fallback value by:
```
```javascript
flatter.getByKey("x.y.z", 42)

42
```

```
```javascript
flatter.getByKey("d")

{ e: 5, f: 6 }
```

Check if the object has a key:
```
```javascript
flatter.has("g.h.i")

true
```

Check if the object has key includes a value:
```
```javascript
flatter.includes("g.h")

true
```

You can get only some fields from the object:
```javascript
flatter.getKeys(['a', 'c', 'd.e', 'g.h'])

{
a: 1,
c: [3, 4],
'd.e': 5,
'g.h': { i: 7 },
}
```

And you can also get some fields from the object in the flat format:
```javascript
flatter.getFlatKeys(['a', 'c', 'd.e', 'g.h'])

{
a: 1,
'c.0': 3,
'c.1': 4,
'd.e': 5,
'g.h.i': 7,
}
```

[npm-url]: https://www.npmjs.com/package/@hckrnews/objects
[npm-image]: https://img.shields.io/npm/v/@hckrnews/objects.svg
[travis-url]: https://travis-ci.org/hckrnews/objects
Expand Down
Loading

0 comments on commit 64f3a1e

Please sign in to comment.