utilful 2.5.2 → 2.5.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.
package/dist/index.d.mts CHANGED
@@ -7,6 +7,6 @@ import { interopDefault } from "./module.mjs";
7
7
  import { deepApply, isObject, memoize, objectEntries, objectKeys } from "./object.mjs";
8
8
  import { QueryObject, QueryValue, getPathname, joinURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash } from "./path.mjs";
9
9
  import { Err, ErrData, Ok, OkData, Result, ResultData, err, isErr, isOk, ok, toResult, tryCatch, unwrapResult } from "./result.mjs";
10
- import { generateRandomId, template } from "./string.mjs";
10
+ import { TEMPLATE_PLACEHOLDER_RE, generateRandomId, template } from "./string.mjs";
11
11
  import { AutocompletableString, BrandedType, LooseAutocomplete, UnifyIntersection } from "./types.mjs";
12
- export { AutocompletableString, BrandedType, CSVCreateOptions, CSVRow, DefuFn, DefuMerger, Emitter, Err, ErrData, EventHandlerList, EventHandlerMap, EventType, Handler, LooseAutocomplete, MaybeArray, Ok, OkData, QueryObject, QueryValue, Result, ResultData, UnifyIntersection, WildCardEventHandlerList, WildcardHandler, cloneJSON, createCSV, createCSVAsync, createCSVStream, createDefu, createEmitter, deepApply, defu, err, escapeCSVValue, generateRandomId, getPathname, interopDefault, isErr, isObject, isOk, joinURL, memoize, objectEntries, objectKeys, ok, parseCSV, parseCSVFromLines, parseCSVStream, template, toArray, toResult, tryCatch, tryParseJSON, unwrapResult, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
12
+ export { AutocompletableString, BrandedType, CSVCreateOptions, CSVRow, DefuFn, DefuMerger, Emitter, Err, ErrData, EventHandlerList, EventHandlerMap, EventType, Handler, LooseAutocomplete, MaybeArray, Ok, OkData, QueryObject, QueryValue, Result, ResultData, TEMPLATE_PLACEHOLDER_RE, UnifyIntersection, WildCardEventHandlerList, WildcardHandler, cloneJSON, createCSV, createCSVAsync, createCSVStream, createDefu, createEmitter, deepApply, defu, err, escapeCSVValue, generateRandomId, getPathname, interopDefault, isErr, isObject, isOk, joinURL, memoize, objectEntries, objectKeys, ok, parseCSV, parseCSVFromLines, parseCSVStream, template, toArray, toResult, tryCatch, tryParseJSON, unwrapResult, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
package/dist/index.mjs CHANGED
@@ -7,5 +7,5 @@ import { interopDefault } from "./module.mjs";
7
7
  import { deepApply, isObject, memoize, objectEntries, objectKeys } from "./object.mjs";
8
8
  import { getPathname, joinURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash } from "./path.mjs";
9
9
  import { Err, Ok, err, isErr, isOk, ok, toResult, tryCatch, unwrapResult } from "./result.mjs";
10
- import { generateRandomId, template } from "./string.mjs";
11
- export { Err, Ok, cloneJSON, createCSV, createCSVAsync, createCSVStream, createDefu, createEmitter, deepApply, defu, err, escapeCSVValue, generateRandomId, getPathname, interopDefault, isErr, isObject, isOk, joinURL, memoize, objectEntries, objectKeys, ok, parseCSV, parseCSVFromLines, parseCSVStream, template, toArray, toResult, tryCatch, tryParseJSON, unwrapResult, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
10
+ import { TEMPLATE_PLACEHOLDER_RE, generateRandomId, template } from "./string.mjs";
11
+ export { Err, Ok, TEMPLATE_PLACEHOLDER_RE, cloneJSON, createCSV, createCSVAsync, createCSVStream, createDefu, createEmitter, deepApply, defu, err, escapeCSVValue, generateRandomId, getPathname, interopDefault, isErr, isObject, isOk, joinURL, memoize, objectEntries, objectKeys, ok, parseCSV, parseCSVFromLines, parseCSVStream, template, toArray, toResult, tryCatch, tryParseJSON, unwrapResult, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
package/dist/path.mjs CHANGED
@@ -56,7 +56,7 @@ function joinURL(...paths) {
56
56
  continue;
57
57
  }
58
58
  if (path === "/") continue;
59
- const resultHasTrailing = result[result.length - 1] === "/";
59
+ const resultHasTrailing = result.at(-1) === "/";
60
60
  const pathHasLeading = path[0] === "/";
61
61
  if (resultHasTrailing && pathHasLeading) result += path.slice(1);
62
62
  else if (!resultHasTrailing && !pathHasLeading) result += `/${path}`;
package/dist/string.d.mts CHANGED
@@ -1,4 +1,6 @@
1
1
  //#region src/string.d.ts
2
+ /** Regex pattern to match template placeholders in the format `{key}`. */
3
+ declare const TEMPLATE_PLACEHOLDER_RE: RegExp;
2
4
  /**
3
5
  * Simple template engine to replace variables in a string.
4
6
  *
@@ -17,4 +19,4 @@ declare function template(str: string, variables: Record<string | number, any>,
17
19
  */
18
20
  declare function generateRandomId(size?: number, dict?: string): string;
19
21
  //#endregion
20
- export { generateRandomId, template };
22
+ export { TEMPLATE_PLACEHOLDER_RE, generateRandomId, template };
package/dist/string.mjs CHANGED
@@ -1,5 +1,7 @@
1
1
  //#region src/string.ts
2
2
  const URL_ALPHABET = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
3
+ /** Regex pattern to match template placeholders in the format `{key}`. */
4
+ const TEMPLATE_PLACEHOLDER_RE = /\{(\w+)\}/g;
3
5
  /**
4
6
  * Simple template engine to replace variables in a string.
5
7
  *
@@ -10,7 +12,7 @@ const URL_ALPHABET = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvw
10
12
  * console.log(template(str, variables)) // Hello, world!
11
13
  */
12
14
  function template(str, variables, fallback) {
13
- return str.replace(/\{(\w+)\}/g, (_, key) => {
15
+ return str.replace(TEMPLATE_PLACEHOLDER_RE, (_, key) => {
14
16
  return variables[key] != null ? String(variables[key]) : (typeof fallback === "function" ? fallback(key) : fallback) ?? key;
15
17
  });
16
18
  }
@@ -28,4 +30,4 @@ function generateRandomId(size = 16, dict = URL_ALPHABET) {
28
30
  return id;
29
31
  }
30
32
  //#endregion
31
- export { generateRandomId, template };
33
+ export { TEMPLATE_PLACEHOLDER_RE, generateRandomId, template };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "utilful",
3
3
  "type": "module",
4
- "version": "2.5.2",
5
- "packageManager": "pnpm@10.30.3",
4
+ "version": "2.5.3",
5
+ "packageManager": "pnpm@10.33.0",
6
6
  "description": "A collection of TypeScript utilities",
7
7
  "author": "Johann Schopplich <hello@johannschopplich.com>",
8
8
  "license": "MIT",
@@ -78,14 +78,14 @@
78
78
  "release": "bumpp"
79
79
  },
80
80
  "devDependencies": {
81
- "@antfu/eslint-config": "^7.6.1",
82
- "@types/node": "^25.3.5",
83
- "bumpp": "^10.4.1",
84
- "eslint": "^10.0.2",
85
- "eslint-flat-config-utils": "^3.0.1",
86
- "tsdown": "^0.21.0",
87
- "typescript": "^5.9.3",
88
- "vitest": "^4.0.18"
81
+ "@antfu/eslint-config": "^7.7.3",
82
+ "@types/node": "^25.5.0",
83
+ "bumpp": "^11.0.1",
84
+ "eslint": "^10.1.0",
85
+ "eslint-flat-config-utils": "^3.1.0",
86
+ "tsdown": "^0.21.7",
87
+ "typescript": "^6.0.2",
88
+ "vitest": "^4.1.2"
89
89
  },
90
90
  "pnpm": {
91
91
  "onlyBuiltDependencies": [