-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: optimize lodash utils (#118)
* refactor: adjust utils of lodash * test: add test case * chore: config lint-staged and commitlint * refactor: adjust memoize * chore: update rollup config * test: fix test case * refactor: fix cr issue
- Loading branch information
Showing
43 changed files
with
578 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx --no-install commitlint --edit "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isArray } from '../../../src/lodash'; | ||
|
||
describe('isArray', () => { | ||
it('array literal', () => { | ||
expect(isArray([])).toBe(true); | ||
expect(isArray([1, 2, 3])).toBe(true); | ||
}); | ||
|
||
it('array object', () => { | ||
expect(isArray(new Array(10))).toBe(true); | ||
expect(isArray(new Array(10).fill(0))).toBe(true); | ||
}); | ||
|
||
it('not array', () => { | ||
expect(isArray(0)).toBe(false); | ||
expect(isArray(123)).toBe(false); | ||
expect(isArray('')).toBe(false); | ||
expect(isArray('abc')).toBe(false); | ||
expect(isArray({})).toBe(false); | ||
expect(isArray(null)).toBe(false); | ||
expect(isArray(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { isDate } from '../../../src/lodash'; | ||
|
||
describe('isDate', () => { | ||
it('date', () => { | ||
expect(isDate(new Date())).toBe(true); | ||
expect(isDate(new Date('2024'))).toBe(true); | ||
}); | ||
|
||
it('not date', () => { | ||
expect(isDate(0)).toBe(false); | ||
expect(isDate(123)).toBe(false); | ||
expect(isDate('')).toBe(false); | ||
expect(isDate('abc')).toBe(false); | ||
expect(isDate([])).toBe(false); | ||
expect(isDate({})).toBe(false); | ||
expect(isDate(null)).toBe(false); | ||
expect(isDate(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isDecimal } from '../../../src/lodash'; | ||
|
||
describe('isDecimal', () => { | ||
it('decimal', () => { | ||
expect(isDecimal(0.1)).toBe(true); | ||
expect(isDecimal(0.123)).toBe(true); | ||
expect(isDecimal(0.123456789)).toBe(true); | ||
expect(isDecimal(0.1234567890123456789)).toBe(true); | ||
expect(isDecimal(0.12345678901234567890123456789)).toBe(true); | ||
expect(isDecimal(0.123456789012345678901234567890123456789)).toBe(true); | ||
}); | ||
|
||
it('not decimal', () => { | ||
expect(isDecimal(0)).toBe(false); | ||
expect(isDecimal(123)).toBe(false); | ||
expect(isDecimal('')).toBe(false); | ||
expect(isDecimal('abc')).toBe(false); | ||
expect(isDecimal([])).toBe(false); | ||
expect(isDecimal({})).toBe(false); | ||
expect(isDecimal(null)).toBe(false); | ||
expect(isDecimal(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { isElement } from '../../../src/lodash'; | ||
|
||
describe('isElement', () => { | ||
it('element', () => { | ||
expect(isElement(document.createElement('div'))).toBe(true); | ||
expect(isElement(document.createElement('span'))).toBe(true); | ||
expect(isElement(document.createElement('a'))).toBe(true); | ||
expect(isElement(document)).toBe(true); | ||
}); | ||
|
||
it('not element', () => { | ||
expect(isElement(window)).toBe(false); | ||
expect(isElement(0)).toBe(false); | ||
expect(isElement(123)).toBe(false); | ||
expect(isElement('')).toBe(false); | ||
expect(isElement('abc')).toBe(false); | ||
expect(isElement([])).toBe(false); | ||
expect(isElement({})).toBe(false); | ||
expect(isElement(null)).toBe(false); | ||
expect(isElement(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { isEven } from '../../../src/lodash'; | ||
|
||
describe('isEven', () => { | ||
it('even', () => { | ||
expect(isEven(0)).toBe(true); | ||
expect(isEven(2)).toBe(true); | ||
expect(isEven(4)).toBe(true); | ||
expect(isEven(6)).toBe(true); | ||
expect(isEven(8)).toBe(true); | ||
expect(isEven(10)).toBe(true); | ||
expect(isEven(12)).toBe(true); | ||
expect(isEven(14)).toBe(true); | ||
expect(isEven(16)).toBe(true); | ||
expect(isEven(18)).toBe(true); | ||
expect(isEven(20)).toBe(true); | ||
}); | ||
|
||
it('not even', () => { | ||
expect(isEven(1)).toBe(false); | ||
expect(isEven(3)).toBe(false); | ||
expect(isEven(5)).toBe(false); | ||
expect(isEven(7)).toBe(false); | ||
expect(isEven(9)).toBe(false); | ||
expect(isEven(11)).toBe(false); | ||
expect(isEven(13)).toBe(false); | ||
expect(isEven(15)).toBe(false); | ||
expect(isEven(17)).toBe(false); | ||
expect(isEven(19)).toBe(false); | ||
expect(isEven(21)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isFinite } from '../../../src/lodash'; | ||
|
||
describe('isFinite', () => { | ||
it('finite', () => { | ||
expect(isFinite(0)).toBe(true); | ||
expect(isFinite(123)).toBe(true); | ||
expect(isFinite(0.1)).toBe(true); | ||
expect(isFinite(0.123)).toBe(true); | ||
expect(isFinite(0.123456789)).toBe(true); | ||
expect(isFinite(0.1234567890123456789)).toBe(true); | ||
expect(isFinite(0.12345678901234567890123456789)).toBe(true); | ||
expect(isFinite(0.123456789012345678901234567890123456789)).toBe(true); | ||
}); | ||
|
||
it('not finite', () => { | ||
expect(isFinite(Infinity)).toBe(false); | ||
expect(isFinite(-Infinity)).toBe(false); | ||
expect(isFinite(NaN)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isFunction } from '../../../src/lodash'; | ||
|
||
describe('isFunction', () => { | ||
it('function', () => { | ||
expect(isFunction(() => {})).toBe(true); | ||
expect(isFunction(function () {})).toBe(true); | ||
expect(isFunction(new Function())).toBe(true); | ||
}); | ||
|
||
it('not function', () => { | ||
expect(isFunction(0)).toBe(false); | ||
expect(isFunction(123)).toBe(false); | ||
expect(isFunction('')).toBe(false); | ||
expect(isFunction('abc')).toBe(false); | ||
expect(isFunction([])).toBe(false); | ||
expect(isFunction({})).toBe(false); | ||
expect(isFunction(null)).toBe(false); | ||
expect(isFunction(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { isInteger } from '../../../src/lodash'; | ||
|
||
describe('isInteger', () => { | ||
it('integer', () => { | ||
expect(isInteger(0)).toBe(true); | ||
expect(isInteger(123)).toBe(true); | ||
expect(isInteger(-123)).toBe(true); | ||
}); | ||
|
||
it('not integer', () => { | ||
expect(isInteger(0.1)).toBe(false); | ||
expect(isInteger(0.123)).toBe(false); | ||
expect(isInteger(0.123456789)).toBe(false); | ||
expect(isInteger(0.1234567890123456789)).toBe(false); | ||
expect(isInteger(0.12345678901234567890123456789)).toBe(false); | ||
expect(isInteger(0.123456789012345678901234567890123456789)).toBe(false); | ||
expect(isInteger(Infinity)).toBe(false); | ||
expect(isInteger(-Infinity)).toBe(false); | ||
expect(isInteger(NaN)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { isNegative } from '../../../src/lodash'; | ||
|
||
describe('isNegative', () => { | ||
it('negative', () => { | ||
expect(isNegative(-1)).toBe(true); | ||
expect(isNegative(-0.1)).toBe(true); | ||
expect(isNegative(-0.123)).toBe(true); | ||
expect(isNegative(-0.123456789)).toBe(true); | ||
expect(isNegative(-0.1234567890123456789)).toBe(true); | ||
expect(isNegative(-0.12345678901234567890123456789)).toBe(true); | ||
expect(isNegative(-0.123456789012345678901234567890123456789)).toBe(true); | ||
}); | ||
|
||
it('not negative', () => { | ||
expect(isNegative(0)).toBe(false); | ||
expect(isNegative(1)).toBe(false); | ||
expect(isNegative(0.1)).toBe(false); | ||
expect(isNegative(0.123)).toBe(false); | ||
expect(isNegative(0.123456789)).toBe(false); | ||
expect(isNegative(0.1234567890123456789)).toBe(false); | ||
expect(isNegative(0.12345678901234567890123456789)).toBe(false); | ||
expect(isNegative(0.123456789012345678901234567890123456789)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { isNil } from '../../../src/lodash'; | ||
|
||
describe('isNil', () => { | ||
it('nil', () => { | ||
expect(isNil(null)).toBe(true); | ||
expect(isNil(undefined)).toBe(true); | ||
}); | ||
|
||
it('not nil', () => { | ||
expect(isNil(0)).toBe(false); | ||
expect(isNil(123)).toBe(false); | ||
expect(isNil('')).toBe(false); | ||
expect(isNil('abc')).toBe(false); | ||
expect(isNil([])).toBe(false); | ||
expect(isNil({})).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { isNull } from '../../../src/lodash'; | ||
|
||
describe('isNull', () => { | ||
it('null', () => { | ||
expect(isNull(null)).toBe(true); | ||
}); | ||
|
||
it('not null', () => { | ||
expect(isNull(0)).toBe(false); | ||
expect(isNull(123)).toBe(false); | ||
expect(isNull('')).toBe(false); | ||
expect(isNull('abc')).toBe(false); | ||
expect(isNull([])).toBe(false); | ||
expect(isNull({})).toBe(false); | ||
expect(isNull(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { isNumberEqual } from '../../../src/lodash'; | ||
|
||
describe('isNumberEqual', () => { | ||
it('equal', () => { | ||
expect(isNumberEqual(0, 0)).toBe(true); | ||
expect(isNumberEqual(1, 1)).toBe(true); | ||
expect(isNumberEqual(0.1, 0.1)).toBe(true); | ||
expect(isNumberEqual(0.123, 0.123)).toBe(true); | ||
expect(isNumberEqual(0.123456789, 0.123456789)).toBe(true); | ||
expect(isNumberEqual(0.1234567890123456789, 0.1234567890123456789)).toBe(true); | ||
expect(isNumberEqual(0.12345678901234567890123456789, 0.12345678901234567890123456789)).toBe(true); | ||
expect(isNumberEqual(0.123456789012345678901234567890123456789, 0.123456789012345678901234567890123456789)).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it('not equal', () => { | ||
expect(isNumberEqual(0, 1)).toBe(false); | ||
expect(isNumberEqual(1, 0)).toBe(false); | ||
expect(isNumberEqual(0.1, 0.2)).toBe(false); | ||
expect(isNumberEqual(0.123, 0.124)).toBe(false); | ||
expect(isNumberEqual(0.123456789, 0.123456788, 0.0000000001)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { isNumber } from '../../../src/lodash'; | ||
|
||
describe('isNumber', () => { | ||
it('number literal', () => { | ||
expect(isNumber(0)).toBe(true); | ||
expect(isNumber(123)).toBe(true); | ||
expect(isNumber(0.1)).toBe(true); | ||
expect(isNumber(123.4)).toBe(true); | ||
expect(isNumber(-0)).toBe(true); | ||
expect(isNumber(-123)).toBe(true); | ||
expect(isNumber(-0.1)).toBe(true); | ||
expect(isNumber(-123.4)).toBe(true); | ||
}); | ||
|
||
it('number object', () => { | ||
expect(isNumber(new Number(0))).toBe(false); | ||
expect(isNumber(new Number(123))).toBe(false); | ||
expect(isNumber(new Number(0.1))).toBe(false); | ||
expect(isNumber(new Number(123.4))).toBe(false); | ||
}); | ||
|
||
it('not number', () => { | ||
expect(isNumber('')).toBe(false); | ||
expect(isNumber('abc')).toBe(false); | ||
expect(isNumber([])).toBe(false); | ||
expect(isNumber({})).toBe(false); | ||
expect(isNumber(null)).toBe(false); | ||
expect(isNumber(undefined)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { isOdd } from '../../../src/lodash'; | ||
|
||
describe('isOdd', () => { | ||
it('odd', () => { | ||
expect(isOdd(1)).toBe(true); | ||
expect(isOdd(3)).toBe(true); | ||
expect(isOdd(5)).toBe(true); | ||
expect(isOdd(7)).toBe(true); | ||
expect(isOdd(9)).toBe(true); | ||
expect(isOdd(11)).toBe(true); | ||
expect(isOdd(13)).toBe(true); | ||
expect(isOdd(15)).toBe(true); | ||
expect(isOdd(17)).toBe(true); | ||
expect(isOdd(19)).toBe(true); | ||
}); | ||
|
||
it('not odd', () => { | ||
expect(isOdd(0)).toBe(false); | ||
expect(isOdd(2)).toBe(false); | ||
expect(isOdd(4)).toBe(false); | ||
expect(isOdd(6)).toBe(false); | ||
expect(isOdd(8)).toBe(false); | ||
expect(isOdd(10)).toBe(false); | ||
expect(isOdd(12)).toBe(false); | ||
expect(isOdd(14)).toBe(false); | ||
expect(isOdd(16)).toBe(false); | ||
expect(isOdd(18)).toBe(false); | ||
expect(isOdd(20)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { isString } from '../../../src/lodash'; | ||
|
||
describe('isString', () => { | ||
it('string literal', () => { | ||
expect(isString('')).toBe(true); | ||
expect(isString('abc')).toBe(true); | ||
expect(isString('123')).toBe(true); | ||
}); | ||
|
||
it('string object', () => { | ||
expect(isString(new String(''))).toBe(false); | ||
expect(isString(new String('abc'))).toBe(false); | ||
expect(isString(new String('123'))).toBe(false); | ||
}); | ||
|
||
it('not string', () => { | ||
expect(isString(0)).toBe(false); | ||
expect(isString(123)).toBe(false); | ||
expect(isString([])).toBe(false); | ||
expect(isString({})).toBe(false); | ||
expect(isString(null)).toBe(false); | ||
expect(isString(undefined)).toBe(false); | ||
}); | ||
}); |
Oops, something went wrong.