utilful 2.5.1 → 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/array.mjs +1 -2
- package/dist/csv.d.mts +2 -5
- package/dist/csv.mjs +1 -2
- package/dist/defu.mjs +1 -2
- package/dist/emitter.mjs +1 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -3
- package/dist/json.mjs +1 -2
- package/dist/module.mjs +1 -2
- package/dist/object.mjs +1 -2
- package/dist/path.mjs +2 -3
- package/dist/result.d.mts +2 -2
- package/dist/result.mjs +1 -2
- package/dist/string.d.mts +3 -1
- package/dist/string.mjs +5 -4
- package/dist/types.mjs +1 -1
- package/package.json +10 -9
package/dist/array.mjs
CHANGED
package/dist/csv.d.mts
CHANGED
|
@@ -102,9 +102,7 @@ declare function createCSVAsync<T extends Record<string, unknown>>(data: AsyncIt
|
|
|
102
102
|
* escapeCSVValue('contains "quotes"') // "contains ""quotes"""
|
|
103
103
|
*/
|
|
104
104
|
declare function escapeCSVValue(value: unknown, options?: {
|
|
105
|
-
/** @default ',' */
|
|
106
|
-
delimiter?: string;
|
|
107
|
-
/** @default false */
|
|
105
|
+
/** @default ',' */delimiter?: string; /** @default false */
|
|
108
106
|
quoteAll?: boolean;
|
|
109
107
|
}): string;
|
|
110
108
|
/**
|
|
@@ -122,8 +120,7 @@ declare function escapeCSVValue(value: unknown, options?: {
|
|
|
122
120
|
* // [{ name: 'John', age: '30' }, { name: 'Jane', age: '25' }]
|
|
123
121
|
*/
|
|
124
122
|
declare function parseCSV<Header extends string>(csv?: string | null | undefined, options?: {
|
|
125
|
-
/** @default ',' */
|
|
126
|
-
delimiter?: string;
|
|
123
|
+
/** @default ',' */delimiter?: string;
|
|
127
124
|
/**
|
|
128
125
|
* Trim whitespace from headers and values.
|
|
129
126
|
* @default true
|
package/dist/csv.mjs
CHANGED
|
@@ -291,6 +291,5 @@ function inferColumns(rows) {
|
|
|
291
291
|
}
|
|
292
292
|
return columns;
|
|
293
293
|
}
|
|
294
|
-
|
|
295
294
|
//#endregion
|
|
296
|
-
export { createCSV, createCSVAsync, createCSVStream, escapeCSVValue, parseCSV, parseCSVFromLines, parseCSVStream };
|
|
295
|
+
export { createCSV, createCSVAsync, createCSVStream, escapeCSVValue, parseCSV, parseCSVFromLines, parseCSVStream };
|
package/dist/defu.mjs
CHANGED
package/dist/emitter.mjs
CHANGED
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,6 +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
|
-
|
|
12
|
-
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/json.mjs
CHANGED
package/dist/module.mjs
CHANGED
package/dist/object.mjs
CHANGED
|
@@ -49,6 +49,5 @@ function deepApply(data, callback) {
|
|
|
49
49
|
function isObject(value) {
|
|
50
50
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
51
51
|
}
|
|
52
|
-
|
|
53
52
|
//#endregion
|
|
54
|
-
export { deepApply, isObject, memoize, objectEntries, objectKeys };
|
|
53
|
+
export { deepApply, isObject, memoize, objectEntries, objectKeys };
|
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
|
|
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}`;
|
|
@@ -123,6 +123,5 @@ function normalizeQueryValue(value) {
|
|
|
123
123
|
if (typeof value === "object") return JSON.stringify(value);
|
|
124
124
|
return String(value);
|
|
125
125
|
}
|
|
126
|
-
|
|
127
126
|
//#endregion
|
|
128
|
-
export { getPathname, joinURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
|
|
127
|
+
export { getPathname, joinURL, withBase, withLeadingSlash, withQuery, withTrailingSlash, withoutBase, withoutLeadingSlash, withoutTrailingSlash };
|
package/dist/result.d.mts
CHANGED
|
@@ -16,7 +16,7 @@ type ResultData<T, E> = OkData<T> | ErrData<E>;
|
|
|
16
16
|
*/
|
|
17
17
|
declare class Ok<T, E = never> {
|
|
18
18
|
readonly value: T;
|
|
19
|
-
readonly ok
|
|
19
|
+
readonly ok = true;
|
|
20
20
|
constructor(value: T);
|
|
21
21
|
/** Transforms the success value. */
|
|
22
22
|
map<U>(fn: (value: T) => U): Ok<U, E>;
|
|
@@ -41,7 +41,7 @@ declare class Ok<T, E = never> {
|
|
|
41
41
|
*/
|
|
42
42
|
declare class Err<T, E> {
|
|
43
43
|
readonly error: E;
|
|
44
|
-
readonly ok
|
|
44
|
+
readonly ok = false;
|
|
45
45
|
constructor(error: E);
|
|
46
46
|
/** No-op on Err, returns self with new value type. */
|
|
47
47
|
map<U>(_fn: (value: T) => U): Err<U, E>;
|
package/dist/result.mjs
CHANGED
|
@@ -104,6 +104,5 @@ function tryCatch(fnOrPromise) {
|
|
|
104
104
|
if (fnOrPromise instanceof Promise) return toResult(fnOrPromise).then((result) => unwrapResult(result));
|
|
105
105
|
return unwrapResult(toResult(fnOrPromise));
|
|
106
106
|
}
|
|
107
|
-
|
|
108
107
|
//#endregion
|
|
109
|
-
export { Err, Ok, err, isErr, isOk, ok, toResult, tryCatch, unwrapResult };
|
|
108
|
+
export { Err, Ok, err, isErr, isOk, ok, toResult, tryCatch, unwrapResult };
|
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,8 +12,8 @@ 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(
|
|
14
|
-
return variables[key]
|
|
15
|
+
return str.replace(TEMPLATE_PLACEHOLDER_RE, (_, key) => {
|
|
16
|
+
return variables[key] != null ? String(variables[key]) : (typeof fallback === "function" ? fallback(key) : fallback) ?? key;
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
@@ -27,6 +29,5 @@ function generateRandomId(size = 16, dict = URL_ALPHABET) {
|
|
|
27
29
|
while (i--) id += dict[Math.random() * len | 0];
|
|
28
30
|
return id;
|
|
29
31
|
}
|
|
30
|
-
|
|
31
32
|
//#endregion
|
|
32
|
-
export { generateRandomId, template };
|
|
33
|
+
export { TEMPLATE_PLACEHOLDER_RE, generateRandomId, template };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "utilful",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.5.
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
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,13 +78,14 @@
|
|
|
78
78
|
"release": "bumpp"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@antfu/eslint-config": "^7.
|
|
82
|
-
"@types/node": "^25.0
|
|
83
|
-
"bumpp": "^
|
|
84
|
-
"eslint": "^
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
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"
|
|
88
89
|
},
|
|
89
90
|
"pnpm": {
|
|
90
91
|
"onlyBuiltDependencies": [
|