Skip to content

Commit

Permalink
feat: init is primitive funciton
Browse files Browse the repository at this point in the history
Apply suggestions from code review

Co-authored-by: Rich Trott <rtrott@gmail.com>

chore: use jest 'toBeFalsy'

fix: inRange test (#5821)
  • Loading branch information
Denys Bondarenko authored and denbon05 committed May 7, 2024
1 parent c7c70a7 commit 00adccd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lodash",
"version": "5.0.0",
"version": "5.1.0",
"license": "MIT",
"private": true,
"main": "dist/lodash.js",
Expand Down Expand Up @@ -47,4 +47,4 @@
"yarn": "1.22.19"
},
"engineStrict": true
}
}
8 changes: 7 additions & 1 deletion src/inRange.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import baseInRange from './.internal/baseInRange.js';
import toFinite from './toFinite';
import toNumber from './toNumber';

/**
* Checks if `number` is between `start` and up to, but not including, `end`. If
Expand Down Expand Up @@ -37,11 +39,15 @@ import baseInRange from './.internal/baseInRange.js';
* // => true
*/
function inRange(number, start, end) {
start = toFinite(start);
if (end === undefined) {
end = start;
start = 0;
} else {
end = toFinite(end);
}
return baseInRange(+number, +start, +end);
number = toNumber(number);
return baseInRange(number, start, end);
}

export default inRange;
24 changes: 24 additions & 0 deletions src/isPrimitive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Checks if `value` is a primitive.
*
* @since 4.1.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a primitive, else `false`.
* @link https://developer.mozilla.org/en-US/docs/Glossary/Primitive
* @example
*
* isPrimitive('abc')
* // => true
*
* isPrimitive(null)
* // => true
*
* isPrimitive({})
* // => false
*/
function isPrimitive(value?: unknown): boolean {
return value !== Object(value);
}

export default isPrimitive;
2 changes: 1 addition & 1 deletion test/inRange.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ describe('inRange', () => {
inRange(-1, -1, NaN),
];

expect(actual, lodashStable.map(actual).toEqual(stubTrue));
expect(actual).toEqual(lodashStable.map(actual,stubTrue));
});
});
24 changes: 24 additions & 0 deletions test/isPrimitive.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import isPrimitive from '../src/isPrimitive';

describe('isPrimitive', () => {
it('should return `true` for primitive', () => {
expect(isPrimitive()).toBeTruthy();
expect(isPrimitive('a')).toBeTruthy();
expect(isPrimitive(13)).toBeTruthy();
expect(isPrimitive(0)).toBeTruthy();
expect(isPrimitive(true)).toBeTruthy();
expect(isPrimitive(false)).toBeTruthy();
expect(isPrimitive(null)).toBeTruthy();
expect(isPrimitive(10n)).toBeTruthy();
});

it('should return `false` for non-primitive', () => {
expect(isPrimitive(Object('args'))).toBeFalsy();
expect(isPrimitive({ title: 'lodash' })).toBeFalsy();
expect(isPrimitive([1, 2, 3])).toBeFalsy();
expect(isPrimitive(new Date())).toBeFalsy();
expect(isPrimitive(new Error())).toBeFalsy();
expect(isPrimitive(/lodash/)).toBeFalsy();
expect(isPrimitive({ 0: 1, length: 1 })).toBeFalsy();
});
});

0 comments on commit 00adccd

Please sign in to comment.