@koine/utils 1.0.73 → 1.0.76

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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Capitalize first letter of the given string.
3
+ *
4
+ * @category text
5
+ * @see https://stackoverflow.com/a/11409944/1938970
6
+ */
7
+ export declare function capitalize<T extends string>(string: null | T): Capitalize<T>;
8
+ export default capitalize;
package/capitalize.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Capitalize first letter of the given string.
3
+ *
4
+ * @category text
5
+ * @see https://stackoverflow.com/a/11409944/1938970
6
+ */
7
+ export function capitalize(string) {
8
+ var ensuredString = string || "";
9
+ return (ensuredString.charAt(0).toUpperCase() +
10
+ ensuredString.slice(1));
11
+ }
12
+ export default capitalize;
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * Returns an array of undefined values of the desired length, useful to build
4
+ * skeleton UIs.
5
+ *
6
+ * @category array
7
+ */
8
+ export declare function getEmptyArray(length: number | string): undefined[];
9
+ export default getEmptyArray;
@@ -0,0 +1,15 @@
1
+ import isNumber from "./isNumber";
2
+ /**
3
+ *
4
+ * Returns an array of undefined values of the desired length, useful to build
5
+ * skeleton UIs.
6
+ *
7
+ * @category array
8
+ */
9
+ export function getEmptyArray /* <T extends undefined | null = undefined> */(length) {
10
+ if (!isNumber(length)) {
11
+ length = parseInt(length, 10);
12
+ }
13
+ return Array.from({ length: length });
14
+ }
15
+ export default getEmptyArray;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get query parameter as `string` treating the `ParsedUrlQuery` result of
3
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
4
+ * router and elsewhere)
5
+ *
6
+ * @category location
7
+ *
8
+ * @param {string} [raw] - The _raw_ query parameter
9
+ * @param {string[]} [allowedValues=[]] - The list of values (as strings) that the parameter can have, if not one of them `null` is returned
10
+ */
11
+ export declare function getParamAmong<T extends string[]>(raw?: string | string[], allowedValues?: T): T[number] | null;
12
+ export default getParamAmong;
@@ -0,0 +1,17 @@
1
+ import getParamAsString from "./getParamAsString";
2
+ /**
3
+ * Get query parameter as `string` treating the `ParsedUrlQuery` result of
4
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
5
+ * router and elsewhere)
6
+ *
7
+ * @category location
8
+ *
9
+ * @param {string} [raw] - The _raw_ query parameter
10
+ * @param {string[]} [allowedValues=[]] - The list of values (as strings) that the parameter can have, if not one of them `null` is returned
11
+ */
12
+ export function getParamAmong(raw, allowedValues) {
13
+ if (allowedValues === void 0) { allowedValues = []; }
14
+ var string = getParamAsString(raw);
15
+ return allowedValues.includes(string) ? string : null;
16
+ }
17
+ export default getParamAmong;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get query parameter as `int`eger treating the `ParsedUrlQuery` result of
3
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
4
+ * router and elsewhere)
5
+ *
6
+ * @category location
7
+ *
8
+ * @param {string} [raw] - The _raw_ query parameter
9
+ * @param {number} [fallback] - Fallback number, we return `null` if not provided
10
+ */
11
+ export declare function getParamAsInt<TFallback extends number | null | undefined>(raw?: string | string[], fallback?: TFallback): number | TFallback;
12
+ export default getParamAsInt;
@@ -0,0 +1,20 @@
1
+ import getParamAsString from "./getParamAsString";
2
+ /**
3
+ * Get query parameter as `int`eger treating the `ParsedUrlQuery` result of
4
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
5
+ * router and elsewhere)
6
+ *
7
+ * @category location
8
+ *
9
+ * @param {string} [raw] - The _raw_ query parameter
10
+ * @param {number} [fallback] - Fallback number, we return `null` if not provided
11
+ */
12
+ export function getParamAsInt(raw, fallback) {
13
+ if (fallback === void 0) { fallback = null; }
14
+ var string = getParamAsString(raw);
15
+ if (string) {
16
+ return parseInt(string, 10);
17
+ }
18
+ return fallback;
19
+ }
20
+ export default getParamAsInt;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Get query parameter as `string` treating the `ParsedUrlQuery` result of
3
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
4
+ * router and elsewhere)
5
+ *
6
+ * @category location
7
+ *
8
+ * @param {string} [raw] - The _raw_ query parameter
9
+ */
10
+ export declare function getParamAsString(raw?: string | string[]): string;
11
+ export default getParamAsString;
@@ -0,0 +1,14 @@
1
+ import isArray from "./isArray";
2
+ /**
3
+ * Get query parameter as `string` treating the `ParsedUrlQuery` result of
4
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
5
+ * router and elsewhere)
6
+ *
7
+ * @category location
8
+ *
9
+ * @param {string} [raw] - The _raw_ query parameter
10
+ */
11
+ export function getParamAsString(raw) {
12
+ return (isArray(raw) ? raw[0] : raw) || "";
13
+ }
14
+ export default getParamAsString;
package/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./accentSets";
2
2
  export * from "./addOrReplaceAtIdx";
3
3
  export * from "./arrayToLookup";
4
4
  export * from "./buildUrlQueryString";
5
+ export * from "./capitalize";
5
6
  export * from "./changeUrlPath";
6
7
  export * from "./chunkByChunks";
7
8
  export * from "./chunkBySize";
@@ -16,8 +17,12 @@ export * from "./Emitter";
16
17
  export * from "./encode";
17
18
  export * from "./ensureInt";
18
19
  export * from "./findDuplicatedIndexes";
20
+ export * from "./getEmptyArray";
19
21
  export * from "./getKeys";
20
22
  export * from "./getNonce";
23
+ export * from "./getParamAmong";
24
+ export * from "./getParamAsInt";
25
+ export * from "./getParamAsString";
21
26
  export * from "./getType";
22
27
  export * from "./getUrlHashParams";
23
28
  export * from "./getUrlHashPathname";
package/index.js CHANGED
@@ -2,6 +2,7 @@ export * from "./accentSets";
2
2
  export * from "./addOrReplaceAtIdx";
3
3
  export * from "./arrayToLookup";
4
4
  export * from "./buildUrlQueryString";
5
+ export * from "./capitalize";
5
6
  export * from "./changeUrlPath";
6
7
  export * from "./chunkByChunks";
7
8
  export * from "./chunkBySize";
@@ -17,8 +18,12 @@ export * from "./encode";
17
18
  export * from "./ensureInt";
18
19
  // export * from "./env"
19
20
  export * from "./findDuplicatedIndexes";
21
+ export * from "./getEmptyArray";
20
22
  export * from "./getKeys";
21
23
  export * from "./getNonce";
24
+ export * from "./getParamAmong";
25
+ export * from "./getParamAsInt";
26
+ export * from "./getParamAsString";
22
27
  export * from "./getType";
23
28
  export * from "./getUrlHashParams";
24
29
  export * from "./getUrlHashPathname";
@@ -92,6 +97,7 @@ export * from "./readCookie";
92
97
  export * from "./redirectTo";
93
98
  export * from "./removeAccents";
94
99
  export * from "./removeCookie";
100
+ // export * from "./removeDuplicates";
95
101
  export * from "./removeDuplicatesByKey";
96
102
  export * from "./removeDuplicatesComparing";
97
103
  export * from "./removeIndexesFromArray";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.capitalize = void 0;
4
+ /**
5
+ * Capitalize first letter of the given string.
6
+ *
7
+ * @category text
8
+ * @see https://stackoverflow.com/a/11409944/1938970
9
+ */
10
+ function capitalize(string) {
11
+ var ensuredString = string || "";
12
+ return (ensuredString.charAt(0).toUpperCase() +
13
+ ensuredString.slice(1));
14
+ }
15
+ exports.capitalize = capitalize;
16
+ exports.default = capitalize;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEmptyArray = void 0;
4
+ var isNumber_1 = require("./isNumber");
5
+ /**
6
+ *
7
+ * Returns an array of undefined values of the desired length, useful to build
8
+ * skeleton UIs.
9
+ *
10
+ * @category array
11
+ */
12
+ function getEmptyArray /* <T extends undefined | null = undefined> */(length) {
13
+ if (!(0, isNumber_1.default)(length)) {
14
+ length = parseInt(length, 10);
15
+ }
16
+ return Array.from({ length: length });
17
+ }
18
+ exports.getEmptyArray = getEmptyArray;
19
+ exports.default = getEmptyArray;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParamAmong = void 0;
4
+ var getParamAsString_1 = require("./getParamAsString");
5
+ /**
6
+ * Get query parameter as `string` treating the `ParsedUrlQuery` result of
7
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
8
+ * router and elsewhere)
9
+ *
10
+ * @category location
11
+ *
12
+ * @param {string} [raw] - The _raw_ query parameter
13
+ * @param {string[]} [allowedValues=[]] - The list of values (as strings) that the parameter can have, if not one of them `null` is returned
14
+ */
15
+ function getParamAmong(raw, allowedValues) {
16
+ if (allowedValues === void 0) { allowedValues = []; }
17
+ var string = (0, getParamAsString_1.default)(raw);
18
+ return allowedValues.includes(string) ? string : null;
19
+ }
20
+ exports.getParamAmong = getParamAmong;
21
+ exports.default = getParamAmong;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParamAsInt = void 0;
4
+ var getParamAsString_1 = require("./getParamAsString");
5
+ /**
6
+ * Get query parameter as `int`eger treating the `ParsedUrlQuery` result of
7
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
8
+ * router and elsewhere)
9
+ *
10
+ * @category location
11
+ *
12
+ * @param {string} [raw] - The _raw_ query parameter
13
+ * @param {number} [fallback] - Fallback number, we return `null` if not provided
14
+ */
15
+ function getParamAsInt(raw, fallback) {
16
+ if (fallback === void 0) { fallback = null; }
17
+ var string = (0, getParamAsString_1.default)(raw);
18
+ if (string) {
19
+ return parseInt(string, 10);
20
+ }
21
+ return fallback;
22
+ }
23
+ exports.getParamAsInt = getParamAsInt;
24
+ exports.default = getParamAsInt;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getParamAsString = void 0;
4
+ var isArray_1 = require("./isArray");
5
+ /**
6
+ * Get query parameter as `string` treating the `ParsedUrlQuery` result of
7
+ * [`querystring`](https://nodejs.org/api/querystring.html) (used in next.js
8
+ * router and elsewhere)
9
+ *
10
+ * @category location
11
+ *
12
+ * @param {string} [raw] - The _raw_ query parameter
13
+ */
14
+ function getParamAsString(raw) {
15
+ return ((0, isArray_1.default)(raw) ? raw[0] : raw) || "";
16
+ }
17
+ exports.getParamAsString = getParamAsString;
18
+ exports.default = getParamAsString;
package/node/index.js CHANGED
@@ -5,6 +5,7 @@ tslib_1.__exportStar(require("./accentSets"), exports);
5
5
  tslib_1.__exportStar(require("./addOrReplaceAtIdx"), exports);
6
6
  tslib_1.__exportStar(require("./arrayToLookup"), exports);
7
7
  tslib_1.__exportStar(require("./buildUrlQueryString"), exports);
8
+ tslib_1.__exportStar(require("./capitalize"), exports);
8
9
  tslib_1.__exportStar(require("./changeUrlPath"), exports);
9
10
  tslib_1.__exportStar(require("./chunkByChunks"), exports);
10
11
  tslib_1.__exportStar(require("./chunkBySize"), exports);
@@ -20,8 +21,12 @@ tslib_1.__exportStar(require("./encode"), exports);
20
21
  tslib_1.__exportStar(require("./ensureInt"), exports);
21
22
  // export * from "./env"
22
23
  tslib_1.__exportStar(require("./findDuplicatedIndexes"), exports);
24
+ tslib_1.__exportStar(require("./getEmptyArray"), exports);
23
25
  tslib_1.__exportStar(require("./getKeys"), exports);
24
26
  tslib_1.__exportStar(require("./getNonce"), exports);
27
+ tslib_1.__exportStar(require("./getParamAmong"), exports);
28
+ tslib_1.__exportStar(require("./getParamAsInt"), exports);
29
+ tslib_1.__exportStar(require("./getParamAsString"), exports);
25
30
  tslib_1.__exportStar(require("./getType"), exports);
26
31
  tslib_1.__exportStar(require("./getUrlHashParams"), exports);
27
32
  tslib_1.__exportStar(require("./getUrlHashPathname"), exports);
@@ -95,6 +100,7 @@ tslib_1.__exportStar(require("./readCookie"), exports);
95
100
  tslib_1.__exportStar(require("./redirectTo"), exports);
96
101
  tslib_1.__exportStar(require("./removeAccents"), exports);
97
102
  tslib_1.__exportStar(require("./removeCookie"), exports);
103
+ // export * from "./removeDuplicates";
98
104
  tslib_1.__exportStar(require("./removeDuplicatesByKey"), exports);
99
105
  tslib_1.__exportStar(require("./removeDuplicatesComparing"), exports);
100
106
  tslib_1.__exportStar(require("./removeIndexesFromArray"), exports);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // /**
3
+ // * FIXME: Type 'Set<any>' can only be iterated through when using the
4
+ // * '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
5
+ // * I am not sure I want to use those ts options here. Let's keep it commented
6
+ // * for now
7
+ // *
8
+ // * @category array
9
+ // */
10
+ // export function removeDuplicates<T extends any[]>(arr: T) {
11
+ // return [...new Set(arr)];
12
+ // }
13
+ // export default removeDuplicates;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "peerDependencies": {
8
8
  "tslib": "^2.4.0"
9
9
  },
10
- "version": "1.0.73",
10
+ "version": "1.0.76",
11
11
  "module": "./index.js",
12
12
  "types": "./index.d.ts"
13
13
  }
File without changes
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // /**
3
+ // * FIXME: Type 'Set<any>' can only be iterated through when using the
4
+ // * '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.
5
+ // * I am not sure I want to use those ts options here. Let's keep it commented
6
+ // * for now
7
+ // *
8
+ // * @category array
9
+ // */
10
+ // export function removeDuplicates<T extends any[]>(arr: T) {
11
+ // return [...new Set(arr)];
12
+ // }
13
+ // export default removeDuplicates;