@jblib/is 0.0.2 → 0.0.4

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.
Files changed (86) hide show
  1. package/dist/index.d.ts +13 -1
  2. package/dist/index.js +13 -1
  3. package/dist/is-array.d.ts +21 -0
  4. package/dist/is-array.d.ts.map +1 -0
  5. package/dist/is-array.js +22 -0
  6. package/dist/is-array.js.map +1 -0
  7. package/dist/is-boolean.d.ts +21 -0
  8. package/dist/is-boolean.d.ts.map +1 -0
  9. package/dist/is-boolean.js +22 -0
  10. package/dist/is-boolean.js.map +1 -0
  11. package/dist/is-date.d.ts +21 -0
  12. package/dist/is-date.d.ts.map +1 -0
  13. package/dist/is-date.js +22 -0
  14. package/dist/is-date.js.map +1 -0
  15. package/dist/is-defined.d.ts +19 -0
  16. package/dist/is-defined.d.ts.map +1 -0
  17. package/dist/is-defined.js +20 -0
  18. package/dist/is-defined.js.map +1 -0
  19. package/dist/is-empty-object.d.ts +23 -0
  20. package/dist/is-empty-object.d.ts.map +1 -0
  21. package/dist/is-empty-object.js +26 -0
  22. package/dist/is-empty-object.js.map +1 -0
  23. package/dist/is-error.d.ts +20 -0
  24. package/dist/is-error.d.ts.map +1 -0
  25. package/dist/is-error.js +21 -0
  26. package/dist/is-error.js.map +1 -0
  27. package/dist/is-function.d.ts +20 -0
  28. package/dist/is-function.d.ts.map +1 -0
  29. package/dist/is-function.js +21 -0
  30. package/dist/is-function.js.map +1 -0
  31. package/dist/is-nil.d.ts +21 -0
  32. package/dist/is-nil.d.ts.map +1 -0
  33. package/dist/is-nil.js +22 -0
  34. package/dist/is-nil.js.map +1 -0
  35. package/dist/is-non-empty-array.d.ts +19 -0
  36. package/dist/is-non-empty-array.d.ts.map +1 -0
  37. package/dist/is-non-empty-array.js +20 -0
  38. package/dist/is-non-empty-array.js.map +1 -0
  39. package/dist/is-number.d.ts +10 -3
  40. package/dist/is-number.d.ts.map +1 -1
  41. package/dist/is-number.js +10 -3
  42. package/dist/is-number.js.map +1 -1
  43. package/dist/is-object.d.ts +20 -0
  44. package/dist/is-object.d.ts.map +1 -0
  45. package/dist/is-object.js +21 -0
  46. package/dist/is-object.js.map +1 -0
  47. package/dist/is-plain-object.d.ts +22 -0
  48. package/dist/is-plain-object.d.ts.map +1 -0
  49. package/dist/is-plain-object.js +27 -0
  50. package/dist/is-plain-object.js.map +1 -0
  51. package/dist/is-primitive.d.ts +27 -0
  52. package/dist/is-primitive.d.ts.map +1 -0
  53. package/dist/is-primitive.js +24 -0
  54. package/dist/is-primitive.js.map +1 -0
  55. package/dist/is-string.d.ts +10 -3
  56. package/dist/is-string.d.ts.map +1 -1
  57. package/dist/is-string.js +10 -3
  58. package/dist/is-string.js.map +1 -1
  59. package/package.json +4 -4
  60. package/src/index.ts +14 -4
  61. package/src/is-array.spec.ts +18 -0
  62. package/src/is-array.ts +19 -0
  63. package/src/is-boolean.spec.ts +18 -0
  64. package/src/is-boolean.ts +19 -0
  65. package/src/is-date.spec.ts +21 -0
  66. package/src/is-date.ts +19 -0
  67. package/src/is-defined.spec.ts +15 -0
  68. package/src/is-defined.ts +17 -0
  69. package/src/is-empty-object.spec.ts +25 -0
  70. package/src/is-empty-object.ts +24 -0
  71. package/src/is-error.spec.ts +19 -0
  72. package/src/is-error.ts +18 -0
  73. package/src/is-function.spec.ts +35 -0
  74. package/src/is-function.ts +18 -0
  75. package/src/is-nil.spec.ts +17 -0
  76. package/src/is-nil.ts +19 -0
  77. package/src/is-non-empty-array.spec.ts +21 -0
  78. package/src/is-non-empty-array.ts +17 -0
  79. package/src/is-number.ts +10 -3
  80. package/src/is-object.spec.ts +17 -0
  81. package/src/is-object.ts +18 -0
  82. package/src/is-plain-object.spec.ts +18 -0
  83. package/src/is-plain-object.ts +28 -0
  84. package/src/is-primitive.spec.ts +23 -0
  85. package/src/is-primitive.ts +26 -0
  86. package/src/is-string.ts +10 -3
@@ -0,0 +1,28 @@
1
+ /**
2
+ * isPlainObject checks if a value is a plain object, that is,
3
+ * an object created by the Object constructor or with a null prototype.
4
+ *
5
+ * @param v value to check.
6
+ * @returns {v is Record<PropertyKey, unknown>} returns true if the value is a plain object or otherwise false.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * isPlainObject({}) // true
11
+ * isPlainObject(Object.create(null)) // true
12
+ * isPlainObject([]) // false
13
+ * isPlainObject(null) // false
14
+ * isPlainObject('hello') // false
15
+ * isPlainObject(42) // false
16
+ * ```
17
+ */
18
+ const isPlainObject = (v: unknown): v is Record<PropertyKey, unknown> => {
19
+ if (typeof v !== 'object' || v === null) {
20
+ return false
21
+ }
22
+
23
+ const proto = Object.getPrototypeOf(v) as unknown
24
+
25
+ return proto === Object.prototype || proto === null
26
+ }
27
+
28
+ export { isPlainObject }
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { isPrimitive } from './is-primitive.js'
4
+
5
+ describe('is primitive', () => {
6
+ it('should return true for primitives', () => {
7
+ expect(isPrimitive(42)).toBe(true)
8
+ expect(isPrimitive('hello')).toBe(true)
9
+ expect(isPrimitive(true)).toBe(true)
10
+ expect(isPrimitive(null)).toBe(true)
11
+ expect(isPrimitive(undefined)).toBe(true)
12
+ })
13
+
14
+ it('should return false for non-primitives', () => {
15
+ expect(isPrimitive({})).toBe(false)
16
+ expect(isPrimitive([])).toBe(false)
17
+ expect(
18
+ isPrimitive(() => {
19
+ void 0
20
+ }),
21
+ ).toBe(false)
22
+ })
23
+ })
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Primitive type represents the primitive values.
3
+ */
4
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined
5
+
6
+ /**
7
+ * isPrimitive checks if a value is a primitive.
8
+ *
9
+ * @param v value to check.
10
+ * @returns {v is Primitive} returns true if the value is a primitive or otherwise false.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * isPrimitive(42) // true
15
+ * isPrimitive('hello') // true
16
+ * isPrimitive(true) // true
17
+ * isPrimitive(null) // true
18
+ * isPrimitive(undefined) // true
19
+ * isPrimitive({}) // false
20
+ * isPrimitive([]) // false
21
+ * isPrimitive(() => {}) // false
22
+ * ```
23
+ */
24
+ const isPrimitive = (v: unknown): v is Primitive => v === null || (typeof v !== 'object' && typeof v !== 'function')
25
+
26
+ export { isPrimitive }
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