Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add _.isBigint #434

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cdn/radash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const isNumber = (value) => {
return false;
}
};
const isBigInt = (value) => {
return typeof value === "bigint";
};
const isDate = (value) => {
return Object.prototype.toString.call(value) === "[object Date]";
};
Expand All @@ -46,6 +49,8 @@ const isEmpty = (value) => {
return true;
if (isNumber(value))
return value === 0;
if (isBigInt(value))
return value === 0n;
if (isDate(value))
return isNaN(value.getTime());
if (isFunction(value))
Expand Down Expand Up @@ -937,4 +942,4 @@ const trim = (str, charsToTrim = " ") => {
return str.replace(regex, "");
};

export { all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, select, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
export { all, alphabetical, assign, boil, callable, camel, capitalize, chain, clone, cluster, compose, construct, counting, crush, dash, debounce, defer, diff, draw, first, flat, fork, get, group, guard, inRange, intersects, invert, isArray, isBigInt, isDate, isEmpty, isEqual, isFloat, isFunction, isInt, isNumber, isObject, isPrimitive, isPromise, isString, isSymbol, iterate, keys, last, list, listify, lowerize, map, mapEntries, mapKeys, mapValues, max, memo, merge, min, objectify, omit, parallel, partial, partob, pascal, pick, proxied, random, range, reduce, replace, replaceOrAppend, retry, select, series, set, shake, shift, shuffle, sift, sleep, snake, sort, sum, template, throttle, title, toFloat, toInt, toggle, trim, tryit as try, tryit, uid, unique, upperize, zip, zipToObject };
6 changes: 6 additions & 0 deletions cdn/radash.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var radash = (function (exports) {
return false;
}
};
const isBigInt = (value) => {
return typeof value === "bigint";
};
const isDate = (value) => {
return Object.prototype.toString.call(value) === "[object Date]";
};
Expand All @@ -49,6 +52,8 @@ var radash = (function (exports) {
return true;
if (isNumber(value))
return value === 0;
if (isBigInt(value))
return value === 0n;
if (isDate(value))
return isNaN(value.getTime());
if (isFunction(value))
Expand Down Expand Up @@ -969,6 +974,7 @@ var radash = (function (exports) {
exports.intersects = intersects;
exports.invert = invert;
exports.isArray = isArray;
exports.isBigInt = isBigInt;
exports.isDate = isDate;
exports.isEmpty = isEmpty;
exports.isEqual = isEqual;
Expand Down
2 changes: 1 addition & 1 deletion cdn/radash.min.js

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions docs/typed/is-bigint.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: isBigInt
description: 'Determine if a value is a bigint'
group: Typed
---

## Basic usage

Pass in a value and get a boolean telling you if the value is a bigint.

```ts
import { isBigInt } from 'radash'

isBigInt('hello') // => false
isBigInt(['hello']) // => false
isBigInt(12) // => false
isBigInt(0n) // => true
```
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": "12.1.0",
"version": "12.1.1",
"description": "Functional utility library - modern, simple, typed, powerful",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export {
} from './string'
export {
isArray,
isBigInt,
isDate,
isEmpty,
isEqual,
Expand Down
58 changes: 58 additions & 0 deletions src/tests/typed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,62 @@ describe('typed module', () => {
})
})

describe('isBigInt function', () => {
test('returns false for null', () => {
const result = _.isBigInt(null)
assert.isFalse(result)
})
test('returns false for undefined', () => {
const result = _.isBigInt(undefined)
assert.isFalse(result)
})
test('returns false for boolean', () => {
const result = _.isBigInt(false)
assert.isFalse(result)
})
test('returns false for class instance', () => {
class Data {}
const result = _.isBigInt(new Data())
assert.isFalse(result)
})
test('returns false for int', () => {
const result = _.isBigInt(22)
assert.isFalse(result)
})
test('returns false for float', () => {
const result = _.isBigInt(22.0567)
assert.isFalse(result)
})
test('returns false for NaN', () => {
const result = _.isBigInt(NaN)
assert.isFalse(result)
})
test('returns false for array', () => {
const result = _.isBigInt([1, 2, 3])
assert.isFalse(result)
})
test('returns false for object', () => {
const result = _.isBigInt({})
assert.isFalse(result)
})
test('returns false for string', () => {
const result = _.isBigInt('abc')
assert.isFalse(result)
})
test('returns false for string class', () => {
const result = _.isBigInt(String('abc'))
assert.isFalse(result)
})
test('returns true for bigint', () => {
const result = _.isBigInt(22n)
assert.isTrue(result)
})
test('returns true for bigint class', () => {
const result = _.isBigInt(BigInt(22))
assert.isTrue(result)
})
})

describe('isInt function', () => {
class Data {}
test('returns false for non-number values', () => {
Expand Down Expand Up @@ -304,6 +360,7 @@ describe('typed module', () => {
assert.isTrue(_.isEmpty(0))
assert.isTrue(_.isEmpty(true))
assert.isTrue(_.isEmpty([]))
assert.isTrue(_.isEmpty(0n))
assert.isTrue(_.isEmpty(false))
assert.isTrue(_.isEmpty({}))
assert.isTrue(_.isEmpty(''))
Expand All @@ -315,6 +372,7 @@ describe('typed module', () => {
assert.isFalse(_.isEmpty(new Date()))
assert.isFalse(_.isEmpty(new Date('2022-09-01T02:19:55.976Z')))
assert.isFalse(_.isEmpty(22))
assert.isFalse(_.isEmpty(1n))
assert.isFalse(_.isEmpty(new Person()))
assert.isFalse(_.isEmpty({ name: 'x' }))
assert.isFalse(_.isEmpty('abc'))
Expand Down
5 changes: 5 additions & 0 deletions src/typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const isNumber = (value: any): value is number => {
}
}

export const isBigInt = (value: any): value is bigint => {
return typeof value === 'bigint'
}

export const isDate = (value: any): value is Date => {
return Object.prototype.toString.call(value) === '[object Date]'
}
Expand All @@ -68,6 +72,7 @@ export const isEmpty = (value: any) => {
if (value === true || value === false) return true
if (value === null || value === undefined) return true
if (isNumber(value)) return value === 0
if (isBigInt(value)) return value === 0n
if (isDate(value)) return isNaN(value.getTime())
if (isFunction(value)) return false
if (isSymbol(value)) return false
Expand Down
Loading