@splendidlabz/utils 1.5.0-beta.6 → 1.5.1

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 (117) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/dom/accessibility.d.ts +28 -0
  3. package/dist/dom/actions/index.d.ts +3 -0
  4. package/dist/dom/actions/masonry.d.ts +3 -0
  5. package/dist/dom/actions/prefer-horizontal-scroll.d.ts +3 -0
  6. package/dist/dom/actions/sticky.d.ts +3 -0
  7. package/dist/dom/bounding-box.d.ts +39 -0
  8. package/dist/dom/clipboard.d.ts +5 -0
  9. package/dist/dom/cookie.d.ts +11 -0
  10. package/dist/dom/css-vars.d.ts +4 -0
  11. package/dist/dom/events.d.ts +18 -0
  12. package/dist/dom/focusable.d.ts +76 -0
  13. package/dist/dom/font-size.d.ts +5 -0
  14. package/dist/dom/get-element.d.ts +100 -0
  15. package/dist/dom/hash.d.ts +1 -0
  16. package/dist/dom/index.d.ts +22 -0
  17. package/dist/dom/keyboard.d.ts +30 -0
  18. package/dist/dom/local-store.d.ts +29 -0
  19. package/dist/dom/media.d.ts +3 -0
  20. package/dist/dom/observers/index.d.ts +3 -0
  21. package/dist/dom/observers/intersection-observer.d.ts +8 -0
  22. package/dist/dom/observers/mutation-observer.d.ts +7 -0
  23. package/dist/dom/observers/observer.d.ts +1 -0
  24. package/dist/dom/observers/resize-observer.d.ts +38 -0
  25. package/dist/dom/pkce.d.ts +6 -0
  26. package/dist/dom/query-params.d.ts +4 -0
  27. package/dist/dom/random-string.d.ts +7 -0
  28. package/dist/dom/sanitize.d.ts +8 -0
  29. package/dist/dom/session-store.d.ts +5 -0
  30. package/dist/dom/trap-focus.d.ts +28 -0
  31. package/dist/dom/ui/aria-current.d.ts +5 -0
  32. package/dist/dom/ui/inconsistent-button-fix.d.ts +12 -0
  33. package/dist/dom/ui/index.d.ts +4 -0
  34. package/dist/dom/ui/scroll-container.d.ts +1 -0
  35. package/dist/dom/ui/traverse-and-scramble.d.ts +19 -0
  36. package/dist/lib/arrays/index.d.ts +5 -0
  37. package/dist/lib/arrays/item-position.d.ts +14 -0
  38. package/dist/lib/arrays/join.d.ts +13 -0
  39. package/dist/lib/arrays/shuffle.d.ts +1 -0
  40. package/dist/lib/arrays/sort.d.ts +30 -0
  41. package/dist/lib/arrays/unique.d.ts +1 -0
  42. package/dist/lib/auth/index.d.ts +1 -0
  43. package/dist/lib/auth/route-manager.d.ts +25 -0
  44. package/dist/lib/checks.d.ts +29 -0
  45. package/dist/lib/date/days.d.ts +5 -0
  46. package/dist/lib/date/index.d.ts +3 -0
  47. package/dist/lib/date/months.d.ts +9 -0
  48. package/dist/lib/date/time.d.ts +8 -0
  49. package/dist/lib/form/form-data.d.ts +7 -0
  50. package/dist/lib/form/index.d.ts +2 -0
  51. package/dist/lib/form/sanitize.d.ts +58 -0
  52. package/dist/lib/functions/debounce.d.ts +1 -0
  53. package/dist/lib/functions/env.d.ts +1 -0
  54. package/dist/lib/functions/functional.d.ts +4 -0
  55. package/dist/lib/functions/index.d.ts +5 -0
  56. package/dist/lib/functions/throttle.d.ts +1 -0
  57. package/dist/lib/functions/timeout.d.ts +3 -0
  58. package/dist/lib/index.d.ts +13 -0
  59. package/dist/lib/numbers/index.d.ts +2 -0
  60. package/dist/lib/numbers/math.d.ts +2 -0
  61. package/dist/lib/objects/camelcase-keys.d.ts +1 -0
  62. package/dist/lib/objects/empty.d.ts +2 -0
  63. package/dist/lib/objects/equal.d.ts +2 -0
  64. package/dist/lib/objects/extend.d.ts +4 -0
  65. package/dist/lib/objects/flatten.d.ts +4 -0
  66. package/dist/lib/objects/index.d.ts +13 -0
  67. package/dist/lib/objects/json.d.ts +1 -0
  68. package/dist/lib/objects/loop.d.ts +2 -0
  69. package/dist/lib/objects/mix/mix.d.ts +1 -0
  70. package/dist/lib/objects/nested-property.d.ts +22 -0
  71. package/dist/lib/objects/normalize-object.d.ts +1 -0
  72. package/dist/lib/objects/omit-empty.d.ts +1 -0
  73. package/dist/lib/objects/size.d.ts +1 -0
  74. package/dist/lib/objects/split.d.ts +10 -0
  75. package/dist/lib/promises/index.d.ts +1 -0
  76. package/dist/lib/promises/reject.d.ts +3 -0
  77. package/dist/lib/sse.d.ts +16 -0
  78. package/dist/lib/strings/convert-case/convert-case.d.ts +8 -0
  79. package/dist/lib/strings/index.d.ts +4 -0
  80. package/dist/lib/strings/markdown.d.ts +23 -0
  81. package/dist/lib/strings/pluralize.d.ts +1 -0
  82. package/dist/lib/strings/query-string.d.ts +8 -0
  83. package/dist/lib/style/index.d.ts +1 -0
  84. package/dist/lib/symbols/index.d.ts +1 -0
  85. package/dist/lib/symbols/symbols.d.ts +2 -0
  86. package/dist/node/common.d.ts +1 -0
  87. package/dist/node/dirname.d.ts +7 -0
  88. package/dist/node/file-cache.d.ts +54 -0
  89. package/dist/node/file.d.ts +2 -0
  90. package/dist/node/hash.d.ts +1 -0
  91. package/dist/node/index.d.ts +7 -0
  92. package/dist/node/pkce.d.ts +6 -0
  93. package/dist/node/random-string.d.ts +2 -0
  94. package/dist/node/sanitize.d.ts +8 -0
  95. package/dom/accessibility.js +22 -0
  96. package/dom/actions/prefer-horizontal-scroll.js +4 -4
  97. package/dom/bounding-box.js +35 -7
  98. package/dom/focusable.js +119 -10
  99. package/dom/get-element.js +97 -5
  100. package/dom/keyboard.js +13 -8
  101. package/dom/observers/intersection-observer.js +1 -1
  102. package/dom/observers/mutation-observer.js +1 -1
  103. package/dom/observers/resize-observer.js +2 -2
  104. package/dom/sanitize.js +1 -1
  105. package/dom/trap-focus.js +18 -3
  106. package/dom/ui/inconsistent-button-fix.js +14 -2
  107. package/dom/ui/traverse-and-scramble.js +29 -8
  108. package/lib/arrays/join.js +7 -4
  109. package/lib/arrays/sort.js +37 -7
  110. package/lib/checks.js +26 -0
  111. package/lib/form/sanitize.js +34 -11
  112. package/lib/sse.js +4 -7
  113. package/lib/strings/markdown.js +12 -4
  114. package/node/file-cache.js +46 -7
  115. package/node/sanitize.js +1 -1
  116. package/package.json +32 -10
  117. package/tsconfig.json +23 -0
@@ -1,10 +1,30 @@
1
1
  import { getNestedValue } from '../objects/nested-property.js'
2
+
2
3
  /**
3
- * Sorts an array of objects, numbers, or strings without mutating the original array
4
- * @param {Array} array - Array to sort
5
- * @param {Object} options - Sort options
6
- * @param {string|string[]|null} options.props - Property or array of properties to sort by. If null, sorts simple arrays
7
- * @param {boolean} options.reverse - Whether to sort in reverse order
4
+ * Sorts an array of objects, numbers, or strings without mutating the original array.
5
+ * Supports nested properties, multiple sort keys, and various data types.
6
+ *
7
+ * @template T
8
+ * @param {T[]} array - Array to sort
9
+ * @param {Object} [options] - Sort options
10
+ * @param {string|string[]|null} [options.props=null] - Property or array of properties to sort by. If null, sorts simple arrays
11
+ * @param {boolean} [options.reverse=false] - Whether to sort in reverse order
12
+ * @returns {T[]} New sorted array
13
+ * @example
14
+ * // Sort simple array
15
+ * sort([3, 1, 2]) // [1, 2, 3]
16
+ *
17
+ * // Sort objects by single property
18
+ * sort(users, { props: 'name' })
19
+ *
20
+ * // Sort objects by multiple properties
21
+ * sort(users, { props: ['age', 'name'] })
22
+ *
23
+ * // Sort in reverse order
24
+ * sort(users, { props: 'age', reverse: true })
25
+ *
26
+ * // Sort by nested property
27
+ * sort(users, { props: 'address.city' })
8
28
  */
9
29
  export function sort(array, { props = null, reverse = false } = {}) {
10
30
  const clone = array.slice()
@@ -40,7 +60,15 @@ export function sort(array, { props = null, reverse = false } = {}) {
40
60
  })
41
61
  }
42
62
 
43
- // Compare values for sorting
63
+ /**
64
+ * Compares two values for sorting, handling different data types.
65
+ * Supports numbers, strings, dates, and falls back to string comparison.
66
+ *
67
+ * @param {*} a - First value to compare
68
+ * @param {*} b - Second value to compare
69
+ * @returns {number} -1 if a < b, 0 if a === b, 1 if a > b
70
+ * @private
71
+ */
44
72
  function compareValues(a, b) {
45
73
  // Compare numbers
46
74
  if (typeof a === 'number' && typeof b === 'number') return a - b
@@ -51,7 +79,9 @@ function compareValues(a, b) {
51
79
  // Compare dates
52
80
  const aDate = new Date(a)
53
81
  const bDate = new Date(b)
54
- if (!isNaN(aDate) && !isNaN(bDate)) return aDate.getTime() - bDate.getTime()
82
+ const aTime = aDate.getTime()
83
+ const bTime = bDate.getTime()
84
+ if (!isNaN(aTime) && !isNaN(bTime)) return aTime - bTime
55
85
 
56
86
  // Convert into strings and compare
57
87
  return String(a).localeCompare(String(b))
package/lib/checks.js CHANGED
@@ -1,11 +1,37 @@
1
+ /**
2
+ * Checks if a value is a plain object (not an array or null)
3
+ * @param {unknown} x - The value to check
4
+ * @returns {boolean} True if the value is a plain object
5
+ * @example
6
+ * isObject({}) // true
7
+ * isObject([]) // false
8
+ * isObject(null) // false
9
+ */
1
10
  export function isObject(x) {
2
11
  return typeof x === 'object' && !Array.isArray(x) && x !== null
3
12
  }
4
13
 
14
+ /**
15
+ * Checks if a value is an array
16
+ * @param {unknown} x - The value to check
17
+ * @returns {boolean} True if the value is an array
18
+ * @example
19
+ * isArray([]) // true
20
+ * isArray({}) // false
21
+ */
5
22
  export function isArray(x) {
6
23
  return Array.isArray(x)
7
24
  }
8
25
 
26
+ /**
27
+ * Checks if a value is not a plain object
28
+ * @param {unknown} x - The value to check
29
+ * @returns {boolean} True if the value is not a plain object
30
+ * @example
31
+ * notObject([]) // true
32
+ * notObject(null) // true
33
+ * notObject({}) // false
34
+ */
9
35
  export function notObject(x) {
10
36
  return !isObject(x)
11
37
  }
@@ -1,9 +1,28 @@
1
1
  /**
2
- * Core sanitization function that handles different value types
2
+ * @typedef {Object} SanitizeOptions
3
+ * @property {Function} [sanitizer] - Function to sanitize strings
4
+ * @property {*} [additional] - Any additional properties are passed through to the sanitizer function
5
+ */
6
+
7
+ /**
8
+ * Core sanitization function that handles different value types.
9
+ * Throws if no sanitizer function is provided.
10
+ * Any additional properties in options are passed through to the sanitizer function.
11
+ *
3
12
  * @param {*} value - The value to sanitize
4
- * @param {Object} [options={}] - Sanitization options
5
- * @param {Function} options.sanitizer - Function to sanitize strings. Must be provided
13
+ * @param {SanitizeOptions} [options={}] - Sanitization options
14
+ * @throws {Error} If sanitizer function is not provided
6
15
  * @returns {*} Sanitized value
16
+ * @example
17
+ * // Basic sanitization
18
+ * sanitize('hello', { sanitizer: str => str.trim() })
19
+ *
20
+ * // With additional options passed to sanitizer
21
+ * sanitize('hello', {
22
+ * sanitizer: (str, length, char) => str.padEnd(length, char),
23
+ * length: 10,
24
+ * char: '-'
25
+ * })
7
26
  */
8
27
  export function sanitize(value, options = {}) {
9
28
  const { sanitizer, ...rest } = options
@@ -22,12 +41,14 @@ export function sanitize(value, options = {}) {
22
41
  return value
23
42
  }
24
43
  /**
25
- * Sanitizes an array by recursively sanitizing each element
44
+ * Sanitizes an array by recursively sanitizing each element.
45
+ * Throws if no sanitizer function is provided.
46
+ * Any additional properties in options are passed through to the sanitizer function.
47
+ *
26
48
  * @param {Array} arr - Array to sanitize
27
- * @param {Object} options - Sanitization options
28
- * @param {Function} options.sanitizer - Function to sanitize strings. Must be provided
29
- * @returns {Array} New array with sanitized values
49
+ * @param {SanitizeOptions} options - Sanitization options
30
50
  * @throws {Error} If sanitizer function is not provided
51
+ * @returns {Array} New array with sanitized values
31
52
  */
32
53
  function sanitizeArray(arr, { sanitizer, ...rest }) {
33
54
  if (!sanitizer) throw new Error('sanitizer function is required')
@@ -35,12 +56,14 @@ function sanitizeArray(arr, { sanitizer, ...rest }) {
35
56
  }
36
57
 
37
58
  /**
38
- * Sanitizes all string values in an object recursively
59
+ * Sanitizes all string values in an object recursively.
60
+ * Throws if no sanitizer function is not provided.
61
+ * Any additional properties in options are passed through to the sanitizer function.
62
+ *
39
63
  * @param {Object} obj - Object to sanitize
40
- * @param {Object} [options={}] - Sanitization options
41
- * @param {Function} options.sanitizer - Function to sanitize strings. Must be provided
42
- * @returns {Object} New object with sanitized values
64
+ * @param {SanitizeOptions} [options={}] - Sanitization options
43
65
  * @throws {Error} If sanitizer function is not provided
66
+ * @returns {Object} New object with sanitized values
44
67
  */
45
68
  function sanitizeObject(obj, { sanitizer, ...options } = {}) {
46
69
  if (!sanitizer) throw new Error('sanitizer function is required')
package/lib/sse.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Server Sent Events (SSE)
2
+ import { parseJSON } from './objects/json.js'
2
3
  import { omitEmpty } from './objects/omit-empty.js'
3
4
 
4
5
  export function createSSE({ event, data, id, retry }) {
@@ -22,7 +23,6 @@ export function createSSE({ event, data, id, retry }) {
22
23
  * @property {number} [retry] - The retry interval if specified
23
24
  */
24
25
  export function parseSSE(message) {
25
- // console.log('parsing SSE', message);
26
26
  const lines = message.split('\n')
27
27
  const result = {
28
28
  event: 'message', // Default event type
@@ -34,10 +34,7 @@ export function parseSSE(message) {
34
34
  for (const line of lines) {
35
35
  if (line.startsWith('data:')) {
36
36
  const data = line.slice(5).trim()
37
- // Try to parse as JSON
38
- try { result.data = JSON.parse(data) }
39
- // If not JSON, use as string
40
- catch { result.data = data }
37
+ result.data = parseJSON(data)
41
38
  continue
42
39
  }
43
40
 
@@ -50,7 +47,7 @@ export function parseSSE(message) {
50
47
  result.id = line.slice(3).trim()
51
48
  continue
52
49
  }
53
-
50
+
54
51
  if (line.startsWith('retry:')) {
55
52
  result.retry = parseInt(line.slice(6).trim(), 10)
56
53
  continue
@@ -59,6 +56,6 @@ export function parseSSE(message) {
59
56
 
60
57
 
61
58
  const ret = omitEmpty(result)
62
- // Only return if we have data
63
59
  return ret.data ? ret : null
64
60
  }
61
+
@@ -2,6 +2,13 @@ import { marked } from 'marked'
2
2
  import { gfmHeadingId } from 'marked-gfm-heading-id'
3
3
  import { mangle } from 'marked-mangle'
4
4
 
5
+ /**
6
+ * Converts markdown content to HTML with whitespace handling
7
+ * @param {string} content - Markdown content to convert
8
+ * @param {Object} [options={}] - Conversion options
9
+ * @param {boolean} [options.inline=false] - Whether content should be treated as inline markdown
10
+ * @returns {string|Promise<string>} HTML string or Promise that resolves to HTML string
11
+ */
5
12
  export function markdown(content, options = {}) {
6
13
  const defaultOptions = { inline: false }
7
14
  const opts = { ...defaultOptions, ...options }
@@ -15,10 +22,11 @@ export function markdown(content, options = {}) {
15
22
  }
16
23
 
17
24
  /**
18
- * Removes leading whitespaces from a Markdown content so they can be rendered appropriately.
19
- * @param {string} content - The content to treat
20
- * @param {Boolean} options.inline - Whether content is inline, not block
21
- * @returns
25
+ * Handles whitespace in markdown content to ensure proper rendering
26
+ * @param {string} content - Markdown content to process
27
+ * @param {Object} [options={}] - Processing options
28
+ * @param {boolean} [options.inline=false] - Whether content is inline markdown
29
+ * @returns {{ content: string, inline: boolean }} Processed content and inline status
22
30
  */
23
31
  export function treatMarkdownWhitespace(content, { inline } = {}) {
24
32
  if (!content) return { content: '', inline }
@@ -3,7 +3,18 @@ import glob from 'glob-promise'
3
3
  import path from 'node:path'
4
4
  import { sort } from '../lib/arrays/index.js'
5
5
 
6
- // Newer and nicer API
6
+ /**
7
+ * Creates a file cache instance for managing cached files in a directory
8
+ * @param {string} dir - Relative path to cache directory
9
+ * @returns {Promise<object>} Cache instance
10
+ * @property {function(string): Promise<number>} cacheAt - Returns the cached file's modified timestamp, or directory's last modified time if no file specified
11
+ * @property {function(string): string} getAbsPath - Returns absolute path for a file in cache
12
+ * @property {function(string): Promise<boolean>} hasFile - Checks if a file exists in cache
13
+ * @property {function(string): Promise<Buffer|undefined>} loadFile - Loads file contents from cache
14
+ * @property {function(string, string|Buffer): Promise<void>} saveFile - Saves data to cache file
15
+ * @property {function(string): Promise<object>} loadJSON - Loads and parses JSON from cache file
16
+ * @property {function(string, object): Promise<void>} saveJSON - Saves object as JSON to cache file
17
+ */
7
18
  export async function createCache(dir) {
8
19
  const absDirpath = path.join(process.cwd(), dir)
9
20
  await fs.mkdir(absDirpath, { recursive: true })
@@ -56,7 +67,7 @@ export async function createCache(dir) {
56
67
  async loadJSON(file) {
57
68
  const data = await this.loadFile(file)
58
69
  try {
59
- return JSON.parse(data)
70
+ return JSON.parse(data.toString())
60
71
  } catch (err) {
61
72
  console.warn(`Error parsing JSON: ${file}`)
62
73
  return {}
@@ -69,7 +80,19 @@ export async function createCache(dir) {
69
80
  }
70
81
  }
71
82
 
72
- // Legacy, not so nice API
83
+ /**
84
+ * Legacy file cache API for managing a single cached file
85
+ * @param {Object} options
86
+ * @param {string} options.dir - Relative path to cache directory
87
+ * @param {string} options.file - Filename to cache
88
+ * @returns {Promise<{
89
+ * modifiedAt: number,
90
+ * load: () => Promise<Buffer>,
91
+ * save: (data: string|Buffer) => Promise<void>,
92
+ * loadJSON: () => Promise<object>,
93
+ * saveJSON: (data: object) => Promise<void>
94
+ * }>}
95
+ */
73
96
  export async function fileCache({ dir, file }) {
74
97
  // Makes the path if it doesn't exist
75
98
  await fs.mkdir(path.join(process.cwd(), dir), { recursive: true })
@@ -94,7 +117,8 @@ export async function fileCache({ dir, file }) {
94
117
  },
95
118
 
96
119
  async loadJSON() {
97
- return JSON.parse(await fs.readFile(cachePath))
120
+ const data = await fs.readFile(cachePath)
121
+ return JSON.parse(data.toString())
98
122
  },
99
123
  async saveJSON(data) {
100
124
  await fs.writeFile(cachePath, JSON.stringify(data))
@@ -102,6 +126,11 @@ export async function fileCache({ dir, file }) {
102
126
  }
103
127
  }
104
128
 
129
+ /**
130
+ * Gets the most recent modification time of files matching the glob pattern
131
+ * @param {string|string[]} globPath - Glob pattern(s) to match files
132
+ * @returns {Promise<number>} Timestamp of most recently modified file, or 0 if no files found
133
+ */
105
134
  export async function getLastModifiedTime(globPath) {
106
135
  let files
107
136
 
@@ -116,13 +145,18 @@ export async function getLastModifiedTime(globPath) {
116
145
  files = a.flat()
117
146
  }
118
147
 
119
- files = await Promise.all(files.map(fs.stat))
120
- files = files.map(file => file.mtimeMs)
148
+ const stats = await Promise.all(files.map(file => fs.stat(file)))
149
+ const timestamps = stats.map(stat => Number(stat.mtimeMs))
121
150
 
122
- const sorted = sort(files, { props: 'mtimeMs', reverse: true })
151
+ const sorted = sort(timestamps, { props: 'mtimeMs', reverse: true })
123
152
  return sorted[0] || 0
124
153
  }
125
154
 
155
+ /**
156
+ * @deprecated Use getLastModifiedTime instead
157
+ * @param {string|string[]} globPath - Glob pattern(s) to match files
158
+ * @returns {Promise<number>} Timestamp of most recently modified file, or 0 if no files found
159
+ */
126
160
  export async function getLatestModifiedTime(globPath) {
127
161
  console.warn(
128
162
  '`getLatestModifiedTime` has been renamed to `getLastModifiedTime` and will be deprecated in future versions. Please use `getLastModifiedTime` instead.',
@@ -130,6 +164,11 @@ export async function getLatestModifiedTime(globPath) {
130
164
  return getLastModifiedTime(globPath)
131
165
  }
132
166
 
167
+ /**
168
+ * Removes leading slash from a path string
169
+ * @param {string} x - Path string to process
170
+ * @returns {string} Path without leading slash
171
+ */
133
172
  export function removeFirstSlash(x) {
134
173
  return x.startsWith('/') ? x.slice(1) : x
135
174
  }
package/node/sanitize.js CHANGED
@@ -9,5 +9,5 @@ import { sanitize as sanitizeLib } from '../lib/form/sanitize.js'
9
9
  * @throws {Error} If input is a string but sanitize-html fails
10
10
  */
11
11
  export function sanitize(value, options = {}) {
12
- return sanitizeLib(value, { sanitizer: sanitizeHtml })
12
+ return sanitizeLib(value, { sanitizer: sanitizeHtml, ...options })
13
13
  }
package/package.json CHANGED
@@ -1,21 +1,42 @@
1
1
  {
2
2
  "name": "@splendidlabz/utils",
3
- "version": "1.5.0-beta.6",
3
+ "version": "1.5.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "exports": {
8
- ".": "./lib/index.js",
9
- "./lib/*": "./lib/*.js",
10
- "./dom": "./dom/index.js",
11
- "./dom/*": "./dom/*.js",
12
- "./node": "./node/index.js",
13
- "./node/*": "./node/*.js"
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./lib/index.js"
11
+ },
12
+ "./lib/*": {
13
+ "types": "./dist/lib/*.d.ts",
14
+ "import": "./lib/*.js"
15
+ },
16
+ "./dom": {
17
+ "types": "./dist/dom/index.d.ts",
18
+ "import": "./dom/index.js"
19
+ },
20
+ "./dom/*": {
21
+ "types": "./dist/dom/*.d.ts",
22
+ "import": "./dom/*.js"
23
+ },
24
+ "./node": {
25
+ "types": "./dist/node/index.d.ts",
26
+ "import": "./node/index.js"
27
+ },
28
+ "./node/*": {
29
+ "types": "./dist/node/*.d.ts",
30
+ "import": "./node/*.js"
31
+ }
14
32
  },
15
33
  "scripts": {
16
34
  "lint": "eslint . --fix",
17
- "test": "vitest run",
18
- "test:watch": "vitest"
35
+ "test": "npm run type-check && vitest run",
36
+ "test:watch": "vitest",
37
+ "type-check": "tsc --noEmit",
38
+ "build": "tsc",
39
+ "prepublishOnly": "npm run build"
19
40
  },
20
41
  "author": "Zell Liew <zellwk@gmail.com>",
21
42
  "dependencies": {
@@ -30,9 +51,10 @@
30
51
  "statuses": "^2.0.1"
31
52
  },
32
53
  "devDependencies": {
33
- "@splendidlabz/eslint-config": "2.0.0-alpha.1",
54
+ "@splendidlabz/eslint-config": "2.0.0",
34
55
  "jsdom": "^26.0.0",
35
56
  "np": "^10.2.0",
57
+ "typescript": "^5.4.2",
36
58
  "vitest": "^3.1.1"
37
59
  }
38
60
  }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "allowJs": true,
7
+ "checkJs": true,
8
+ "declaration": true,
9
+ "emitDeclarationOnly": true,
10
+ "outDir": "./dist",
11
+ "strict": false,
12
+ "noImplicitAny": false,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "isolatedModules": true,
17
+ "noEmit": false,
18
+ "esModuleInterop": true,
19
+ "allowSyntheticDefaultImports": true
20
+ },
21
+ "include": ["lib/**/*", "dom/**/*", "node/**/*"],
22
+ "exclude": ["node_modules", "**/*.test.js", "**/*.spec.js"]
23
+ }