Skip to content

Commit

Permalink
merging has to find
Browse files Browse the repository at this point in the history
  • Loading branch information
Mat Taylor authored and Mat Taylor committed Mar 13, 2023
1 parent 60c8ebb commit 596b8fe
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ The following methods are availble to all Objects via protoype inheritence, unle
| [`[@@iterator]`](docs/api.md#iterator) | Iterate through values of `this` |
| [`clean`](docs/api.md#clean) | Return a copy of `this` without falsey entries |
| [`filter`](docs/api.md#filter) | Create a copy of `this` with only entries that match a filter function |
| [`find`](docs/api.md#find) | Find keys of `this` which match a function |
| [`find`](docs/api.md#find) | Find keys of `this` which match a function or value |
| [`assign`](docs/api.md#assign) | Assign new properties to `this` |
| [`extend`](docs/api.md#extend) | Assign default properties to `this` |
| [`same`](docs/api.md#same) | Return new object like `this` with properties shared with another |
| [`diff`](docs/api.md#diff) | Return new object like `this` with properties not shared with another |
| [`delete`](docs/api.md#delete) | Remove keys from `this` |
| [`some`](docs/api.md#some) | Test a function against at least one entry of `this` |
| [`every`](docs/api.md#every) | Test a function against all entries of `this` |
| [`has`](docs/api.md#has) | Lookup key of `this` by value |
| [`at`](docs/api.md#at) | Lookup value by key path |
| [`$`](docs/api.md#fmt) | Coerce `this` into a string with configurable formatting |
| [`clone`](docs/api.md#clone) | Clone `this` with configurable depths |
Expand Down
25 changes: 5 additions & 20 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,18 @@ var o = { a: 1, b: 2 }.filter(v => v > 2) // {}

<a id="find"></a>

## `Object..find(function)`
## `Object..find(test)`

Return first key of `this` where value passes function
Function takes value and key as arguments.
If `test` is a function, Return first key of `this` which passes `test` where `test` takes each value and key as arguments. If `test` is not a function then return the first key of `this` where the value equals `test` (using `value.eq(test)`)

<div data-runkit>

```javascript
var o = { a: 1, b: 2 }.find(v => v > 1) // 'b'
var o = { a: 1, b: 2 }.find(v => v > 2) // null
var o = { a: 1, b: 2 }.find(2) // b
var o = { a: 1, b: 2 }.find(0) // undefined

```

</div>
Expand Down Expand Up @@ -286,23 +288,6 @@ var o = { a: 1, b: 2 }.every(v => v > 1) // false

</div>

<a id="has"></a>

## `Object..has(value)`

Returns first key of `this` where the value equals the argument, otherwise undefined.

<div data-runkit>

```javascript
var o = { a: 1, b: 2 }.has(2) // b
var o = { a: 1, b: 2 }.has(0) // undefined
;[1].has(1) // 1
;[].has(1) // undefined
```

</div>

<a id="at"></a>

## `Object..at(path)`
Expand Down
8 changes: 2 additions & 6 deletions objix.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ const
return r
},

has(o,d) {
return this.find(v => v.eq(o))
},

filter(f, r={}) {
for (let k in this) if (f(this[k],k)) r[k] = this[k]
return r
Expand All @@ -42,8 +38,8 @@ const
: this[C] == t || !i && this instanceof t
},

find(f) {
for (let k in this) if (f(this[k],k)) return k
find(t) {
for (let k in this) if (t.call ? t(this[k],k) : this[k].eq(t)) return k
},

extend(...a) {
Expand Down
2 changes: 1 addition & 1 deletion objix.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "objix",
"version": "1.11.9",
"version": "1.12.0",
"description": "A dangerously convienient, high performance and super lightweight utility (2.7kb) that injects methods into the Object prototype to sugar for many common use cases working with Javascript objects.",
"main": "objix.js",
"scripts": {
Expand Down

0 comments on commit 596b8fe

Please sign in to comment.