Skip to content

Commit

Permalink
remove deprecated get function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Epps committed Nov 9, 2022
1 parent cfe269e commit 72808c0
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cdn/.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.0.2
10.0.0
7 changes: 0 additions & 7 deletions cdn/radash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,6 @@ const omit = (obj, keys) => {
);
};
const get = (value, funcOrPath, defaultValue = null) => {
if (isFunction(funcOrPath)) {
try {
return funcOrPath(value) ?? defaultValue;
} catch {
return defaultValue;
}
}
const segments = funcOrPath.split(/[\.\[\]]/g);
let current = value;
for (const key of segments) {
Expand Down
7 changes: 0 additions & 7 deletions cdn/radash.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,6 @@ var radash = (function (exports) {
);
};
const get = (value, funcOrPath, defaultValue = null) => {
if (isFunction(funcOrPath)) {
try {
return funcOrPath(value) ?? defaultValue;
} catch {
return defaultValue;
}
}
const segments = funcOrPath.split(/[\.\[\]]/g);
let current = value;
for (const key of segments) {
Expand Down
2 changes: 1 addition & 1 deletion cdn/radash.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radash",
"version": "9.0.2",
"version": "10.0.0",
"description": "Functional utility library - modern, simple, typed, powerful",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
17 changes: 6 additions & 11 deletions src/object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFunction, isObject } from './typed'
import { isObject } from './typed'

type LowercasedKeys<T extends Record<string, any>> = {
[P in keyof T & string as Lowercase<P>]: T[P]
Expand Down Expand Up @@ -190,21 +190,16 @@ export const omit = <T, TKeys extends keyof T>(
}

/**
* Warning: Passing a function has been @deprecated
* and will be removed in the next major version.
* Dynamically get a nested value from an array or
* object with a string.
*
* @example get(person, 'friends[0].name')
*/
export const get = <T, K>(
value: T,
funcOrPath: ((t: T) => K) | string,
funcOrPath: string,
defaultValue: K | null = null
): K | null => {
if (isFunction(funcOrPath)) {
try {
return (funcOrPath as Function)(value) ?? defaultValue
} catch {
return defaultValue
}
}
const segments = (funcOrPath as string).split(/[\.\[\]]/g)
let current: any = value
for (const key of segments) {
Expand Down
28 changes: 0 additions & 28 deletions src/tests/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,34 +241,6 @@ describe('object module', () => {
assert.equal(_.get(null, 'name'), null)
assert.equal(_.get(undefined, 'name'), null)
})
test('returns specified value or default using function', () => {
assert.equal(
_.get(jay, x => x.name),
'jay'
)
assert.equal(
_.get(jay, x => x.friends?.[0].age),
17
)
assert.equal(
_.get(
jay,
x => {
throw 'error'
},
17
),
17
)
assert.equal(
_.get({ age: undefined }, x => x.age, 22),
22
)
assert.equal(
_.get(jay, x => x.friends?.[0].friends?.[0].friends?.[0].age, 22),
22
)
})
test('returns specified value or default using path', () => {
assert.equal(_.get({ age: undefined }, 'age', 22), 22)
assert.equal(_.get(jay, 'friends[0].age'), 17)
Expand Down

0 comments on commit 72808c0

Please sign in to comment.