@neovici/cosmoz-utils 6.20.1 → 6.21.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/dist/location.d.ts +3 -1
- package/dist/location.js +4 -2
- package/dist/object.d.ts +1 -1
- package/dist/object.js +1 -1
- package/package.json +1 -1
package/dist/location.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export declare const hashUrl: () => URL
|
|
1
|
+
export declare const hashUrl: () => URL;
|
|
2
|
+
export declare const singleParse: <T = string>(hashParam: string, codec?: (value: string) => T) => T | T[] | undefined;
|
|
3
|
+
export declare const multiParse: <T = string>(hashParam: string, codec?: (entry: [string, string]) => [string, T]) => Record<string, T>;
|
package/dist/location.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { identity } from './function';
|
|
2
|
-
export const hashUrl = () => new URL(location.hash.replace(/^#!?/iu, '').replace('%23', '#'), location.origin)
|
|
2
|
+
export const hashUrl = () => new URL(location.hash.replace(/^#!?/iu, '').replace('%23', '#'), location.origin);
|
|
3
|
+
export const singleParse = (hashParam, codec = identity) => {
|
|
3
4
|
const values = new URLSearchParams(hashUrl().hash.replace('#', '')).getAll(hashParam);
|
|
4
5
|
switch (values.length) {
|
|
5
6
|
case 0:
|
|
@@ -9,7 +10,8 @@ export const hashUrl = () => new URL(location.hash.replace(/^#!?/iu, '').replace
|
|
|
9
10
|
default:
|
|
10
11
|
return values.map(codec);
|
|
11
12
|
}
|
|
12
|
-
}
|
|
13
|
+
};
|
|
14
|
+
export const multiParse = (hashParam, codec = identity) => {
|
|
13
15
|
const params = Array.from(new URLSearchParams(hashUrl().hash.replace('#', '')).entries())
|
|
14
16
|
.filter(([param]) => param.startsWith(hashParam))
|
|
15
17
|
.map(([param, value]) => codec([param.replace(hashParam, ''), value]))
|
package/dist/object.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { identity } from './function';
|
|
|
2
2
|
export type Rec<K extends PropertyKey = PropertyKey, V = any> = Record<K, V>;
|
|
3
3
|
export declare function prop(): typeof identity;
|
|
4
4
|
export declare function prop(a: '' | null | false | undefined | 0): typeof identity;
|
|
5
|
-
export declare function prop<K extends PropertyKey>(key?: K): <O>(obj: O) => K extends keyof O ? O[K] : undefined;
|
|
5
|
+
export declare function prop<K extends PropertyKey>(key?: K): <O>(obj: O) => O extends object ? (K extends keyof O ? O[K] : undefined) : O;
|
|
6
6
|
export declare const strProp: <K extends PropertyKey>(key?: K) => <O>(o: O) => string;
|
|
7
7
|
export declare const transform: <K extends string, V, RK extends PropertyKey, RV>(obj: Record<K, V>, trans: (entries: [Extract<K, string>, V][]) => Iterable<readonly [RK, RV]>) => { [key in RK]: RV; };
|
|
8
8
|
export declare const omit: <const K extends readonly PropertyKey[]>(keys: K) => <const T extends Rec>(obj: T) => Omit<T, K[number]>;
|
package/dist/object.js
CHANGED