Skip to content

Commit

Permalink
fix: use lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
simonguo committed Apr 11, 2024
1 parent 3dc2961 commit eb62127
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 115 deletions.
24 changes: 24 additions & 0 deletions package-lock.json

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

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"types"
],
"homepage": "https://github.com/rsuite/schema-typed#readme",
"dependencies": {
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/node": "^20.12.5",
Expand Down
21 changes: 0 additions & 21 deletions src/utils/get.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export { default as get } from 'lodash.get';
export { default as set } from 'lodash.set';
export { default as basicEmptyCheck } from './basicEmptyCheck';
export { default as checkRequired } from './checkRequired';
export { default as createValidator } from './createValidator';
export { default as createValidatorAsync } from './createValidatorAsync';
export { default as isEmpty } from './isEmpty';
export { default as formatErrorMessage } from './formatErrorMessage';
export { default as get } from './get';
export { default as set } from './set';
export { default as shallowEqual } from './shallowEqual';
export { default as pathTransform } from './pathTransform';
22 changes: 0 additions & 22 deletions src/utils/set.ts

This file was deleted.

72 changes: 2 additions & 70 deletions test/utilsSpec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import chai, { expect } from 'chai';
import {
formatErrorMessage,
checkRequired,
get,
set,
shallowEqual,
pathTransform
} from '../src/utils';
import chai from 'chai';
import { formatErrorMessage, checkRequired, shallowEqual, pathTransform } from '../src/utils';

chai.should();

Expand Down Expand Up @@ -70,67 +63,6 @@ describe('#utils', () => {
});
});

describe('## get', () => {
it('Should get the value of the object', () => {
const obj = { a: { b: { c: 1 } } };
get(obj, 'a.b.c').should.equal(1);
get(obj, 'a.b').should.deep.equal({ c: 1 });
get(obj, 'a').should.deep.equal({ b: { c: 1 } });

expect(get(obj, 'a.b.d')).to.be.undefined;
expect(get(obj, 'a.b.d.e')).to.be.undefined;
expect(get(obj, 'a.b.d.e.f')).to.be.undefined;
});

it('Should get the value of the array', () => {
const obj = { a: [{ b: 1 }, { b: 2 }] };
get(obj, 'a.0.b').should.equal(1);
get(obj, 'a.1.b').should.equal(2);
expect(get(obj, 'a.2.b')).to.be.undefined;
});

it('Should get the value of the array and object', () => {
const obj = { a: [{ b: { c: 1 } }, { b: { c: 2 } }] };
get(obj, 'a.0.b.c').should.equal(1);
get(obj, 'a.1.b.c').should.equal(2);
expect(get(obj, 'a.2.b.c')).to.be.undefined;
});

it('Should return the default value', () => {
const obj = { a: { b: [{ c: 1 }, { c: 2 }] } };
expect(get(obj, 'a.b.2.c', 10)).to.equal(10);
expect(get(undefined, 'a.b', 10)).to.equal(10);
});
});

describe('## set', () => {
it('Should set the value of the object', () => {
const obj = { a: { b: { c: 1 } } };
set(obj, 'a.b.c', 2);
obj.a.b.c.should.equal(2);
set(obj, 'a.b', { c: 3 });
obj.a.b.should.deep.equal({ c: 3 });
set(obj, 'a', { b: { c: 4 } });
obj.a.should.deep.equal({ b: { c: 4 } });
});

it('Should set the value of the array', () => {
const obj = { a: [{ b: 1 }, { b: 2 }] };
set(obj, 'a.0.b', 3);
obj.a[0].b.should.equal(3);
set(obj, 'a.1.b', 4);
obj.a[1].b.should.equal(4);
});

it('Should set the value of the array and object', () => {
const obj = { a: [{ b: { c: 1 } }, { b: { c: 2 } }] };
set(obj, 'a.0.b.c', 3);
obj.a[0].b.c.should.equal(3);
set(obj, 'a.1.b.c', 4);
obj.a[1].b.c.should.equal(4);
});
});

describe('## shallowEqual', () => {
it('Should compare the object', () => {
const obj1 = { a: 1, b: 2 };
Expand Down

0 comments on commit eb62127

Please sign in to comment.