Skip to content

Commit 9aabe4b

Browse files
committed
feat(extend): New extend method to add the methods from object-dot to the Object protoype chain so that you can call it directly like so: Object.get(...)
1 parent 3f222ad commit 9aabe4b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

__tests__/object-dot.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,12 @@ describe('exists', () => {
121121
).toBe(false)
122122
})
123123
})
124+
125+
describe('extend', () => {
126+
const object = { foo: { bar: { a: { b: 'foo' } } } }
127+
objectd.extend()
128+
Object.set(object, 'foo.isCool', true)
129+
expect(object.foo.isCool).toBe(true)
130+
expect(Object.get(object, 'foo.bar.a.b')).toBe('foo')
131+
expect(Object.exists(object, 'foo.bar')).toBe(true)
132+
})

lib/object-dot.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ function exists ({ object, path }) {
3636
return true
3737
}
3838

39-
module.exports = { set, get, exists }
39+
function extend () {
40+
/* eslint-disable */
41+
Object.prototype.get = get
42+
Object.prototype.set = set
43+
Object.prototype.exists = exists
44+
/* eslint-enable */
45+
}
46+
47+
module.exports = { set, get, exists, extend }

0 commit comments

Comments
 (0)