@koine/utils 1.0.26 → 1.0.29

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 (345) hide show
  1. package/{async.d.ts → Defer.d.ts} +5 -5
  2. package/{async.js → Defer.js} +2 -7
  3. package/{emitter.d.ts → Emitter.d.ts} +1 -0
  4. package/{emitter.js → Emitter.js} +1 -0
  5. package/accentSets.d.ts +16 -0
  6. package/accentSets.js +38 -0
  7. package/addOrReplaceAtIdx.d.ts +5 -0
  8. package/addOrReplaceAtIdx.js +19 -0
  9. package/arrayToLookup.d.ts +7 -0
  10. package/arrayToLookup.js +13 -0
  11. package/buildUrlQueryString.d.ts +12 -0
  12. package/buildUrlQueryString.js +24 -0
  13. package/changeUrlPath.d.ts +10 -0
  14. package/changeUrlPath.js +18 -0
  15. package/chunkByChunks.d.ts +7 -0
  16. package/chunkByChunks.js +37 -0
  17. package/chunkBySize.d.ts +6 -0
  18. package/chunkBySize.js +12 -0
  19. package/clamp.d.ts +8 -0
  20. package/clamp.js +10 -0
  21. package/clsx.d.ts +9 -0
  22. package/clsx.js +49 -0
  23. package/convertRange.d.ts +14 -0
  24. package/convertRange.js +16 -0
  25. package/cookie.d.ts +7 -26
  26. package/cookie.js +3 -221
  27. package/decode.d.ts +6 -0
  28. package/decode.js +10 -0
  29. package/encode.d.ts +6 -0
  30. package/encode.js +10 -0
  31. package/{cast.d.ts → ensureInt.d.ts} +3 -1
  32. package/{cast.js → ensureInt.js} +3 -4
  33. package/findDuplicatedIndexes.d.ts +5 -0
  34. package/findDuplicatedIndexes.js +14 -0
  35. package/getKeys.d.ts +9 -0
  36. package/getKeys.js +9 -0
  37. package/getNonce.d.ts +6 -0
  38. package/getNonce.js +9 -0
  39. package/getType.d.ts +22 -0
  40. package/getType.js +19 -0
  41. package/getUrlHashParams.d.ts +9 -0
  42. package/getUrlHashParams.js +16 -0
  43. package/getUrlHashPathname.d.ts +9 -0
  44. package/getUrlHashPathname.js +13 -0
  45. package/getUrlPathnameParts.d.ts +12 -0
  46. package/getUrlPathnameParts.js +20 -0
  47. package/getUrlQueryParams.d.ts +14 -0
  48. package/getUrlQueryParams.js +38 -0
  49. package/index.d.ts +107 -15
  50. package/index.js +108 -16
  51. package/isAnyObject.d.ts +8 -0
  52. package/isAnyObject.js +10 -0
  53. package/isArray.d.ts +7 -0
  54. package/isArray.js +10 -0
  55. package/isBlob.d.ts +7 -0
  56. package/isBlob.js +10 -0
  57. package/isBoolean.d.ts +7 -0
  58. package/isBoolean.js +10 -0
  59. package/isBrowser.d.ts +6 -0
  60. package/{ssr.js → isBrowser.js} +5 -2
  61. package/isDate.d.ts +7 -0
  62. package/isDate.js +10 -0
  63. package/isEmptyArray.d.ts +7 -0
  64. package/isEmptyArray.js +10 -0
  65. package/isEmptyObject.d.ts +9 -0
  66. package/isEmptyObject.js +10 -0
  67. package/isEmptyString.d.ts +7 -0
  68. package/isEmptyString.js +9 -0
  69. package/isError.d.ts +7 -0
  70. package/isError.js +10 -0
  71. package/isExternalUrl.d.ts +9 -0
  72. package/isExternalUrl.js +21 -0
  73. package/isFile.d.ts +7 -0
  74. package/isFile.js +10 -0
  75. package/isFloat.d.ts +7 -0
  76. package/isFloat.js +10 -0
  77. package/isFormData.d.ts +7 -0
  78. package/isFormData.js +10 -0
  79. package/isFullArray.d.ts +7 -0
  80. package/isFullArray.js +10 -0
  81. package/isFullObject.d.ts +8 -0
  82. package/isFullObject.js +10 -0
  83. package/isFullString.d.ts +7 -0
  84. package/isFullString.js +10 -0
  85. package/isFunction.d.ts +8 -0
  86. package/isFunction.js +9 -0
  87. package/{detect.d.ts → isIE.d.ts} +3 -4
  88. package/isIE.js +18 -0
  89. package/isInt.d.ts +7 -0
  90. package/isInt.js +10 -0
  91. package/isMap.d.ts +7 -0
  92. package/isMap.js +10 -0
  93. package/isMobile.d.ts +7 -0
  94. package/{detect.js → isMobile.js} +4 -15
  95. package/isNaNValue.d.ts +7 -0
  96. package/isNaNValue.js +10 -0
  97. package/isNegativeNumber.d.ts +7 -0
  98. package/isNegativeNumber.js +10 -0
  99. package/isNull.d.ts +7 -0
  100. package/isNull.js +10 -0
  101. package/isNullOrUndefined.d.ts +7 -0
  102. package/isNullOrUndefined.js +10 -0
  103. package/isNumber.d.ts +9 -0
  104. package/isNumber.js +12 -0
  105. package/isObject.d.ts +8 -0
  106. package/isObject.js +10 -0
  107. package/isObjectLike.d.ts +10 -0
  108. package/isObjectLike.js +12 -0
  109. package/isOneOf.d.ts +9 -0
  110. package/isOneOf.js +10 -0
  111. package/isPlainObject.d.ts +8 -0
  112. package/isPlainObject.js +13 -0
  113. package/isPositiveNumber.d.ts +7 -0
  114. package/isPositiveNumber.js +10 -0
  115. package/isPrimitive.d.ts +7 -0
  116. package/isPrimitive.js +20 -0
  117. package/isPromise.d.ts +7 -0
  118. package/isPromise.js +10 -0
  119. package/isRegExp.d.ts +7 -0
  120. package/isRegExp.js +10 -0
  121. package/isServer.d.ts +6 -0
  122. package/isServer.js +8 -0
  123. package/isSet.d.ts +7 -0
  124. package/isSet.js +10 -0
  125. package/isString.d.ts +7 -0
  126. package/isString.js +10 -0
  127. package/isSymbol.d.ts +7 -0
  128. package/isSymbol.js +10 -0
  129. package/isType.d.ts +11 -0
  130. package/isType.js +22 -0
  131. package/isUndefined.d.ts +7 -0
  132. package/isUndefined.js +10 -0
  133. package/isWeakMap.d.ts +7 -0
  134. package/isWeakMap.js +10 -0
  135. package/isWeakSet.d.ts +7 -0
  136. package/isWeakSet.js +10 -0
  137. package/location.d.ts +2 -145
  138. package/location.js +1 -299
  139. package/mapListBy.d.ts +7 -0
  140. package/mapListBy.js +14 -0
  141. package/{match-sorter.d.ts → matchSorter.d.ts} +1 -0
  142. package/{match-sorter.js → matchSorter.js} +2 -1
  143. package/mergeObjects.d.ts +7 -0
  144. package/{objects.js → mergeObjects.js} +2 -31
  145. package/mergeUrlQueryParams.d.ts +9 -0
  146. package/mergeUrlQueryParams.js +22 -0
  147. package/navigateToHashParams.d.ts +9 -0
  148. package/navigateToHashParams.js +22 -0
  149. package/navigateToMergedHashParams.d.ts +8 -0
  150. package/navigateToMergedHashParams.js +14 -0
  151. package/navigateToMergedParams.d.ts +9 -0
  152. package/navigateToMergedParams.js +14 -0
  153. package/navigateToParams.d.ts +10 -0
  154. package/navigateToParams.js +18 -0
  155. package/navigateWithoutUrlParam.d.ts +8 -0
  156. package/navigateWithoutUrlParam.js +19 -0
  157. package/node/{async.js → Defer.js} +3 -9
  158. package/node/{emitter.js → Emitter.js} +1 -0
  159. package/node/accentSets.js +41 -0
  160. package/node/addOrReplaceAtIdx.js +23 -0
  161. package/node/arrayToLookup.js +17 -0
  162. package/node/buildUrlQueryString.js +28 -0
  163. package/node/changeUrlPath.js +22 -0
  164. package/node/chunkByChunks.js +41 -0
  165. package/node/chunkBySize.js +16 -0
  166. package/node/clamp.js +14 -0
  167. package/node/clsx.js +53 -0
  168. package/node/convertRange.js +20 -0
  169. package/node/cookie.js +4 -227
  170. package/node/decode.js +14 -0
  171. package/node/encode.js +14 -0
  172. package/node/{cast.js → ensureInt.js} +4 -6
  173. package/node/findDuplicatedIndexes.js +18 -0
  174. package/node/getKeys.js +12 -0
  175. package/node/getNonce.js +13 -0
  176. package/node/getType.js +23 -0
  177. package/node/getUrlHashParams.js +20 -0
  178. package/node/getUrlHashPathname.js +17 -0
  179. package/node/getUrlPathnameParts.js +24 -0
  180. package/node/getUrlQueryParams.js +42 -0
  181. package/node/index.js +108 -16
  182. package/node/isAnyObject.js +14 -0
  183. package/node/isArray.js +14 -0
  184. package/node/isBlob.js +14 -0
  185. package/node/isBoolean.js +14 -0
  186. package/node/{ssr.js → isBrowser.js} +6 -3
  187. package/node/isDate.js +14 -0
  188. package/node/isEmptyArray.js +14 -0
  189. package/node/isEmptyObject.js +14 -0
  190. package/node/isEmptyString.js +13 -0
  191. package/node/isError.js +14 -0
  192. package/node/isExternalUrl.js +25 -0
  193. package/node/isFile.js +14 -0
  194. package/node/isFloat.js +14 -0
  195. package/node/isFormData.js +14 -0
  196. package/node/isFullArray.js +14 -0
  197. package/node/isFullObject.js +14 -0
  198. package/node/isFullString.js +14 -0
  199. package/node/isFunction.js +13 -0
  200. package/node/isIE.js +22 -0
  201. package/node/isInt.js +14 -0
  202. package/node/isMap.js +14 -0
  203. package/node/{detect.js → isMobile.js} +6 -18
  204. package/node/isNaNValue.js +14 -0
  205. package/node/isNegativeNumber.js +14 -0
  206. package/node/isNull.js +14 -0
  207. package/node/isNullOrUndefined.js +13 -0
  208. package/node/isNumber.js +16 -0
  209. package/node/isObject.js +14 -0
  210. package/node/isObjectLike.js +16 -0
  211. package/node/isOneOf.js +14 -0
  212. package/node/isPlainObject.js +17 -0
  213. package/node/isPositiveNumber.js +14 -0
  214. package/node/isPrimitive.js +24 -0
  215. package/node/isPromise.js +14 -0
  216. package/node/isRegExp.js +14 -0
  217. package/node/isServer.js +11 -0
  218. package/node/isSet.js +14 -0
  219. package/node/isString.js +14 -0
  220. package/node/isSymbol.js +14 -0
  221. package/node/isType.js +26 -0
  222. package/node/isUndefined.js +14 -0
  223. package/node/isWeakMap.js +14 -0
  224. package/node/isWeakSet.js +14 -0
  225. package/node/location.js +0 -321
  226. package/node/mapListBy.js +18 -0
  227. package/node/{match-sorter.js → matchSorter.js} +3 -2
  228. package/node/{objects.js → mergeObjects.js} +5 -36
  229. package/node/mergeUrlQueryParams.js +26 -0
  230. package/node/navigateToHashParams.js +26 -0
  231. package/node/navigateToMergedHashParams.js +18 -0
  232. package/node/navigateToMergedParams.js +18 -0
  233. package/node/navigateToParams.js +22 -0
  234. package/node/navigateWithoutUrlParam.js +23 -0
  235. package/node/normaliseUrl.js +18 -0
  236. package/node/normaliseUrlPathname.js +18 -0
  237. package/node/{analytics-google.js → pageview.js} +12 -10
  238. package/node/parseCookie.js +52 -0
  239. package/node/parseURL.js +24 -0
  240. package/node/randomInt.js +13 -0
  241. package/node/{misc.js → randomKey.js} +2 -0
  242. package/node/readCookie.js +38 -0
  243. package/node/redirectTo.js +19 -0
  244. package/node/removeAccents.js +19 -0
  245. package/node/removeCookie.js +19 -0
  246. package/node/removeDuplicatesByKey.js +25 -0
  247. package/node/removeDuplicatesComparing.js +14 -0
  248. package/node/removeIndexesFromArray.js +18 -0
  249. package/node/removeTrailingSlash.js +14 -0
  250. package/node/{math.js → roundTo.js} +3 -32
  251. package/node/serializeCookie.js +108 -0
  252. package/node/setCookie.js +61 -0
  253. package/node/shuffle.js +36 -0
  254. package/node/slugify.js +27 -0
  255. package/node/swapMap.js +18 -0
  256. package/node/{typography.js → titleCase.js} +3 -12
  257. package/node/toNumber.js +12 -0
  258. package/node/{colors.js → toRgba.js} +4 -0
  259. package/node/transformToUrlPathname.js +20 -0
  260. package/node/truncate.js +17 -0
  261. package/node/uid.js +4 -13
  262. package/node/updateLinkParams.js +18 -0
  263. package/node/updateUrlQueryParams.js +22 -0
  264. package/node/uuid.js +17 -0
  265. package/node/wait.js +13 -0
  266. package/node/whitelistObject.js +19 -0
  267. package/normaliseUrl.d.ts +10 -0
  268. package/normaliseUrl.js +14 -0
  269. package/normaliseUrlPathname.d.ts +10 -0
  270. package/normaliseUrlPathname.js +14 -0
  271. package/package.json +1 -1
  272. package/{analytics-google.d.ts → pageview.d.ts} +3 -0
  273. package/{analytics-google.js → pageview.js} +12 -10
  274. package/parseCookie.d.ts +11 -0
  275. package/parseCookie.js +48 -0
  276. package/parseURL.d.ts +17 -0
  277. package/parseURL.js +20 -0
  278. package/randomInt.d.ts +7 -0
  279. package/randomInt.js +9 -0
  280. package/{misc.d.ts → randomKey.d.ts} +2 -0
  281. package/{misc.js → randomKey.js} +2 -0
  282. package/readCookie.d.ts +3 -0
  283. package/readCookie.js +34 -0
  284. package/redirectTo.d.ts +9 -0
  285. package/redirectTo.js +15 -0
  286. package/removeAccents.d.ts +6 -0
  287. package/removeAccents.js +15 -0
  288. package/removeCookie.d.ts +10 -0
  289. package/removeCookie.js +15 -0
  290. package/removeDuplicatesByKey.d.ts +8 -0
  291. package/removeDuplicatesByKey.js +21 -0
  292. package/removeDuplicatesComparing.d.ts +5 -0
  293. package/removeDuplicatesComparing.js +10 -0
  294. package/removeIndexesFromArray.d.ts +5 -0
  295. package/removeIndexesFromArray.js +14 -0
  296. package/removeTrailingSlash.d.ts +7 -0
  297. package/removeTrailingSlash.js +10 -0
  298. package/roundTo.d.ts +8 -0
  299. package/{math.js → roundTo.js} +2 -28
  300. package/serializeCookie.d.ts +27 -0
  301. package/serializeCookie.js +104 -0
  302. package/setCookie.d.ts +10 -0
  303. package/setCookie.js +57 -0
  304. package/shuffle.d.ts +16 -0
  305. package/shuffle.js +32 -0
  306. package/{text.d.ts → slugify.d.ts} +2 -5
  307. package/slugify.js +23 -0
  308. package/swapMap.d.ts +7 -0
  309. package/swapMap.js +14 -0
  310. package/{typography.d.ts → titleCase.d.ts} +2 -4
  311. package/{typography.js → titleCase.js} +2 -10
  312. package/toNumber.d.ts +5 -0
  313. package/toNumber.js +8 -0
  314. package/{colors.d.ts → toRgba.d.ts} +4 -0
  315. package/{colors.js → toRgba.js} +4 -0
  316. package/transformToUrlPathname.d.ts +11 -0
  317. package/transformToUrlPathname.js +16 -0
  318. package/truncate.d.ts +7 -0
  319. package/truncate.js +13 -0
  320. package/uid.d.ts +3 -6
  321. package/uid.js +3 -11
  322. package/updateLinkParams.d.ts +10 -0
  323. package/updateLinkParams.js +14 -0
  324. package/updateUrlQueryParams.d.ts +9 -0
  325. package/updateUrlQueryParams.js +18 -0
  326. package/uuid.d.ts +8 -0
  327. package/uuid.js +13 -0
  328. package/wait.d.ts +7 -0
  329. package/wait.js +9 -0
  330. package/whitelistObject.d.ts +8 -0
  331. package/whitelistObject.js +15 -0
  332. package/arrays.d.ts +0 -41
  333. package/arrays.js +0 -153
  334. package/is.d.ts +0 -288
  335. package/is.js +0 -376
  336. package/math.d.ts +0 -28
  337. package/node/arrays.js +0 -166
  338. package/node/is.js +0 -417
  339. package/node/security.js +0 -29
  340. package/node/text.js +0 -70
  341. package/objects.d.ts +0 -22
  342. package/security.d.ts +0 -12
  343. package/security.js +0 -23
  344. package/ssr.d.ts +0 -2
  345. package/text.js +0 -65
package/location.d.ts CHANGED
@@ -1,147 +1,4 @@
1
- export declare type AnyQueryParams = undefined | null | Record<string | number, unknown>;
2
- /**
3
- * Solution without DOM or specific env native methods
4
- *
5
- * @see https://stackoverflow.com/a/21553982/1938970
6
- */
7
- export declare function parseURL(url: string): {
8
- href: string;
9
- protocol: string;
10
- host: string;
11
- hostname: string;
12
- port: string;
13
- pathname: string;
14
- search: string;
15
- hash: string;
16
- } | null;
17
- /**
18
- * Strips out the trailing slash
19
- */
20
- export declare function removeTralingSlash(urlLike?: string): string;
21
- /**
22
- * Normalise URL (absolute URL)
23
- *
24
- * - replaces too many consecutive slashes (except `http{s}://`)
25
- * - removes the trailing slash
26
- */
27
- export declare function normaliseUrl(absoluteUrl?: string): string;
28
- /**
29
- * Normalise URL pathname (relative URL)
30
- *
31
- * - replaces too many consecutive slashes
32
- * - removes the trailing slash
33
- */
34
- export declare function normaliseUrlPathname(pathname?: string): string;
35
- /**
36
- * Transform string in a URL pathname (relative URL)
37
- *
38
- * - adds an initial slash
39
- * - encode the string
40
- * - replaces whitespaces with dashes
41
- */
42
- export declare function transformToUrlPathname(toPathname?: string): string;
43
- /**
44
- * Get parsed query parameters as object dictionary (from URL or given query string)
45
- *
46
- * @param url A URL which contains a `?`, e.g. `?myparam=x` or `https://a.com?myparams=x`.
47
- * If not provided it defaults reading the current URL query string with
48
- * `location.search`. Through this argument you can use this
49
- * same function to parse, for instance, the query params of
50
- * the `href` of a `<a href="...">` HTML tag.
51
- *
52
- */
53
- export declare function getUrlQueryParams<T extends NonNullable<AnyQueryParams>>(url?: string): T;
54
- /**
55
- * Get pathname parts
56
- *
57
- * First clean the pathname from the first slash if any then split the pathname
58
- * in parts,
59
- * Given a pathname like: `"/en/{prefix}/{collection}/{slug}"` we obtain
60
- * `[locale, prefix, collection, slug]`
61
- */
62
- export declare function getUrlPathnameParts(pathname?: string): string[];
63
- /**
64
- * Get clean query string for URL
65
- *
66
- * It returns the query string **with** the initial `?`
67
- *
68
- * TODO: at some point replace with `URLSearchParams`, @see [caniuse](https://caniuse.com/?search=URLSearchParams)
69
- */
70
- export declare function buildUrlQueryString(params?: AnyQueryParams): string;
71
- /**
72
- * Change URL path, ensures initial and ending slashes and normalise eventual
73
- * consecutive slashes, it uses `history`.
74
- *
75
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
76
- * @returns {string} The new cleaned pathname
77
- */
78
- export declare function changeUrlPath(pathname: string, state?: object, replace?: boolean): string;
79
- /**
80
- * Change current URL query parameters, it uses `history`.
81
- *
82
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
83
- * @returns The query string with initial `?`
84
- */
85
- export declare function navigateToParams(params?: string | AnyQueryParams, replace?: boolean): string;
86
1
  /**
87
- * Merge current URL query parameters with the given ones, it uses `history`.
88
- *
89
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
2
+ * @category location
90
3
  */
91
- export declare function navigateToMergedParams(params?: NonNullable<AnyQueryParams>, replace?: boolean): string;
92
- /**
93
- * Remove URL query parameter, it uses `history`
94
- *
95
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
96
- */
97
- export declare function navigateWithoutUrlParam(paramName?: string, replace?: boolean): string;
98
- /**
99
- * Merge query parameters objects, it *mutates* the first given object argument
100
- *
101
- * @pure
102
- */
103
- export declare function mergeUrlQueryParams<T extends AnyQueryParams>(oldParams?: NonNullable<AnyQueryParams>, newParams?: NonNullable<AnyQueryParams>): T;
104
- /**
105
- * Update a URL string query parameters merging the given new query parameters
106
- *
107
- * @pure
108
- */
109
- export declare function updateUrlQueryParams(url: string, newParams?: NonNullable<AnyQueryParams>): string;
110
- /**
111
- * Update link `<a href="">` merging the given new query parameters.
112
- * it returns the newly created `href` URL value
113
- *
114
- * @pure
115
- */
116
- export declare function updateLinkParams($anchor: HTMLAnchorElement, newParams: NonNullable<AnyQueryParams>): string;
117
- /**
118
- * Redirect to url with params {optionally}, removes eventual trailing question
119
- * marks from the given URL, it uses `location`
120
- */
121
- export declare function redirectTo(url: string, params?: AnyQueryParams): void;
122
- /**
123
- * Is external url compared to the given current URL (if not provided it falls
124
- * back to `location.href`)
125
- *
126
- */
127
- export declare function isExternalUrl(url: string, currentUrl?: string): boolean;
128
- /**
129
- * It updates the `location.hash` with the given query params, it uses `location.hash`
130
- * if a second argument `hash` is not provded
131
- */
132
- export declare function navigateToHashParams(params?: string | AnyQueryParams, hash?: string): string;
133
- /**
134
- * It updates the "query params" within the `location.hash`, it uses `location`
135
- */
136
- export declare function navigateToMergedHashParams(params?: NonNullable<AnyQueryParams>, hash?: string): string;
137
- /**
138
- * It returns the "query params" as an object extracting it from the given `hash`
139
- *string or, if not provided, failling back reading the `location.hash`
140
- */
141
- export declare function getUrlHashParams<T extends NonNullable<AnyQueryParams>>(hash?: string): T;
142
- /**
143
- * It returns the "pathname" cleaned up from the `#` and the initial slashes
144
- * extracting it from the given `hash` string or, if not provided, failling
145
- * back reading the `location.hash`
146
- */
147
- export declare function getUrlHashPathname(hash?: string): string;
4
+ export declare type AnyQueryParams = undefined | null | Record<string | number, unknown>;
package/location.js CHANGED
@@ -1,299 +1 @@
1
- import { isBrowser } from "./ssr";
2
- import { isString, isNull, isUndefined } from "./is";
3
- /**
4
- * Solution without DOM or specific env native methods
5
- *
6
- * @see https://stackoverflow.com/a/21553982/1938970
7
- */
8
- export function parseURL(url) {
9
- var match = url.match(/^(https?:)\/\/(([^:/?#]*)(?::([0-9]+))?)([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
10
- return (match && {
11
- href: url,
12
- protocol: match[1],
13
- host: match[2],
14
- hostname: match[3],
15
- port: match[4],
16
- pathname: match[5],
17
- search: match[6],
18
- hash: match[7],
19
- });
20
- }
21
- /**
22
- * Strips out the trailing slash
23
- */
24
- export function removeTralingSlash(urlLike) {
25
- if (urlLike === void 0) { urlLike = ""; }
26
- return urlLike.replace(/\/*$/, "");
27
- }
28
- /**
29
- * Normalise URL (absolute URL)
30
- *
31
- * - replaces too many consecutive slashes (except `http{s}://`)
32
- * - removes the trailing slash
33
- */
34
- export function normaliseUrl(absoluteUrl) {
35
- if (absoluteUrl === void 0) { absoluteUrl = ""; }
36
- return removeTralingSlash(absoluteUrl.replace(/([^:]\/)\/+/g, "$1"));
37
- }
38
- /**
39
- * Normalise URL pathname (relative URL)
40
- *
41
- * - replaces too many consecutive slashes
42
- * - removes the trailing slash
43
- */
44
- export function normaliseUrlPathname(pathname) {
45
- if (pathname === void 0) { pathname = ""; }
46
- return removeTralingSlash(pathname.replace(/\/+/g, "/"));
47
- }
48
- /**
49
- * Transform string in a URL pathname (relative URL)
50
- *
51
- * - adds an initial slash
52
- * - encode the string
53
- * - replaces whitespaces with dashes
54
- */
55
- export function transformToUrlPathname(toPathname) {
56
- return isString(toPathname)
57
- ? "/".concat(encodeURIComponent(toPathname.replace(/\s/g, "-").toLowerCase()))
58
- : "";
59
- }
60
- /**
61
- * Get parsed query parameters as object dictionary (from URL or given query string)
62
- *
63
- * @param url A URL which contains a `?`, e.g. `?myparam=x` or `https://a.com?myparams=x`.
64
- * If not provided it defaults reading the current URL query string with
65
- * `location.search`. Through this argument you can use this
66
- * same function to parse, for instance, the query params of
67
- * the `href` of a `<a href="...">` HTML tag.
68
- *
69
- */
70
- export function getUrlQueryParams(url) {
71
- var _a;
72
- var params = {};
73
- var search = url
74
- ? (_a = url.split("?")) === null || _a === void 0 ? void 0 : _a[1]
75
- : isBrowser
76
- ? location.search.substring(1)
77
- : "";
78
- if (!search) {
79
- return {};
80
- }
81
- try {
82
- // @see https://stackoverflow.com/a/8649003/1938970
83
- var paramsAsObj = "{\"".concat(search
84
- .replace(/&/g, '","')
85
- .replace(/=/g, '":"'), "\"}");
86
- params = JSON.parse(paramsAsObj, function (key, value) {
87
- return key === "" ? value : decodeURIComponent(value);
88
- });
89
- }
90
- catch (e) {
91
- // do nothing or warn on process.env["NODE_ENV"] !== "production"
92
- }
93
- return params;
94
- }
95
- /**
96
- * Get pathname parts
97
- *
98
- * First clean the pathname from the first slash if any then split the pathname
99
- * in parts,
100
- * Given a pathname like: `"/en/{prefix}/{collection}/{slug}"` we obtain
101
- * `[locale, prefix, collection, slug]`
102
- */
103
- export function getUrlPathnameParts(pathname) {
104
- if (pathname === void 0) { pathname = ""; }
105
- pathname = pathname || isBrowser ? location.pathname : "";
106
- return pathname
107
- .replace(/^\//, "")
108
- .split("/")
109
- .filter(function (part) { return part; });
110
- }
111
- /**
112
- * Get clean query string for URL
113
- *
114
- * It returns the query string **with** the initial `?`
115
- *
116
- * TODO: at some point replace with `URLSearchParams`, @see [caniuse](https://caniuse.com/?search=URLSearchParams)
117
- */
118
- export function buildUrlQueryString(params) {
119
- if (params === void 0) { params = {}; }
120
- var output = "";
121
- for (var key in params) {
122
- var value = params[key];
123
- if (!isNull(value) && !isUndefined(value)) {
124
- output += "".concat(key, "=").concat(encodeURIComponent(value + ""), "&");
125
- }
126
- }
127
- // removes the last &
128
- return output ? "?".concat(output.replace(/&+$/, "")) : "";
129
- }
130
- /**
131
- * Change URL path, ensures initial and ending slashes and normalise eventual
132
- * consecutive slashes, it uses `history`.
133
- *
134
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
135
- * @returns {string} The new cleaned pathname
136
- */
137
- export function changeUrlPath(pathname, state, replace) {
138
- var path = normaliseUrlPathname("/".concat(pathname, "/"));
139
- if (isBrowser) {
140
- history[replace ? "replaceState" : "pushState"](state, "", path);
141
- }
142
- return path;
143
- }
144
- /**
145
- * Change current URL query parameters, it uses `history`.
146
- *
147
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
148
- * @returns The query string with initial `?`
149
- */
150
- export function navigateToParams(params, replace) {
151
- if (params === void 0) { params = {}; }
152
- var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
153
- if (isBrowser) {
154
- history[replace ? "replaceState" : "pushState"](null, "", location.pathname + queryString);
155
- }
156
- return queryString;
157
- }
158
- /**
159
- * Merge current URL query parameters with the given ones, it uses `history`.
160
- *
161
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
162
- */
163
- export function navigateToMergedParams(params, replace) {
164
- if (params === void 0) { params = {}; }
165
- return navigateToParams(mergeUrlQueryParams(getUrlQueryParams(), params), replace);
166
- }
167
- /**
168
- * Remove URL query parameter, it uses `history`
169
- *
170
- * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
171
- */
172
- export function navigateWithoutUrlParam(paramName, replace) {
173
- var params = {};
174
- var currentParams = getUrlQueryParams();
175
- for (var key in currentParams) {
176
- if (key !== paramName) {
177
- params[key] = currentParams[key];
178
- }
179
- }
180
- return navigateToParams(params, replace);
181
- }
182
- /**
183
- * Merge query parameters objects, it *mutates* the first given object argument
184
- *
185
- * @pure
186
- */
187
- export function mergeUrlQueryParams(oldParams, newParams) {
188
- if (oldParams === void 0) { oldParams = {}; }
189
- if (newParams === void 0) { newParams = {}; }
190
- for (var key in newParams) {
191
- var value = newParams[key];
192
- if (oldParams[key] && isNull(value)) {
193
- delete oldParams[key];
194
- }
195
- else {
196
- oldParams[key] = value;
197
- }
198
- }
199
- return oldParams;
200
- }
201
- /**
202
- * Update a URL string query parameters merging the given new query parameters
203
- *
204
- * @pure
205
- */
206
- export function updateUrlQueryParams(url, newParams) {
207
- if (newParams === void 0) { newParams = {}; }
208
- var parts = url.split("?");
209
- var allParams = parts[1]
210
- ? mergeUrlQueryParams(getUrlQueryParams(url), newParams)
211
- : newParams;
212
- return parts[0] + buildUrlQueryString(allParams);
213
- }
214
- /**
215
- * Update link `<a href="">` merging the given new query parameters.
216
- * it returns the newly created `href` URL value
217
- *
218
- * @pure
219
- */
220
- export function updateLinkParams($anchor, newParams) {
221
- var href = updateUrlQueryParams($anchor.href, newParams);
222
- $anchor.href = href;
223
- return href;
224
- }
225
- /**
226
- * Redirect to url with params {optionally}, removes eventual trailing question
227
- * marks from the given URL, it uses `location`
228
- */
229
- export function redirectTo(url, params) {
230
- if (isBrowser) {
231
- var queryString = buildUrlQueryString(params);
232
- location.href = url.replace(/\?+$/g, "") + queryString;
233
- }
234
- }
235
- /**
236
- * Is external url compared to the given current URL (if not provided it falls
237
- * back to `location.href`)
238
- *
239
- */
240
- export function isExternalUrl(url, currentUrl) {
241
- var _a;
242
- var reg = /https?:\/\/((?:[\w\d-]+\.)+[\w\d]{2,})/i;
243
- var urlMatches = reg.exec(url);
244
- // if no matches are found it means we either have an invalid URL, a relative
245
- // URL or a hash link, and those are not considered externals
246
- if (!urlMatches) {
247
- return false;
248
- }
249
- currentUrl = currentUrl || isBrowser ? location.href : "";
250
- return currentUrl ? ((_a = reg.exec(currentUrl)) === null || _a === void 0 ? void 0 : _a[1]) !== urlMatches[1] : true;
251
- }
252
- /**
253
- * It updates the `location.hash` with the given query params, it uses `location.hash`
254
- * if a second argument `hash` is not provded
255
- */
256
- export function navigateToHashParams(params, hash) {
257
- if (params === void 0) { params = {}; }
258
- if (hash === void 0) { hash = ""; }
259
- var useLocation = !hash;
260
- hash = hash || location.hash;
261
- var hashQueryLess = getUrlHashPathname(hash);
262
- var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
263
- var newHash = "#/" + hashQueryLess + queryString;
264
- if (useLocation) {
265
- location.hash = newHash;
266
- }
267
- return newHash;
268
- }
269
- /**
270
- * It updates the "query params" within the `location.hash`, it uses `location`
271
- */
272
- export function navigateToMergedHashParams(params, hash) {
273
- if (params === void 0) { params = {}; }
274
- if (hash === void 0) { hash = ""; }
275
- return navigateToHashParams(mergeUrlQueryParams(getUrlHashParams(hash), params), hash);
276
- }
277
- /**
278
- * It returns the "query params" as an object extracting it from the given `hash`
279
- *string or, if not provided, failling back reading the `location.hash`
280
- */
281
- export function getUrlHashParams(hash) {
282
- if (hash === void 0) { hash = ""; }
283
- hash = hash || location.hash;
284
- var hashParts = hash.split("?");
285
- if (hashParts.length >= 1) {
286
- return Object.fromEntries(new URLSearchParams(hashParts[1]));
287
- }
288
- return {};
289
- }
290
- /**
291
- * It returns the "pathname" cleaned up from the `#` and the initial slashes
292
- * extracting it from the given `hash` string or, if not provided, failling
293
- * back reading the `location.hash`
294
- */
295
- export function getUrlHashPathname(hash) {
296
- if (hash === void 0) { hash = ""; }
297
- hash = hash || location.hash;
298
- return hash.split("?")[0].replace(/^#\//, "");
299
- }
1
+ export {};
package/mapListBy.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Maps an array of objects into a map keyed with the given key
3
+ *
4
+ * @category array
5
+ */
6
+ export declare function mapListBy<T extends Record<string | number | symbol, any>>(array?: T[], key?: keyof T): Record<T[keyof T], T>;
7
+ export default mapListBy;
package/mapListBy.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Maps an array of objects into a map keyed with the given key
3
+ *
4
+ * @category array
5
+ */
6
+ export function mapListBy(array, key) {
7
+ if (array === void 0) { array = []; }
8
+ if (key === void 0) { key = ""; }
9
+ return array.reduce(function (obj, item) {
10
+ obj[item[key]] = item;
11
+ return obj;
12
+ }, {});
13
+ }
14
+ export default mapListBy;
@@ -58,3 +58,4 @@ declare const defaultBaseSortFn: BaseSorter<unknown>;
58
58
  declare function matchSorter<ItemType = string>(items: ReadonlyArray<ItemType>, value: string, options?: MatchSorterOptions<ItemType>): Array<ItemType>;
59
59
  export { matchSorter, defaultBaseSortFn };
60
60
  export type { MatchSorterOptions, KeyAttributesOptions, KeyOption, KeyAttributes, RankingInfo, ValueGetterKey, };
61
+ export default matchSorter;
@@ -15,7 +15,7 @@ import { __assign } from "tslib";
15
15
  * @copyright (c) 2020 Kent C. Dodds
16
16
  * @author Kent C. Dodds <me@kentcdodds.com> (https://kentcdodds.com)
17
17
  */
18
- import { removeAccents } from "./text";
18
+ import removeAccents from "./removeAccents";
19
19
  var RANKING_CASE_SENSITIVE_EQUAL = 7;
20
20
  var RANKING_EQUAL = 6;
21
21
  var RANKING_STARTS_WITH = 5;
@@ -367,3 +367,4 @@ function getKeyAttributes(key) {
367
367
  return __assign(__assign({}, defaultKeyAttributes), key);
368
368
  }
369
369
  export { matchSorter, defaultBaseSortFn };
370
+ export default matchSorter;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Merge two or more objects together. It mutates the target object.
3
+ *
4
+ * @category objects
5
+ * @see https://stackoverflow.com/a/46973278/1938970
6
+ */
7
+ export declare const mergeObjects: <T extends object = object>(target: T, ...sources: T[]) => T;
@@ -1,15 +1,9 @@
1
1
  import { __spreadArray } from "tslib";
2
- import { isObject } from "./is";
3
- /**
4
- * Type safe replacement for `Object.keys(myObject)` to iterate over a record
5
- * without loosing the key's types in simple `string`s.
6
- *
7
- * @see https://stackoverflow.com/a/59459000/1938970
8
- */
9
- export var getKeys = Object.keys;
2
+ import { isObject } from "./isObject";
10
3
  /**
11
4
  * Merge two or more objects together. It mutates the target object.
12
5
  *
6
+ * @category objects
13
7
  * @see https://stackoverflow.com/a/46973278/1938970
14
8
  */
15
9
  export var mergeObjects = function (target) {
@@ -41,26 +35,3 @@ export var mergeObjects = function (target) {
41
35
  }
42
36
  return mergeObjects.apply(void 0, __spreadArray([target], sources, false));
43
37
  };
44
- /**
45
- * Swap object map key/value
46
- */
47
- export function swapMap(map) {
48
- if (map === void 0) { map = {}; }
49
- var output = {};
50
- for (var key in map) {
51
- output[map[key]] = key;
52
- }
53
- return output;
54
- }
55
- /**
56
- * Whitelist an object properties by selecting only the given keys, it returns a
57
- * new object.
58
- */
59
- export function whitelistObject(object, keys) {
60
- var output = {};
61
- var len = keys.length;
62
- while (len--) {
63
- output[keys[len]] = object[keys[len]];
64
- }
65
- return output;
66
- }
@@ -0,0 +1,9 @@
1
+ import { type AnyQueryParams } from "./location";
2
+ /**
3
+ * Merge query parameters objects, it *mutates* the first given object argument
4
+ *
5
+ * @category location
6
+ * @pure
7
+ */
8
+ export declare function mergeUrlQueryParams<T extends AnyQueryParams>(oldParams?: NonNullable<AnyQueryParams>, newParams?: NonNullable<AnyQueryParams>): T;
9
+ export default mergeUrlQueryParams;
@@ -0,0 +1,22 @@
1
+ import isNull from "./isNull";
2
+ /**
3
+ * Merge query parameters objects, it *mutates* the first given object argument
4
+ *
5
+ * @category location
6
+ * @pure
7
+ */
8
+ export function mergeUrlQueryParams(oldParams, newParams) {
9
+ if (oldParams === void 0) { oldParams = {}; }
10
+ if (newParams === void 0) { newParams = {}; }
11
+ for (var key in newParams) {
12
+ var value = newParams[key];
13
+ if (oldParams[key] && isNull(value)) {
14
+ delete oldParams[key];
15
+ }
16
+ else {
17
+ oldParams[key] = value;
18
+ }
19
+ }
20
+ return oldParams;
21
+ }
22
+ export default mergeUrlQueryParams;
@@ -0,0 +1,9 @@
1
+ import { type AnyQueryParams } from "./location";
2
+ /**
3
+ * It updates the `location.hash` with the given query params, it uses `location.hash`
4
+ * if a second argument `hash` is not provded
5
+ *
6
+ * @category location
7
+ */
8
+ export declare function navigateToHashParams(params?: string | AnyQueryParams, hash?: string): string;
9
+ export default navigateToHashParams;
@@ -0,0 +1,22 @@
1
+ import buildUrlQueryString from "./buildUrlQueryString";
2
+ import getUrlHashPathname from "./getUrlHashPathname";
3
+ /**
4
+ * It updates the `location.hash` with the given query params, it uses `location.hash`
5
+ * if a second argument `hash` is not provded
6
+ *
7
+ * @category location
8
+ */
9
+ export function navigateToHashParams(params, hash) {
10
+ if (params === void 0) { params = {}; }
11
+ if (hash === void 0) { hash = ""; }
12
+ var useLocation = !hash;
13
+ hash = hash || location.hash;
14
+ var hashQueryLess = getUrlHashPathname(hash);
15
+ var queryString = typeof params === "string" ? params : buildUrlQueryString(params);
16
+ var newHash = "#/" + hashQueryLess + queryString;
17
+ if (useLocation) {
18
+ location.hash = newHash;
19
+ }
20
+ return newHash;
21
+ }
22
+ export default navigateToHashParams;
@@ -0,0 +1,8 @@
1
+ import { type AnyQueryParams } from "./location";
2
+ /**
3
+ * It updates the "query params" within the `location.hash`, it uses `location`
4
+ *
5
+ * @category location
6
+ */
7
+ export declare function navigateToMergedHashParams(params?: NonNullable<AnyQueryParams>, hash?: string): string;
8
+ export default navigateToMergedHashParams;
@@ -0,0 +1,14 @@
1
+ import getUrlHashParams from "./getUrlHashParams";
2
+ import mergeUrlQueryParams from "./mergeUrlQueryParams";
3
+ import navigateToHashParams from "./navigateToHashParams";
4
+ /**
5
+ * It updates the "query params" within the `location.hash`, it uses `location`
6
+ *
7
+ * @category location
8
+ */
9
+ export function navigateToMergedHashParams(params, hash) {
10
+ if (params === void 0) { params = {}; }
11
+ if (hash === void 0) { hash = ""; }
12
+ return navigateToHashParams(mergeUrlQueryParams(getUrlHashParams(hash), params), hash);
13
+ }
14
+ export default navigateToMergedHashParams;
@@ -0,0 +1,9 @@
1
+ import { type AnyQueryParams } from "./location";
2
+ /**
3
+ * Merge current URL query parameters with the given ones, it uses `history`.
4
+ *
5
+ * @category location
6
+ * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
7
+ */
8
+ export declare function navigateToMergedParams(params?: NonNullable<AnyQueryParams>, replace?: boolean): string;
9
+ export default navigateToMergedParams;
@@ -0,0 +1,14 @@
1
+ import getUrlQueryParams from "./getUrlQueryParams";
2
+ import mergeUrlQueryParams from "./mergeUrlQueryParams";
3
+ import navigateToParams from "./navigateToParams";
4
+ /**
5
+ * Merge current URL query parameters with the given ones, it uses `history`.
6
+ *
7
+ * @category location
8
+ * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
9
+ */
10
+ export function navigateToMergedParams(params, replace) {
11
+ if (params === void 0) { params = {}; }
12
+ return navigateToParams(mergeUrlQueryParams(getUrlQueryParams(), params), replace);
13
+ }
14
+ export default navigateToMergedParams;
@@ -0,0 +1,10 @@
1
+ import { type AnyQueryParams } from "./location";
2
+ /**
3
+ * Change current URL query parameters, it uses `history`.
4
+ *
5
+ * @category location
6
+ * @param replace Replace URL instead of pushing it in the history stack. By default it pushes it.
7
+ * @returns The query string with initial `?`
8
+ */
9
+ export declare function navigateToParams(params?: string | AnyQueryParams, replace?: boolean): string;
10
+ export default navigateToParams;