Skip to content

Commit ebed19a

Browse files
committed
small tweaks
1 parent cda4645 commit ebed19a

File tree

4 files changed

+32
-61
lines changed

4 files changed

+32
-61
lines changed

docs/typed/isBigInt.mdx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
title: isBigInt
3-
description: 'Determine if a value is BigInt'
3+
description: 'Determine if a value is a BigInt'
44
---
55

66
### Usage
77

8-
Pass in a value and get a boolean telling you if the value is a bigint.
8+
Pass in a value and get a boolean telling you if the value is a bigint, using the `typeof` operator.
99

1010
```ts
1111
import * as _ from 'radashi'
1212

13-
_.isBigInt('hello') // => false
14-
_.isBigInt(['hello']) // => false
15-
_.isBigInt(12) // => false
1613
_.isBigInt(0n) // => true
14+
_.isBigInt(BigInt(0)) // => true
15+
_.isBigInt(12) // => false
16+
_.isBigInt('0n') // => false
1717
```

src/mod.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export * from './string/title.ts'
112112
export * from './string/trim.ts'
113113

114114
export * from './typed/isArray.ts'
115+
export * from './typed/isBigInt.ts'
115116
export * from './typed/isBoolean.ts'
116117
export * from './typed/isClass.ts'
117118
export * from './typed/isDate.ts'
@@ -141,6 +142,5 @@ export * from './typed/isTagged.ts'
141142
export * from './typed/isUndefined.ts'
142143
export * from './typed/isWeakMap.ts'
143144
export * from './typed/isWeakSet.ts'
144-
export * from './typed/isBigInt.ts'
145145

146146
export * from './types.ts'

src/typed/isBigInt.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
2-
* Return true if the give value is bigint.
2+
* Return true if the give value is a BigInt.
33
*
44
* @see https://radashi.js.org/reference/typed/isBigInt
55
* @example
66
* ```ts
7-
* isBigInt('hello') // => false
8-
* isBigInt(['hello']) // => false
9-
* isBigInt(12) // => false
10-
* isBigInt(0n) // => true
7+
* _.isBigInt(0n) // => true
8+
* _.isBigInt(BigInt(0)) // => true
9+
* _.isBigInt(12) // => false
10+
* _.isBigInt('0n') // => false
1111
* ```
1212
*/
1313
export function isBigInt(value: unknown): value is bigint {

tests/typed/isBigInt.test.ts

+21-50
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,28 @@
11
import * as _ from 'radashi'
22

33
describe('isBigInt function', () => {
4-
test('returns false for null', () => {
5-
const result = _.isBigInt(null)
6-
expect(result).toBeFalsy()
7-
})
8-
test('returns false for undefined', () => {
9-
const result = _.isBigInt(undefined)
10-
expect(result).toBeFalsy()
11-
})
12-
test('returns false for boolean', () => {
13-
const result = _.isBigInt(false)
14-
expect(result).toBeFalsy()
15-
})
16-
test('returns false for class instance', () => {
4+
test('returns false for non-bigint values', () => {
5+
// Primitive values
6+
expect(_.isBigInt(null)).toBeFalsy()
7+
expect(_.isBigInt(undefined)).toBeFalsy()
8+
expect(_.isBigInt(false)).toBeFalsy()
9+
expect(_.isBigInt(22)).toBeFalsy()
10+
expect(_.isBigInt(22.0567)).toBeFalsy()
11+
expect(_.isBigInt(Number.NaN)).toBeFalsy()
12+
expect(_.isBigInt('0n')).toBeFalsy()
13+
14+
// Objects and collections
15+
expect(_.isBigInt([1, 2, 3])).toBeFalsy()
16+
expect(_.isBigInt({})).toBeFalsy()
17+
expect(_.isBigInt(String('abc'))).toBeFalsy()
18+
19+
// Class instance
1720
class Data {}
18-
const result = _.isBigInt(new Data())
19-
expect(result).toBeFalsy()
20-
})
21-
test('returns false for int', () => {
22-
const result = _.isBigInt(22)
23-
expect(result).toBeFalsy()
24-
})
25-
test('returns false for float', () => {
26-
const result = _.isBigInt(22.0567)
27-
assert.isFalse(result)
21+
expect(_.isBigInt(new Data())).toBeFalsy()
2822
})
29-
test('returns false for NaN', () => {
30-
const result = _.isBigInt(Number.NaN)
31-
expect(result).toBeFalsy()
32-
})
33-
test('returns false for array', () => {
34-
const result = _.isBigInt([1, 2, 3])
35-
expect(result).toBeFalsy()
36-
})
37-
test('returns false for object', () => {
38-
const result = _.isBigInt({})
39-
expect(result).toBeFalsy()
40-
})
41-
test('returns false for string', () => {
42-
const result = _.isBigInt('abc')
43-
expect(result).toBeFalsy()
44-
})
45-
test('returns false for string class', () => {
46-
const result = _.isBigInt(String('abc'))
47-
expect(result).toBeFalsy()
48-
})
49-
test('returns true for bigint', () => {
50-
const result = _.isBigInt(22n)
51-
expect(result).toBeTruthy()
52-
})
53-
test('returns true for bigint class', () => {
54-
const result = _.isBigInt(BigInt(22))
55-
expect(result).toBeTruthy()
23+
24+
test('returns true for bigint values', () => {
25+
expect(_.isBigInt(22n)).toBeTruthy()
26+
expect(_.isBigInt(BigInt(22))).toBeTruthy()
5627
})
5728
})

0 commit comments

Comments
 (0)