@jblib/is 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,16 @@
1
1
  //#region src/is-number.d.ts
2
2
  /**
3
- * Checks if a value is a number.
3
+ * isNumber checks if the provided value is a number.
4
4
  *
5
- * @param v value to check
6
- * @returns boolean indicating if the value is a number
5
+ * @param v value to check.
6
+ * @returns {v is number} returns true if v is a number or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isNumber(123) // true
11
+ * isNumber('hello') // false
12
+ * isNumber({}) // false
13
+ * ```
7
14
  */
8
15
  declare const isNumber: (v: unknown) => v is number;
9
16
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"is-number.d.ts","names":[],"sources":["../src/is-number.ts"],"mappings":";;;;;;;cAMM,QAAA,GAAY,CAAA,cAAa,CAAA"}
1
+ {"version":3,"file":"is-number.d.ts","names":[],"sources":["../src/is-number.ts"],"mappings":";;;;;;;;;;;;;;cAaM,QAAA,GAAY,CAAA,cAAa,CAAA"}
package/dist/is-number.js CHANGED
@@ -1,9 +1,16 @@
1
1
  //#region src/is-number.ts
2
2
  /**
3
- * Checks if a value is a number.
3
+ * isNumber checks if the provided value is a number.
4
4
  *
5
- * @param v value to check
6
- * @returns boolean indicating if the value is a number
5
+ * @param v value to check.
6
+ * @returns {v is number} returns true if v is a number or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isNumber(123) // true
11
+ * isNumber('hello') // false
12
+ * isNumber({}) // false
13
+ * ```
7
14
  */
8
15
  const isNumber = (v) => typeof v === "number";
9
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"is-number.js","names":[],"sources":["../src/is-number.ts"],"sourcesContent":["/**\n * Checks if a value is a number.\n *\n * @param v value to check\n * @returns boolean indicating if the value is a number\n */\nconst isNumber = (v: unknown): v is number => typeof v === 'number'\n\nexport { isNumber }\n"],"mappings":";;;;;;;AAMA,MAAM,YAAY,MAA4B,OAAO,MAAM"}
1
+ {"version":3,"file":"is-number.js","names":[],"sources":["../src/is-number.ts"],"sourcesContent":["/**\n * isNumber checks if the provided value is a number.\n *\n * @param v value to check.\n * @returns {v is number} returns true if v is a number or otherwise false.\n *\n * @example\n * ```ts\n * isNumber(123) // true\n * isNumber('hello') // false\n * isNumber({}) // false\n * ```\n */\nconst isNumber = (v: unknown): v is number => typeof v === 'number'\n\nexport { isNumber }\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,YAAY,MAA4B,OAAO,MAAM"}
@@ -1,9 +1,16 @@
1
1
  //#region src/is-string.d.ts
2
2
  /**
3
- * Checks if a value is a string.
3
+ * isString checks if the provided value is a string.
4
4
  *
5
- * @param v value to check
6
- * @returns boolean indicating if the value is a string
5
+ * @param v value to check.
6
+ * @returns {v is string} returns true if v is a string or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isString('hello') // true
11
+ * isString(123) // false
12
+ * isString({}) // false
13
+ * ```
7
14
  */
8
15
  declare const isString: (v: unknown) => v is string;
9
16
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"is-string.d.ts","names":[],"sources":["../src/is-string.ts"],"mappings":";;;;;;;cAMM,QAAA,GAAY,CAAA,cAAa,CAAA"}
1
+ {"version":3,"file":"is-string.d.ts","names":[],"sources":["../src/is-string.ts"],"mappings":";;;;;;;;;;;;;;cAaM,QAAA,GAAY,CAAA,cAAa,CAAA"}
package/dist/is-string.js CHANGED
@@ -1,9 +1,16 @@
1
1
  //#region src/is-string.ts
2
2
  /**
3
- * Checks if a value is a string.
3
+ * isString checks if the provided value is a string.
4
4
  *
5
- * @param v value to check
6
- * @returns boolean indicating if the value is a string
5
+ * @param v value to check.
6
+ * @returns {v is string} returns true if v is a string or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isString('hello') // true
11
+ * isString(123) // false
12
+ * isString({}) // false
13
+ * ```
7
14
  */
8
15
  const isString = (v) => typeof v === "string";
9
16
 
@@ -1 +1 @@
1
- {"version":3,"file":"is-string.js","names":[],"sources":["../src/is-string.ts"],"sourcesContent":["/**\n * Checks if a value is a string.\n *\n * @param v value to check\n * @returns boolean indicating if the value is a string\n */\nconst isString = (v: unknown): v is string => typeof v === 'string'\n\nexport { isString }\n"],"mappings":";;;;;;;AAMA,MAAM,YAAY,MAA4B,OAAO,MAAM"}
1
+ {"version":3,"file":"is-string.js","names":[],"sources":["../src/is-string.ts"],"sourcesContent":["/**\n * isString checks if the provided value is a string.\n *\n * @param v value to check.\n * @returns {v is string} returns true if v is a string or otherwise false.\n *\n * @example\n * ```ts\n * isString('hello') // true\n * isString(123) // false\n * isString({}) // false\n * ```\n */\nconst isString = (v: unknown): v is string => typeof v === 'string'\n\nexport { isString }\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,YAAY,MAA4B,OAAO,MAAM"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@jblib/is",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "is, condition checks",
5
5
  "type": "module",
6
6
  "devDependencies": {
7
- "vitest": "^4.1.5",
8
- "typescript": "^6.0.3",
9
7
  "prettier": "^3.8.3",
10
8
  "tsdown": "^0.21.10",
11
- "@jblib/eslint": "0.0.1"
9
+ "typescript": "^6.0.3",
10
+ "vitest": "^4.1.5",
11
+ "@jblib/eslint": "0.0.4"
12
12
  },
13
13
  "keywords": [
14
14
  "is"
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isArray } from './is-array.js'
4
+
5
+ describe('is array', () => {
6
+ it('should return true for arrays', () => {
7
+ expect(isArray([])).toBe(true)
8
+ expect(isArray([1, 2, 3])).toBe(true)
9
+ })
10
+
11
+ it('should return false for non-arrays', () => {
12
+ expect(isArray('hello')).toBe(false)
13
+ expect(isArray({})).toBe(false)
14
+ expect(isArray(123)).toBe(false)
15
+ expect(isArray(null)).toBe(false)
16
+ expect(isArray(undefined)).toBe(false)
17
+ })
18
+ })
@@ -0,0 +1,19 @@
1
+ /**
2
+ * isArray checks if the provided value is an array.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is unknown[]} returns true if the value is an array or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isArray([]) // true
10
+ * isArray([1, 2, 3]) // true
11
+ * isArray('hello') // false
12
+ * isArray({}) // false
13
+ * isArray(123) // false
14
+ * isArray(undefined) // false
15
+ * ```
16
+ */
17
+ const isArray = (v: unknown): v is unknown[] => Array.isArray(v)
18
+
19
+ export { isArray }
@@ -0,0 +1,35 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isFunction } from './is-function.js'
4
+
5
+ describe('is function', () => {
6
+ it('should return true for functions', () => {
7
+ expect(
8
+ isFunction(() => {
9
+ void 0
10
+ }),
11
+ ).toBe(true)
12
+
13
+ expect(
14
+ isFunction(function () {
15
+ void 0
16
+ }),
17
+ ).toBe(true)
18
+
19
+ expect(
20
+ // eslint-disable-next-line @typescript-eslint/require-await
21
+ isFunction(async function () {
22
+ void 0
23
+ }),
24
+ ).toBe(true)
25
+ })
26
+
27
+ it('should return false for non-functions', () => {
28
+ expect(isFunction('hello')).toBe(false)
29
+ expect(isFunction({})).toBe(false)
30
+ expect(isFunction(123)).toBe(false)
31
+ expect(isFunction(null)).toBe(false)
32
+ expect(isFunction(undefined)).toBe(false)
33
+ expect(isFunction([])).toBe(false)
34
+ })
35
+ })
@@ -0,0 +1,18 @@
1
+ /**
2
+ * isFunction checks if the provided value is a function.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is (...args: unknown[]) => unknown} returns true if v is a function or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isFunction(() => {}) // true
10
+ * isFunction(function() {}) // true
11
+ * isFunction(async function() {}) // true
12
+ * isFunction('hello') // false
13
+ * isFunction({}) // false
14
+ * ```
15
+ */
16
+ const isFunction = (v: unknown): v is (...args: unknown[]) => unknown => typeof v === 'function'
17
+
18
+ export { isFunction }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isNonEmptyArray } from './is-non-empty-array.js'
4
+
5
+ describe('is non empty array', () => {
6
+ it('should return true for non-empty arrays', () => {
7
+ expect(isNonEmptyArray([1, 2, 3])).toBe(true)
8
+ })
9
+
10
+ it('should return false for empty arrays', () => {
11
+ expect(isNonEmptyArray([])).toBe(false)
12
+ })
13
+
14
+ it('should return false for non-arrays', () => {
15
+ expect(isNonEmptyArray('hello')).toBe(false)
16
+ expect(isNonEmptyArray({})).toBe(false)
17
+ expect(isNonEmptyArray(123)).toBe(false)
18
+ expect(isNonEmptyArray(null)).toBe(false)
19
+ expect(isNonEmptyArray(undefined)).toBe(false)
20
+ })
21
+ })
@@ -0,0 +1,17 @@
1
+ /**
2
+ * isNonEmptyArray checks if the provided value is an array and contains at least one element.
3
+ *
4
+ * @param v value to check.
5
+ * @returns {v is unknown[]} returns true if v is a non-empty array or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isNonEmptyArray([1, 2, 3]) // true
10
+ * isNonEmptyArray([]) // false
11
+ * isNonEmptyArray('hello') // false
12
+ * isNonEmptyArray({}) // false
13
+ * ```
14
+ */
15
+ const isNonEmptyArray = (v: unknown): v is unknown[] => Array.isArray(v) && v.length > 0
16
+
17
+ export { isNonEmptyArray }
package/src/is-number.ts CHANGED
@@ -1,8 +1,15 @@
1
1
  /**
2
- * Checks if a value is a number.
2
+ * isNumber checks if the provided value is a number.
3
3
  *
4
- * @param v value to check
5
- * @returns boolean indicating if the value is a number
4
+ * @param v value to check.
5
+ * @returns {v is number} returns true if v is a number or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isNumber(123) // true
10
+ * isNumber('hello') // false
11
+ * isNumber({}) // false
12
+ * ```
6
13
  */
7
14
  const isNumber = (v: unknown): v is number => typeof v === 'number'
8
15
 
package/src/is-string.ts CHANGED
@@ -1,8 +1,15 @@
1
1
  /**
2
- * Checks if a value is a string.
2
+ * isString checks if the provided value is a string.
3
3
  *
4
- * @param v value to check
5
- * @returns boolean indicating if the value is a string
4
+ * @param v value to check.
5
+ * @returns {v is string} returns true if v is a string or otherwise false.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * isString('hello') // true
10
+ * isString(123) // false
11
+ * isString({}) // false
12
+ * ```
6
13
  */
7
14
  const isString = (v: unknown): v is string => typeof v === 'string'
8
15