umsizi 0.2.2 → 0.4.0

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/README.md CHANGED
@@ -117,6 +117,114 @@ const value = identity("umsizi");
117
117
 
118
118
  ```
119
119
 
120
+ #### `typedKeys`
121
+
122
+ ```ts
123
+ import { typedKeys } from "umsizi";
124
+
125
+ const user = { id: "1", name: "Jack" } as const;
126
+
127
+ typedKeys(user);
128
+ // ["id", "name"]
129
+ ```
130
+
131
+ #### `typedEntries`
132
+
133
+ ```ts
134
+ import { typedEntries } from "umsizi";
135
+
136
+ const user = { id: "1", active: true } as const;
137
+
138
+ typedEntries(user);
139
+ // [["id", "1"], ["active", true]]
140
+ ```
141
+
142
+ #### `typedFromEntries`
143
+
144
+ ```ts
145
+ import { typedFromEntries } from "umsizi";
146
+
147
+ const user = typedFromEntries([
148
+ ["id", "1"],
149
+ ["active", true],
150
+ ] as const);
151
+ ```
152
+
153
+ #### `pick`
154
+
155
+ ```ts
156
+ import { pick } from "umsizi";
157
+
158
+ pick({ id: "1", name: "Jack", role: "admin" }, "id", "role");
159
+ // { id: "1", role: "admin" }
160
+ ```
161
+
162
+ #### `omit`
163
+
164
+ ```ts
165
+ import { omit } from "umsizi";
166
+
167
+ omit({ id: "1", name: "Jack", role: "admin" }, "role");
168
+ // { id: "1", name: "Jack" }
169
+ ```
170
+
171
+ For the best autocomplete, prefer the rest-key form for `pick()` and `omit()`.
172
+ If you pass an array literal and want exact key inference, use `as const`:
173
+
174
+ ```ts
175
+ pick(user, ["id", "role"] as const);
176
+ omit(user, ["createdAt"] as const);
177
+ ```
178
+
179
+ #### `isEmpty`
180
+
181
+ ```ts
182
+ import { isEmpty } from "umsizi";
183
+
184
+ isEmpty({});
185
+ // true
186
+ ```
187
+
188
+ #### `hasOwn`
189
+
190
+ ```ts
191
+ import { hasOwn } from "umsizi";
192
+
193
+ const user = { id: "1" };
194
+ const key: string = "id";
195
+
196
+ if (hasOwn(user, key)) {
197
+ user[key];
198
+ }
199
+ ```
200
+
201
+ #### `mapValues`
202
+
203
+ ```ts
204
+ import { mapValues } from "umsizi";
205
+
206
+ mapValues({ draft: 1, published: 2 }, (value) => value * 2);
207
+ // { draft: 2, published: 4 }
208
+ ```
209
+
210
+ #### `filterValues`
211
+
212
+ ```ts
213
+ import { filterValues } from "umsizi";
214
+
215
+ filterValues({ a: 1, b: 0, c: null }, (value) => value !== null);
216
+ // { a: 1, b: 0 }
217
+ ```
218
+
219
+ #### `compactObject`
220
+
221
+ ```ts
222
+ import { compactObject } from "umsizi";
223
+
224
+ compactObject({ id: "1", nickname: null, active: false });
225
+ // { id: "1", active: false }
226
+ ```
227
+
120
228
  ### React Utilities (`umsizi/react`)
121
229
 
122
230
  #### `isRenderFunction`
package/dist/index.d.ts CHANGED
@@ -1,9 +1,70 @@
1
- import { t as normalizePathname } from "./index-rZiv1o95.js";
2
- import { t as hasFileExtension } from "./index-DtjbEW43.js";
3
- import { t as isRenderFunction } from "./index-dktuz4mv.js";
4
-
1
+ //#region src/core/types.d.ts
2
+ type StringKeyOf<T extends object> = Extract<keyof T, string>;
3
+ type ObjectEntry<T extends object> = { [K in StringKeyOf<T>]: readonly [K, T[K]] }[StringKeyOf<T>];
4
+ type ObjectEntries<T extends object> = Array<ObjectEntry<T>>;
5
+ type EntryTuple = readonly [PropertyKey, unknown];
6
+ type EntryTuples = ReadonlyArray<EntryTuple>;
7
+ type ObjectFromEntries<T extends EntryTuples> = { [K in T[number] as K[0]]: K[1] };
8
+ type ValueMapper<T extends object, R> = (value: T[StringKeyOf<T>], key: StringKeyOf<T>, object: T) => R;
9
+ type ValuePredicate<T extends object> = (value: T[StringKeyOf<T>], key: StringKeyOf<T>, object: T) => boolean;
10
+ type ValueGuard<T extends object, S extends T[StringKeyOf<T>]> = (value: T[StringKeyOf<T>], key: StringKeyOf<T>, object: T) => value is S;
11
+ type MappedValues<T extends object, R> = { [K in StringKeyOf<T>]: R };
12
+ type FilteredValues<T extends object, S extends T[StringKeyOf<T>]> = Partial<{ [K in StringKeyOf<T>]: Extract<T[K], S> }>;
13
+ type CompactedObject<T extends object> = Partial<{ [K in StringKeyOf<T>]: Exclude<T[K], null | undefined> }>;
14
+ //#endregion
15
+ //#region src/core/compact-object.d.ts
16
+ /**
17
+ * Creates a new object with all `null` and `undefined` values removed.
18
+ *
19
+ * Other falsy values such as `0`, `false`, `""`, and `NaN` are preserved.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const user = { id: "1", nickname: null, active: false } as const;
24
+ *
25
+ * compactObject(user); // { id: "1", active: false }
26
+ * ```
27
+ */
28
+ declare function compactObject<T extends object>(object: T): CompactedObject<T>;
29
+ //#endregion
30
+ //#region src/core/filter-values.d.ts
31
+ /**
32
+ * Filters an object's own enumerable string-keyed properties by value.
33
+ *
34
+ * Supports both boolean predicates and type-guard predicates. The result type
35
+ * remains partial because any property may be removed at runtime.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const settings = { retries: 3, label: "", timeout: null } as const;
40
+ *
41
+ * filterValues(settings, (value) => value !== null);
42
+ * // { retries: 3, label: "" }
43
+ * ```
44
+ */
45
+ declare function filterValues<T extends object, S extends T[Extract<keyof T, string>]>(object: T, predicate: ValueGuard<T, S>): FilteredValues<T, S>;
46
+ declare function filterValues<T extends object>(object: T, predicate: ValuePredicate<T>): FilteredValues<T, T[Extract<keyof T, string>]>;
47
+ //#endregion
48
+ //#region src/core/has-own.d.ts
49
+ /**
50
+ * Checks whether an object has the given property as its own key.
51
+ *
52
+ * This is a typed wrapper around `Object.hasOwn` that narrows the provided key
53
+ * when the check succeeds.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const user = { id: "1" };
58
+ * const key: string = "id";
59
+ *
60
+ * if (hasOwn(user, key)) {
61
+ * user[key]; // key is narrowed to "id"
62
+ * }
63
+ * ```
64
+ */
65
+ declare function hasOwn<T extends object, K$1 extends PropertyKey>(object: T, key: K$1): key is Extract<K$1, keyof T>;
66
+ //#endregion
5
67
  //#region src/core/identity.d.ts
6
-
7
68
  /**
8
69
  * Returns the given value unchanged.
9
70
  *
@@ -17,5 +78,121 @@ import { t as isRenderFunction } from "./index-dktuz4mv.js";
17
78
  */
18
79
  declare function identity<T>(value: T): T;
19
80
  //#endregion
20
- export { hasFileExtension, identity, isRenderFunction, normalizePathname };
81
+ //#region src/core/is-empty.d.ts
82
+ /**
83
+ * Returns `true` when an object has no own enumerable properties.
84
+ *
85
+ * Both string keys and symbol keys are considered. Non-enumerable properties
86
+ * are ignored.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * isEmpty({}); // true
91
+ * isEmpty({ id: "1" }); // false
92
+ * ```
93
+ */
94
+ declare function isEmpty(object: object): boolean;
95
+ //#endregion
96
+ //#region src/core/map-values.d.ts
97
+ /**
98
+ * Maps the values of an object's own enumerable string-keyed properties while
99
+ * preserving the original enumerable string-key set.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * const counts = { draft: 1, published: 2 };
104
+ *
105
+ * mapValues(counts, (value) => value * 2);
106
+ * // { draft: 2, published: 4 }
107
+ * ```
108
+ */
109
+ declare function mapValues<T extends object, R>(object: T, mapper: ValueMapper<T, R>): MappedValues<T, R>;
110
+ //#endregion
111
+ //#region src/core/omit.d.ts
112
+ /**
113
+ * Creates a new object excluding the selected own enumerable properties.
114
+ *
115
+ * Prefer the rest-key form for the strongest autocomplete and inference.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const user = { id: "1", name: "Umsizi", role: "admin" } as const;
120
+ *
121
+ * omit(user, "id", "name"); // { role: "admin" }
122
+ * omit(user, ["role"] as const); // { id: "1", name: "Umsizi" }
123
+ * ```
124
+ */
125
+ declare function omit<T extends object, const Keys extends readonly (keyof T)[]>(object: T, ...keys: Keys): Omit<T, Keys[number]>;
126
+ declare function omit<T extends object, const FirstKey extends keyof T, const RestKeys extends readonly (keyof T)[]>(object: T, keys: readonly [FirstKey, ...RestKeys]): Omit<T, FirstKey | RestKeys[number]>;
127
+ declare function omit<T extends object>(object: T, keys: readonly (keyof T)[]): Partial<T>;
128
+ //#endregion
129
+ //#region src/core/pick.d.ts
130
+ /**
131
+ * Creates a new object containing only the selected own properties.
132
+ *
133
+ * Prefer the rest-key form for the strongest autocomplete and inference.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * const user = { id: "1", name: "Umsizi", role: "admin" } as const;
138
+ *
139
+ * pick(user, "name"); // { name: "Umsizi" }
140
+ * pick(user, ["id", "role"] as const); // { id: "1", role: "admin" }
141
+ * ```
142
+ */
143
+ declare function pick<T extends object, const Keys extends readonly (keyof T)[]>(object: T, ...keys: Keys): Pick<T, Keys[number]>;
144
+ declare function pick<T extends object, const FirstKey extends keyof T, const RestKeys extends readonly (keyof T)[]>(object: T, keys: readonly [FirstKey, ...RestKeys]): Pick<T, FirstKey | RestKeys[number]>;
145
+ declare function pick<T extends object>(object: T, keys: readonly (keyof T)[]): Partial<T>;
146
+ //#endregion
147
+ //#region src/core/typed-entries.d.ts
148
+ /**
149
+ * Returns the own enumerable string-keyed entries of an object with preserved
150
+ * key/value pairing.
151
+ *
152
+ * This is a typed wrapper around `Object.entries`.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * const user = { id: "1", active: true } as const;
157
+ *
158
+ * typedEntries(user); // [["id", "1"], ["active", true]]
159
+ * ```
160
+ */
161
+ declare function typedEntries<T extends object>(object: T): ObjectEntries<T>;
162
+ //#endregion
163
+ //#region src/core/typed-from-entries.d.ts
164
+ /**
165
+ * Creates an object from entries while preserving the key and value types from
166
+ * the input tuple array.
167
+ *
168
+ * This is a typed wrapper around `Object.fromEntries`.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * const status = typedFromEntries([
173
+ * ["id", "1"],
174
+ * ["active", true],
175
+ * ] as const);
176
+ *
177
+ * // inferred as: { id: "1"; active: true }
178
+ * ```
179
+ */
180
+ declare function typedFromEntries<const T extends EntryTuples>(entries: T): ObjectFromEntries<T>;
181
+ //#endregion
182
+ //#region src/core/typed-keys.d.ts
183
+ /**
184
+ * Returns the own enumerable string keys of an object with preserved key types.
185
+ *
186
+ * This is a typed wrapper around `Object.keys`.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const user = { id: "1", name: "Umsizi" } as const;
191
+ *
192
+ * typedKeys(user); // ["id", "name"]
193
+ * ```
194
+ */
195
+ declare function typedKeys<T extends object>(object: T): Array<StringKeyOf<T>>;
196
+ //#endregion
197
+ export { compactObject, filterValues, hasOwn, identity, isEmpty, mapValues, omit, pick, typedEntries, typedFromEntries, typedKeys };
21
198
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,7 +1,77 @@
1
- import { t as normalizePathname } from "./next-C3wp7UoQ.js";
2
- import { t as hasFileExtension } from "./node-D-nlzpmG.js";
3
- import { t as isRenderFunction } from "./react-BCidSnzT.js";
1
+ //#region src/core/typed-keys.ts
2
+ /**
3
+ * Returns the own enumerable string keys of an object with preserved key types.
4
+ *
5
+ * This is a typed wrapper around `Object.keys`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const user = { id: "1", name: "Umsizi" } as const;
10
+ *
11
+ * typedKeys(user); // ["id", "name"]
12
+ * ```
13
+ */
14
+ function typedKeys(object) {
15
+ return Object.keys(object);
16
+ }
17
+
18
+ //#endregion
19
+ //#region src/core/compact-object.ts
20
+ /**
21
+ * Creates a new object with all `null` and `undefined` values removed.
22
+ *
23
+ * Other falsy values such as `0`, `false`, `""`, and `NaN` are preserved.
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const user = { id: "1", nickname: null, active: false } as const;
28
+ *
29
+ * compactObject(user); // { id: "1", active: false }
30
+ * ```
31
+ */
32
+ function compactObject(object) {
33
+ const result = {};
34
+ for (const key of typedKeys(object)) {
35
+ const value = object[key];
36
+ if (value != null) result[key] = value;
37
+ }
38
+ return result;
39
+ }
40
+
41
+ //#endregion
42
+ //#region src/core/filter-values.ts
43
+ function filterValues(object, predicate) {
44
+ const result = {};
45
+ for (const key of typedKeys(object)) {
46
+ const value = object[key];
47
+ if (predicate(value, key, object)) result[key] = value;
48
+ }
49
+ return result;
50
+ }
4
51
 
52
+ //#endregion
53
+ //#region src/core/has-own.ts
54
+ /**
55
+ * Checks whether an object has the given property as its own key.
56
+ *
57
+ * This is a typed wrapper around `Object.hasOwn` that narrows the provided key
58
+ * when the check succeeds.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const user = { id: "1" };
63
+ * const key: string = "id";
64
+ *
65
+ * if (hasOwn(user, key)) {
66
+ * user[key]; // key is narrowed to "id"
67
+ * }
68
+ * ```
69
+ */
70
+ function hasOwn(object, key) {
71
+ return Object.hasOwn(object, key);
72
+ }
73
+
74
+ //#endregion
5
75
  //#region src/core/identity.ts
6
76
  /**
7
77
  * Returns the given value unchanged.
@@ -19,5 +89,105 @@ function identity(value) {
19
89
  }
20
90
 
21
91
  //#endregion
22
- export { hasFileExtension, identity, isRenderFunction, normalizePathname };
92
+ //#region src/core/is-empty.ts
93
+ /**
94
+ * Returns `true` when an object has no own enumerable properties.
95
+ *
96
+ * Both string keys and symbol keys are considered. Non-enumerable properties
97
+ * are ignored.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * isEmpty({}); // true
102
+ * isEmpty({ id: "1" }); // false
103
+ * ```
104
+ */
105
+ function isEmpty(object) {
106
+ if (Object.keys(object).length > 0) return false;
107
+ for (const key of Object.getOwnPropertySymbols(object)) if (Object.prototype.propertyIsEnumerable.call(object, key)) return false;
108
+ return true;
109
+ }
110
+
111
+ //#endregion
112
+ //#region src/core/map-values.ts
113
+ /**
114
+ * Maps the values of an object's own enumerable string-keyed properties while
115
+ * preserving the original enumerable string-key set.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * const counts = { draft: 1, published: 2 };
120
+ *
121
+ * mapValues(counts, (value) => value * 2);
122
+ * // { draft: 2, published: 4 }
123
+ * ```
124
+ */
125
+ function mapValues(object, mapper) {
126
+ const result = {};
127
+ for (const key of typedKeys(object)) result[key] = mapper(object[key], key, object);
128
+ return result;
129
+ }
130
+
131
+ //#endregion
132
+ //#region src/core/omit.ts
133
+ function omit(object, firstKeyOrKeys, ...restKeys) {
134
+ const keys = Array.isArray(firstKeyOrKeys) ? firstKeyOrKeys : [firstKeyOrKeys, ...restKeys];
135
+ const omittedKeys = new Set(keys);
136
+ const result = {};
137
+ for (const key of Reflect.ownKeys(object)) if (Object.prototype.propertyIsEnumerable.call(object, key) && !omittedKeys.has(key)) result[key] = object[key];
138
+ return result;
139
+ }
140
+
141
+ //#endregion
142
+ //#region src/core/pick.ts
143
+ function pick(object, firstKeyOrKeys, ...restKeys) {
144
+ const keys = Array.isArray(firstKeyOrKeys) ? firstKeyOrKeys : [firstKeyOrKeys, ...restKeys];
145
+ const result = {};
146
+ for (const key of keys) if (hasOwn(object, key)) result[key] = object[key];
147
+ return result;
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/core/typed-entries.ts
152
+ /**
153
+ * Returns the own enumerable string-keyed entries of an object with preserved
154
+ * key/value pairing.
155
+ *
156
+ * This is a typed wrapper around `Object.entries`.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * const user = { id: "1", active: true } as const;
161
+ *
162
+ * typedEntries(user); // [["id", "1"], ["active", true]]
163
+ * ```
164
+ */
165
+ function typedEntries(object) {
166
+ return Object.entries(object);
167
+ }
168
+
169
+ //#endregion
170
+ //#region src/core/typed-from-entries.ts
171
+ /**
172
+ * Creates an object from entries while preserving the key and value types from
173
+ * the input tuple array.
174
+ *
175
+ * This is a typed wrapper around `Object.fromEntries`.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * const status = typedFromEntries([
180
+ * ["id", "1"],
181
+ * ["active", true],
182
+ * ] as const);
183
+ *
184
+ * // inferred as: { id: "1"; active: true }
185
+ * ```
186
+ */
187
+ function typedFromEntries(entries) {
188
+ return Object.fromEntries(entries);
189
+ }
190
+
191
+ //#endregion
192
+ export { compactObject, filterValues, hasOwn, identity, isEmpty, mapValues, omit, pick, typedEntries, typedFromEntries, typedKeys };
23
193
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/core/identity.ts"],"sourcesContent":["/**\n * Returns the given value unchanged.\n *\n * Useful as a default callback, a type-inference anchor, or a no-op\n * placeholder where a transform function is expected.\n *\n * @example\n * ```ts\n * identity(\"umsizi\"); // \"umsizi\"\n * ```\n */\nexport function identity<T>(value: T): T {\n\treturn value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAWA,SAAgB,SAAY,OAAa;AACxC,QAAO"}
1
+ {"version":3,"file":"index.js","names":["result: Partial<T>","result: Partial<T>"],"sources":["../src/core/typed-keys.ts","../src/core/compact-object.ts","../src/core/filter-values.ts","../src/core/has-own.ts","../src/core/identity.ts","../src/core/is-empty.ts","../src/core/map-values.ts","../src/core/omit.ts","../src/core/pick.ts","../src/core/typed-entries.ts","../src/core/typed-from-entries.ts"],"sourcesContent":["import type { StringKeyOf } from \"./types\";\n\n/**\n * Returns the own enumerable string keys of an object with preserved key types.\n *\n * This is a typed wrapper around `Object.keys`.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\" } as const;\n *\n * typedKeys(user); // [\"id\", \"name\"]\n * ```\n */\nexport function typedKeys<T extends object>(object: T): Array<StringKeyOf<T>> {\n\treturn Object.keys(object) as Array<StringKeyOf<T>>;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { CompactedObject } from \"./types\";\n\n/**\n * Creates a new object with all `null` and `undefined` values removed.\n *\n * Other falsy values such as `0`, `false`, `\"\"`, and `NaN` are preserved.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", nickname: null, active: false } as const;\n *\n * compactObject(user); // { id: \"1\", active: false }\n * ```\n */\nexport function compactObject<T extends object>(object: T): CompactedObject<T> {\n\tconst result = {} as CompactedObject<T>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (value != null) {\n\t\t\tresult[key] = value as Exclude<T[typeof key], null | undefined>;\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { FilteredValues, ValueGuard, ValuePredicate } from \"./types\";\n\n/**\n * Filters an object's own enumerable string-keyed properties by value.\n *\n * Supports both boolean predicates and type-guard predicates. The result type\n * remains partial because any property may be removed at runtime.\n *\n * @example\n * ```ts\n * const settings = { retries: 3, label: \"\", timeout: null } as const;\n *\n * filterValues(settings, (value) => value !== null);\n * // { retries: 3, label: \"\" }\n * ```\n */\nexport function filterValues<\n\tT extends object,\n\tS extends T[Extract<keyof T, string>],\n>(object: T, predicate: ValueGuard<T, S>): FilteredValues<T, S>;\nexport function filterValues<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): FilteredValues<T, T[Extract<keyof T, string>]>;\nexport function filterValues<T extends object>(\n\tobject: T,\n\tpredicate: ValuePredicate<T>,\n): FilteredValues<T, T[Extract<keyof T, string>]> {\n\tconst result = {} as FilteredValues<T, T[Extract<keyof T, string>]>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tconst value = object[key];\n\n\t\tif (predicate(value, key, object)) {\n\t\t\tresult[key] = value;\n\t\t}\n\t}\n\n\treturn result;\n}\n","/**\n * Checks whether an object has the given property as its own key.\n *\n * This is a typed wrapper around `Object.hasOwn` that narrows the provided key\n * when the check succeeds.\n *\n * @example\n * ```ts\n * const user = { id: \"1\" };\n * const key: string = \"id\";\n *\n * if (hasOwn(user, key)) {\n * user[key]; // key is narrowed to \"id\"\n * }\n * ```\n */\nexport function hasOwn<T extends object, K extends PropertyKey>(\n\tobject: T,\n\tkey: K,\n): key is Extract<K, keyof T> {\n\treturn Object.hasOwn(object, key);\n}\n","/**\n * Returns the given value unchanged.\n *\n * Useful as a default callback, a type-inference anchor, or a no-op\n * placeholder where a transform function is expected.\n *\n * @example\n * ```ts\n * identity(\"umsizi\"); // \"umsizi\"\n * ```\n */\nexport function identity<T>(value: T): T {\n\treturn value;\n}\n","/**\n * Returns `true` when an object has no own enumerable properties.\n *\n * Both string keys and symbol keys are considered. Non-enumerable properties\n * are ignored.\n *\n * @example\n * ```ts\n * isEmpty({}); // true\n * isEmpty({ id: \"1\" }); // false\n * ```\n */\nexport function isEmpty(object: object): boolean {\n\tif (Object.keys(object).length > 0) {\n\t\treturn false;\n\t}\n\n\tfor (const key of Object.getOwnPropertySymbols(object)) {\n\t\tif (Object.prototype.propertyIsEnumerable.call(object, key)) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n","import { typedKeys } from \"./typed-keys\";\nimport type { MappedValues, ValueMapper } from \"./types\";\n\n/**\n * Maps the values of an object's own enumerable string-keyed properties while\n * preserving the original enumerable string-key set.\n *\n * @example\n * ```ts\n * const counts = { draft: 1, published: 2 };\n *\n * mapValues(counts, (value) => value * 2);\n * // { draft: 2, published: 4 }\n * ```\n */\nexport function mapValues<T extends object, R>(\n\tobject: T,\n\tmapper: ValueMapper<T, R>,\n): MappedValues<T, R> {\n\tconst result = {} as MappedValues<T, R>;\n\n\tfor (const key of typedKeys(object)) {\n\t\tresult[key] = mapper(object[key], key, object);\n\t}\n\n\treturn result;\n}\n","/**\n * Creates a new object excluding the selected own enumerable properties.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\", role: \"admin\" } as const;\n *\n * omit(user, \"id\", \"name\"); // { role: \"admin\" }\n * omit(user, [\"role\"] as const); // { id: \"1\", name: \"Umsizi\" }\n * ```\n */\nexport function omit<T extends object, const Keys extends readonly (keyof T)[]>(\n\tobject: T,\n\t...keys: Keys\n): Omit<T, Keys[number]>;\nexport function omit<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tobject: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): Omit<T, FirstKey | RestKeys[number]>;\nexport function omit<T extends object>(\n\tobject: T,\n\tkeys: readonly (keyof T)[],\n): Partial<T>;\nexport function omit<T extends object>(\n\tobject: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): Partial<T> {\n\tconst keys = (\n\t\tArray.isArray(firstKeyOrKeys)\n\t\t\t? firstKeyOrKeys\n\t\t\t: [firstKeyOrKeys, ...restKeys]\n\t) as readonly (keyof T)[];\n\tconst omittedKeys = new Set<PropertyKey>(keys as readonly PropertyKey[]);\n\tconst result: Partial<T> = {};\n\n\tfor (const key of Reflect.ownKeys(object) as (keyof T)[]) {\n\t\tif (\n\t\t\tObject.prototype.propertyIsEnumerable.call(object, key) &&\n\t\t\t!omittedKeys.has(key)\n\t\t) {\n\t\t\t(result as T)[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import { hasOwn } from \"./has-own\";\n\n/**\n * Creates a new object containing only the selected own properties.\n *\n * Prefer the rest-key form for the strongest autocomplete and inference.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", name: \"Umsizi\", role: \"admin\" } as const;\n *\n * pick(user, \"name\"); // { name: \"Umsizi\" }\n * pick(user, [\"id\", \"role\"] as const); // { id: \"1\", role: \"admin\" }\n * ```\n */\nexport function pick<T extends object, const Keys extends readonly (keyof T)[]>(\n\tobject: T,\n\t...keys: Keys\n): Pick<T, Keys[number]>;\nexport function pick<\n\tT extends object,\n\tconst FirstKey extends keyof T,\n\tconst RestKeys extends readonly (keyof T)[],\n>(\n\tobject: T,\n\tkeys: readonly [FirstKey, ...RestKeys],\n): Pick<T, FirstKey | RestKeys[number]>;\nexport function pick<T extends object>(\n\tobject: T,\n\tkeys: readonly (keyof T)[],\n): Partial<T>;\nexport function pick<T extends object>(\n\tobject: T,\n\tfirstKeyOrKeys: keyof T | readonly (keyof T)[],\n\t...restKeys: readonly (keyof T)[]\n): Partial<T> {\n\tconst keys = (\n\t\tArray.isArray(firstKeyOrKeys)\n\t\t\t? firstKeyOrKeys\n\t\t\t: [firstKeyOrKeys, ...restKeys]\n\t) as readonly (keyof T)[];\n\tconst result: Partial<T> = {};\n\n\tfor (const key of keys) {\n\t\tif (hasOwn(object, key)) {\n\t\t\tresult[key] = object[key];\n\t\t}\n\t}\n\n\treturn result;\n}\n","import type { ObjectEntries } from \"./types\";\n\n/**\n * Returns the own enumerable string-keyed entries of an object with preserved\n * key/value pairing.\n *\n * This is a typed wrapper around `Object.entries`.\n *\n * @example\n * ```ts\n * const user = { id: \"1\", active: true } as const;\n *\n * typedEntries(user); // [[\"id\", \"1\"], [\"active\", true]]\n * ```\n */\nexport function typedEntries<T extends object>(object: T): ObjectEntries<T> {\n\treturn Object.entries(object) as unknown as ObjectEntries<T>;\n}\n","import type { EntryTuples, ObjectFromEntries } from \"./types\";\n\n/**\n * Creates an object from entries while preserving the key and value types from\n * the input tuple array.\n *\n * This is a typed wrapper around `Object.fromEntries`.\n *\n * @example\n * ```ts\n * const status = typedFromEntries([\n * [\"id\", \"1\"],\n * [\"active\", true],\n * ] as const);\n *\n * // inferred as: { id: \"1\"; active: true }\n * ```\n */\nexport function typedFromEntries<const T extends EntryTuples>(\n\tentries: T,\n): ObjectFromEntries<T> {\n\treturn Object.fromEntries(entries) as ObjectFromEntries<T>;\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAgB,UAA4B,QAAkC;AAC7E,QAAO,OAAO,KAAK,OAAO;;;;;;;;;;;;;;;;;ACA3B,SAAgB,cAAgC,QAA+B;CAC9E,MAAM,SAAS,EAAE;AAEjB,MAAK,MAAM,OAAO,UAAU,OAAO,EAAE;EACpC,MAAM,QAAQ,OAAO;AAErB,MAAI,SAAS,KACZ,QAAO,OAAO;;AAIhB,QAAO;;;;;ACDR,SAAgB,aACf,QACA,WACiD;CACjD,MAAM,SAAS,EAAE;AAEjB,MAAK,MAAM,OAAO,UAAU,OAAO,EAAE;EACpC,MAAM,QAAQ,OAAO;AAErB,MAAI,UAAU,OAAO,KAAK,OAAO,CAChC,QAAO,OAAO;;AAIhB,QAAO;;;;;;;;;;;;;;;;;;;;;ACvBR,SAAgB,OACf,QACA,KAC6B;AAC7B,QAAO,OAAO,OAAO,QAAQ,IAAI;;;;;;;;;;;;;;;;ACTlC,SAAgB,SAAY,OAAa;AACxC,QAAO;;;;;;;;;;;;;;;;;ACAR,SAAgB,QAAQ,QAAyB;AAChD,KAAI,OAAO,KAAK,OAAO,CAAC,SAAS,EAChC,QAAO;AAGR,MAAK,MAAM,OAAO,OAAO,sBAAsB,OAAO,CACrD,KAAI,OAAO,UAAU,qBAAqB,KAAK,QAAQ,IAAI,CAC1D,QAAO;AAIT,QAAO;;;;;;;;;;;;;;;;;ACRR,SAAgB,UACf,QACA,QACqB;CACrB,MAAM,SAAS,EAAE;AAEjB,MAAK,MAAM,OAAO,UAAU,OAAO,CAClC,QAAO,OAAO,OAAO,OAAO,MAAM,KAAK,OAAO;AAG/C,QAAO;;;;;ACIR,SAAgB,KACf,QACA,gBACA,GAAG,UACU;CACb,MAAM,OACL,MAAM,QAAQ,eAAe,GAC1B,iBACA,CAAC,gBAAgB,GAAG,SAAS;CAEjC,MAAM,cAAc,IAAI,IAAiB,KAA+B;CACxE,MAAMA,SAAqB,EAAE;AAE7B,MAAK,MAAM,OAAO,QAAQ,QAAQ,OAAO,CACxC,KACC,OAAO,UAAU,qBAAqB,KAAK,QAAQ,IAAI,IACvD,CAAC,YAAY,IAAI,IAAI,CAErB,CAAC,OAAa,OAAO,OAAO;AAI9B,QAAO;;;;;ACpBR,SAAgB,KACf,QACA,gBACA,GAAG,UACU;CACb,MAAM,OACL,MAAM,QAAQ,eAAe,GAC1B,iBACA,CAAC,gBAAgB,GAAG,SAAS;CAEjC,MAAMC,SAAqB,EAAE;AAE7B,MAAK,MAAM,OAAO,KACjB,KAAI,OAAO,QAAQ,IAAI,CACtB,QAAO,OAAO,OAAO;AAIvB,QAAO;;;;;;;;;;;;;;;;;;AClCR,SAAgB,aAA+B,QAA6B;AAC3E,QAAO,OAAO,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;ACE9B,SAAgB,iBACf,SACuB;AACvB,QAAO,OAAO,YAAY,QAAQ"}
package/dist/next.d.ts CHANGED
@@ -1,2 +1,23 @@
1
- import { t as normalizePathname } from "./index-rZiv1o95.js";
2
- export { normalizePathname };
1
+ //#region src/next/normalize-pathname.d.ts
2
+ /**
3
+ * Normalizes a path-like string for routing/comparison purposes.
4
+ *
5
+ * - Ensures a leading slash.
6
+ * - Collapses consecutive slashes into one.
7
+ * - Strips a trailing slash (except for the root path).
8
+ * - An empty string normalizes to `"/"`.
9
+ *
10
+ * Query strings and fragments are treated as opaque path characters and are
11
+ * not parsed or stripped — pass only the pathname segment of a URL.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * normalizePathname("dashboard"); // "/dashboard"
16
+ * normalizePathname("//dashboard///settings/"); // "/dashboard/settings"
17
+ * normalizePathname(""); // "/"
18
+ * ```
19
+ */
20
+ declare function normalizePathname(pathname: string): string;
21
+ //#endregion
22
+ export { normalizePathname };
23
+ //# sourceMappingURL=next.d.ts.map
package/dist/next.js CHANGED
@@ -1,3 +1,29 @@
1
- import { t as normalizePathname } from "./next-C3wp7UoQ.js";
1
+ //#region src/next/normalize-pathname.ts
2
+ /**
3
+ * Normalizes a path-like string for routing/comparison purposes.
4
+ *
5
+ * - Ensures a leading slash.
6
+ * - Collapses consecutive slashes into one.
7
+ * - Strips a trailing slash (except for the root path).
8
+ * - An empty string normalizes to `"/"`.
9
+ *
10
+ * Query strings and fragments are treated as opaque path characters and are
11
+ * not parsed or stripped — pass only the pathname segment of a URL.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * normalizePathname("dashboard"); // "/dashboard"
16
+ * normalizePathname("//dashboard///settings/"); // "/dashboard/settings"
17
+ * normalizePathname(""); // "/"
18
+ * ```
19
+ */
20
+ function normalizePathname(pathname) {
21
+ if (pathname === "") return "/";
22
+ const normalized = pathname.replace(/\/{2,}/g, "/").replace(/\/$/, "");
23
+ if (normalized === "") return "/";
24
+ return normalized.startsWith("/") ? normalized : `/${normalized}`;
25
+ }
2
26
 
3
- export { normalizePathname };
27
+ //#endregion
28
+ export { normalizePathname };
29
+ //# sourceMappingURL=next.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next.js","names":[],"sources":["../src/next/normalize-pathname.ts"],"sourcesContent":["/**\n * Normalizes a path-like string for routing/comparison purposes.\n *\n * - Ensures a leading slash.\n * - Collapses consecutive slashes into one.\n * - Strips a trailing slash (except for the root path).\n * - An empty string normalizes to `\"/\"`.\n *\n * Query strings and fragments are treated as opaque path characters and are\n * not parsed or stripped — pass only the pathname segment of a URL.\n *\n * @example\n * ```ts\n * normalizePathname(\"dashboard\"); // \"/dashboard\"\n * normalizePathname(\"//dashboard///settings/\"); // \"/dashboard/settings\"\n * normalizePathname(\"\"); // \"/\"\n * ```\n */\nexport function normalizePathname(pathname: string): string {\n\tif (pathname === \"\") {\n\t\treturn \"/\";\n\t}\n\n\tconst normalized = pathname.replace(/\\/{2,}/g, \"/\").replace(/\\/$/, \"\");\n\n\tif (normalized === \"\") {\n\t\treturn \"/\";\n\t}\n\n\treturn normalized.startsWith(\"/\") ? normalized : `/${normalized}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBAAkB,UAA0B;AAC3D,KAAI,aAAa,GAChB,QAAO;CAGR,MAAM,aAAa,SAAS,QAAQ,WAAW,IAAI,CAAC,QAAQ,OAAO,GAAG;AAEtE,KAAI,eAAe,GAClB,QAAO;AAGR,QAAO,WAAW,WAAW,IAAI,GAAG,aAAa,IAAI"}
package/dist/node.d.ts CHANGED
@@ -1,2 +1,19 @@
1
- import { t as hasFileExtension } from "./index-DtjbEW43.js";
2
- export { hasFileExtension };
1
+ //#region src/node/has-file-extension.d.ts
2
+ /**
3
+ * Checks whether a file path ends with the given extension.
4
+ *
5
+ * The leading dot on `extension` is optional — both `"ts"` and `".ts"` are
6
+ * accepted. The comparison is case-sensitive and is a plain `endsWith`
7
+ * check, so it does not validate that `filePath` is a well-formed path.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * hasFileExtension("src/index.ts", ".ts"); // true
12
+ * hasFileExtension("package.json", "json"); // true
13
+ * hasFileExtension("README.md", "ts"); // false
14
+ * ```
15
+ */
16
+ declare function hasFileExtension(filePath: string, extension: string): boolean;
17
+ //#endregion
18
+ export { hasFileExtension };
19
+ //# sourceMappingURL=node.d.ts.map
package/dist/node.js CHANGED
@@ -1,3 +1,23 @@
1
- import { t as hasFileExtension } from "./node-D-nlzpmG.js";
1
+ //#region src/node/has-file-extension.ts
2
+ /**
3
+ * Checks whether a file path ends with the given extension.
4
+ *
5
+ * The leading dot on `extension` is optional — both `"ts"` and `".ts"` are
6
+ * accepted. The comparison is case-sensitive and is a plain `endsWith`
7
+ * check, so it does not validate that `filePath` is a well-formed path.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * hasFileExtension("src/index.ts", ".ts"); // true
12
+ * hasFileExtension("package.json", "json"); // true
13
+ * hasFileExtension("README.md", "ts"); // false
14
+ * ```
15
+ */
16
+ function hasFileExtension(filePath, extension) {
17
+ const normalizedExtension = extension.startsWith(".") ? extension : `.${extension}`;
18
+ return filePath.endsWith(normalizedExtension);
19
+ }
2
20
 
3
- export { hasFileExtension };
21
+ //#endregion
22
+ export { hasFileExtension };
23
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","names":[],"sources":["../src/node/has-file-extension.ts"],"sourcesContent":["/**\n * Checks whether a file path ends with the given extension.\n *\n * The leading dot on `extension` is optional — both `\"ts\"` and `\".ts\"` are\n * accepted. The comparison is case-sensitive and is a plain `endsWith`\n * check, so it does not validate that `filePath` is a well-formed path.\n *\n * @example\n * ```ts\n * hasFileExtension(\"src/index.ts\", \".ts\"); // true\n * hasFileExtension(\"package.json\", \"json\"); // true\n * hasFileExtension(\"README.md\", \"ts\"); // false\n * ```\n */\nexport function hasFileExtension(filePath: string, extension: string): boolean {\n\tconst normalizedExtension = extension.startsWith(\".\")\n\t\t? extension\n\t\t: `.${extension}`;\n\n\treturn filePath.endsWith(normalizedExtension);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,iBAAiB,UAAkB,WAA4B;CAC9E,MAAM,sBAAsB,UAAU,WAAW,IAAI,GAClD,YACA,IAAI;AAEP,QAAO,SAAS,SAAS,oBAAoB"}
package/dist/react.d.ts CHANGED
@@ -1,2 +1,22 @@
1
- import { t as isRenderFunction } from "./index-dktuz4mv.js";
2
- export { isRenderFunction };
1
+ //#region src/react/is-render-function.d.ts
2
+ /**
3
+ * Type guard for values that are callable in render-oriented code paths
4
+ * (e.g. `children` passed as a render prop).
5
+ *
6
+ * Matches any callable value, including async functions, generator
7
+ * functions, and class constructors — it does not distinguish between
8
+ * function kinds, only "is this safe to call as a function".
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const children: unknown = () => "ready";
13
+ *
14
+ * if (isRenderFunction(children)) {
15
+ * children();
16
+ * }
17
+ * ```
18
+ */
19
+ declare function isRenderFunction(value: unknown): value is (...args: readonly unknown[]) => unknown;
20
+ //#endregion
21
+ export { isRenderFunction };
22
+ //# sourceMappingURL=react.d.ts.map
package/dist/react.js CHANGED
@@ -1,3 +1,25 @@
1
- import { t as isRenderFunction } from "./react-BCidSnzT.js";
1
+ //#region src/react/is-render-function.ts
2
+ /**
3
+ * Type guard for values that are callable in render-oriented code paths
4
+ * (e.g. `children` passed as a render prop).
5
+ *
6
+ * Matches any callable value, including async functions, generator
7
+ * functions, and class constructors — it does not distinguish between
8
+ * function kinds, only "is this safe to call as a function".
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const children: unknown = () => "ready";
13
+ *
14
+ * if (isRenderFunction(children)) {
15
+ * children();
16
+ * }
17
+ * ```
18
+ */
19
+ function isRenderFunction(value) {
20
+ return typeof value === "function";
21
+ }
2
22
 
3
- export { isRenderFunction };
23
+ //#endregion
24
+ export { isRenderFunction };
25
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","names":[],"sources":["../src/react/is-render-function.ts"],"sourcesContent":["/**\n * Type guard for values that are callable in render-oriented code paths\n * (e.g. `children` passed as a render prop).\n *\n * Matches any callable value, including async functions, generator\n * functions, and class constructors — it does not distinguish between\n * function kinds, only \"is this safe to call as a function\".\n *\n * @example\n * ```ts\n * const children: unknown = () => \"ready\";\n *\n * if (isRenderFunction(children)) {\n * children();\n * }\n * ```\n */\nexport function isRenderFunction(\n\tvalue: unknown,\n): value is (...args: readonly unknown[]) => unknown {\n\treturn typeof value === \"function\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,iBACf,OACoD;AACpD,QAAO,OAAO,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "umsizi",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "A zero-dependency TypeScript utility library.",
5
5
  "license": "MIT",
6
6
  "author": "Jack-WebDev",
@@ -92,7 +92,7 @@
92
92
  ],
93
93
  "scripts": {
94
94
  "build": "tsdown",
95
- "ci": "pnpm run lint && pnpm run check-types && pnpm run test:coverage && pnpm run build && pnpm exec size-limit && pnpm run check:package",
95
+ "ci": "pnpm run lint && pnpm run check-types && pnpm run check-types:examples && pnpm run test:coverage && pnpm run build && pnpm exec size-limit && pnpm run check:package",
96
96
  "check:package": "pnpm run check:package:npm && pnpm run check:package:jsr",
97
97
  "check:package:jsr": "pnpm dlx jsr publish --dry-run --allow-dirty",
98
98
  "check:package:npm": "HUSKY=0 npm_config_cache=/tmp/umsizi-npm-cache npm pack --dry-run --ignore-scripts",
@@ -101,6 +101,7 @@
101
101
  "lint": "biome check .",
102
102
  "lint:fix": "biome check --write .",
103
103
  "check-types": "tsc --noEmit",
104
+ "check-types:examples": "tsc --noEmit --project tsconfig.json --pretty false",
104
105
  "release:publish": "pnpm run build && pnpm exec changeset publish && pnpm dlx jsr publish --allow-dirty",
105
106
  "release:version": "pnpm exec changeset version && node ./scripts/sync-release-version.mjs",
106
107
  "test": "vitest run",
@@ -1,19 +0,0 @@
1
- //#region src/node/has-file-extension.d.ts
2
- /**
3
- * Checks whether a file path ends with the given extension.
4
- *
5
- * The leading dot on `extension` is optional — both `"ts"` and `".ts"` are
6
- * accepted. The comparison is case-sensitive and is a plain `endsWith`
7
- * check, so it does not validate that `filePath` is a well-formed path.
8
- *
9
- * @example
10
- * ```ts
11
- * hasFileExtension("src/index.ts", ".ts"); // true
12
- * hasFileExtension("package.json", "json"); // true
13
- * hasFileExtension("README.md", "ts"); // false
14
- * ```
15
- */
16
- declare function hasFileExtension(filePath: string, extension: string): boolean;
17
- //#endregion
18
- export { hasFileExtension as t };
19
- //# sourceMappingURL=index-DtjbEW43.d.ts.map
@@ -1,22 +0,0 @@
1
- //#region src/react/is-render-function.d.ts
2
- /**
3
- * Type guard for values that are callable in render-oriented code paths
4
- * (e.g. `children` passed as a render prop).
5
- *
6
- * Matches any callable value, including async functions, generator
7
- * functions, and class constructors — it does not distinguish between
8
- * function kinds, only "is this safe to call as a function".
9
- *
10
- * @example
11
- * ```ts
12
- * const children: unknown = () => "ready";
13
- *
14
- * if (isRenderFunction(children)) {
15
- * children();
16
- * }
17
- * ```
18
- */
19
- declare function isRenderFunction(value: unknown): value is (...args: readonly unknown[]) => unknown;
20
- //#endregion
21
- export { isRenderFunction as t };
22
- //# sourceMappingURL=index-dktuz4mv.d.ts.map
@@ -1,23 +0,0 @@
1
- //#region src/next/normalize-pathname.d.ts
2
- /**
3
- * Normalizes a path-like string for routing/comparison purposes.
4
- *
5
- * - Ensures a leading slash.
6
- * - Collapses consecutive slashes into one.
7
- * - Strips a trailing slash (except for the root path).
8
- * - An empty string normalizes to `"/"`.
9
- *
10
- * Query strings and fragments are treated as opaque path characters and are
11
- * not parsed or stripped — pass only the pathname segment of a URL.
12
- *
13
- * @example
14
- * ```ts
15
- * normalizePathname("dashboard"); // "/dashboard"
16
- * normalizePathname("//dashboard///settings/"); // "/dashboard/settings"
17
- * normalizePathname(""); // "/"
18
- * ```
19
- */
20
- declare function normalizePathname(pathname: string): string;
21
- //#endregion
22
- export { normalizePathname as t };
23
- //# sourceMappingURL=index-rZiv1o95.d.ts.map
@@ -1,29 +0,0 @@
1
- //#region src/next/normalize-pathname.ts
2
- /**
3
- * Normalizes a path-like string for routing/comparison purposes.
4
- *
5
- * - Ensures a leading slash.
6
- * - Collapses consecutive slashes into one.
7
- * - Strips a trailing slash (except for the root path).
8
- * - An empty string normalizes to `"/"`.
9
- *
10
- * Query strings and fragments are treated as opaque path characters and are
11
- * not parsed or stripped — pass only the pathname segment of a URL.
12
- *
13
- * @example
14
- * ```ts
15
- * normalizePathname("dashboard"); // "/dashboard"
16
- * normalizePathname("//dashboard///settings/"); // "/dashboard/settings"
17
- * normalizePathname(""); // "/"
18
- * ```
19
- */
20
- function normalizePathname(pathname) {
21
- if (pathname === "") return "/";
22
- const normalized = pathname.replace(/\/{2,}/g, "/").replace(/\/$/, "");
23
- if (normalized === "") return "/";
24
- return normalized.startsWith("/") ? normalized : `/${normalized}`;
25
- }
26
-
27
- //#endregion
28
- export { normalizePathname as t };
29
- //# sourceMappingURL=next-C3wp7UoQ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"next-C3wp7UoQ.js","names":[],"sources":["../src/next/normalize-pathname.ts"],"sourcesContent":["/**\n * Normalizes a path-like string for routing/comparison purposes.\n *\n * - Ensures a leading slash.\n * - Collapses consecutive slashes into one.\n * - Strips a trailing slash (except for the root path).\n * - An empty string normalizes to `\"/\"`.\n *\n * Query strings and fragments are treated as opaque path characters and are\n * not parsed or stripped — pass only the pathname segment of a URL.\n *\n * @example\n * ```ts\n * normalizePathname(\"dashboard\"); // \"/dashboard\"\n * normalizePathname(\"//dashboard///settings/\"); // \"/dashboard/settings\"\n * normalizePathname(\"\"); // \"/\"\n * ```\n */\nexport function normalizePathname(pathname: string): string {\n\tif (pathname === \"\") {\n\t\treturn \"/\";\n\t}\n\n\tconst normalized = pathname.replace(/\\/{2,}/g, \"/\").replace(/\\/$/, \"\");\n\n\tif (normalized === \"\") {\n\t\treturn \"/\";\n\t}\n\n\treturn normalized.startsWith(\"/\") ? normalized : `/${normalized}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,kBAAkB,UAA0B;AAC3D,KAAI,aAAa,GAChB,QAAO;CAGR,MAAM,aAAa,SAAS,QAAQ,WAAW,IAAI,CAAC,QAAQ,OAAO,GAAG;AAEtE,KAAI,eAAe,GAClB,QAAO;AAGR,QAAO,WAAW,WAAW,IAAI,GAAG,aAAa,IAAI"}
@@ -1,23 +0,0 @@
1
- //#region src/node/has-file-extension.ts
2
- /**
3
- * Checks whether a file path ends with the given extension.
4
- *
5
- * The leading dot on `extension` is optional — both `"ts"` and `".ts"` are
6
- * accepted. The comparison is case-sensitive and is a plain `endsWith`
7
- * check, so it does not validate that `filePath` is a well-formed path.
8
- *
9
- * @example
10
- * ```ts
11
- * hasFileExtension("src/index.ts", ".ts"); // true
12
- * hasFileExtension("package.json", "json"); // true
13
- * hasFileExtension("README.md", "ts"); // false
14
- * ```
15
- */
16
- function hasFileExtension(filePath, extension) {
17
- const normalizedExtension = extension.startsWith(".") ? extension : `.${extension}`;
18
- return filePath.endsWith(normalizedExtension);
19
- }
20
-
21
- //#endregion
22
- export { hasFileExtension as t };
23
- //# sourceMappingURL=node-D-nlzpmG.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node-D-nlzpmG.js","names":[],"sources":["../src/node/has-file-extension.ts"],"sourcesContent":["/**\n * Checks whether a file path ends with the given extension.\n *\n * The leading dot on `extension` is optional — both `\"ts\"` and `\".ts\"` are\n * accepted. The comparison is case-sensitive and is a plain `endsWith`\n * check, so it does not validate that `filePath` is a well-formed path.\n *\n * @example\n * ```ts\n * hasFileExtension(\"src/index.ts\", \".ts\"); // true\n * hasFileExtension(\"package.json\", \"json\"); // true\n * hasFileExtension(\"README.md\", \"ts\"); // false\n * ```\n */\nexport function hasFileExtension(filePath: string, extension: string): boolean {\n\tconst normalizedExtension = extension.startsWith(\".\")\n\t\t? extension\n\t\t: `.${extension}`;\n\n\treturn filePath.endsWith(normalizedExtension);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAcA,SAAgB,iBAAiB,UAAkB,WAA4B;CAC9E,MAAM,sBAAsB,UAAU,WAAW,IAAI,GAClD,YACA,IAAI;AAEP,QAAO,SAAS,SAAS,oBAAoB"}
@@ -1,25 +0,0 @@
1
- //#region src/react/is-render-function.ts
2
- /**
3
- * Type guard for values that are callable in render-oriented code paths
4
- * (e.g. `children` passed as a render prop).
5
- *
6
- * Matches any callable value, including async functions, generator
7
- * functions, and class constructors — it does not distinguish between
8
- * function kinds, only "is this safe to call as a function".
9
- *
10
- * @example
11
- * ```ts
12
- * const children: unknown = () => "ready";
13
- *
14
- * if (isRenderFunction(children)) {
15
- * children();
16
- * }
17
- * ```
18
- */
19
- function isRenderFunction(value) {
20
- return typeof value === "function";
21
- }
22
-
23
- //#endregion
24
- export { isRenderFunction as t };
25
- //# sourceMappingURL=react-BCidSnzT.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react-BCidSnzT.js","names":[],"sources":["../src/react/is-render-function.ts"],"sourcesContent":["/**\n * Type guard for values that are callable in render-oriented code paths\n * (e.g. `children` passed as a render prop).\n *\n * Matches any callable value, including async functions, generator\n * functions, and class constructors — it does not distinguish between\n * function kinds, only \"is this safe to call as a function\".\n *\n * @example\n * ```ts\n * const children: unknown = () => \"ready\";\n *\n * if (isRenderFunction(children)) {\n * children();\n * }\n * ```\n */\nexport function isRenderFunction(\n\tvalue: unknown,\n): value is (...args: readonly unknown[]) => unknown {\n\treturn typeof value === \"function\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,SAAgB,iBACf,OACoD;AACpD,QAAO,OAAO,UAAU"}