@worknice/utils 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ Copyright (c) 2024 Worknice
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
4
+ associated documentation files (the "Software"), to deal in the Software without restriction,
5
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
6
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
7
+ furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial
10
+ portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
13
+ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
15
+ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Worknice Utils
2
+
3
+ This package contains a collection of utilities used across Worknice projects.
@@ -0,0 +1,8 @@
1
+ declare class RequestError extends Error {
2
+ method: string;
3
+ response: Response;
4
+ responseBody?: string | undefined;
5
+ constructor(method: string, response: Response, responseBody?: string | undefined, options?: ErrorOptions);
6
+ }
7
+
8
+ export { RequestError as default };
@@ -0,0 +1,19 @@
1
+ class RequestError extends Error {
2
+ constructor(method, response, responseBody, options) {
3
+ super(
4
+ `${method} ${response.url} ${response.status} ${response.statusText}` + (responseBody ? `
5
+
6
+ ${responseBody}` : ""),
7
+ options
8
+ );
9
+ this.method = method;
10
+ this.response = response;
11
+ this.responseBody = responseBody;
12
+ this.name = "RequestError";
13
+ }
14
+ }
15
+ var RequestError_default = RequestError;
16
+ export {
17
+ RequestError_default as default
18
+ };
19
+ //# sourceMappingURL=RequestError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors/RequestError.ts"],"sourcesContent":["class RequestError extends Error {\n constructor(\n public method: string,\n public response: Response,\n public responseBody?: string,\n options?: ErrorOptions,\n ) {\n super(\n `${method} ${response.url} ${response.status} ${response.statusText}` +\n (responseBody ? `\\n\\n${responseBody}` : \"\"),\n options,\n );\n this.name = \"RequestError\";\n }\n}\n\nexport default RequestError;\n"],"mappings":"AAAA,MAAM,qBAAqB,MAAM;AAAA,EAC/B,YACS,QACA,UACA,cACP,SACA;AACA;AAAA,MACE,GAAG,MAAM,IAAI,SAAS,GAAG,IAAI,SAAS,MAAM,IAAI,SAAS,UAAU,MAChE,eAAe;AAAA;AAAA,EAAO,YAAY,KAAK;AAAA,MAC1C;AAAA,IACF;AATO;AACA;AACA;AAQP,SAAK,OAAO;AAAA,EACd;AACF;AAEA,IAAO,uBAAQ;","names":[]}
@@ -0,0 +1,5 @@
1
+ export { default as isAfter } from './utils/isAfter.js';
2
+ export { default as isSamePlainDate } from './utils/isSamePlainDate.js';
3
+ export { default as isValidPlainDate } from './utils/isValidPlainDate.js';
4
+ export { default as parsePlainDate } from './utils/parsePlainDate.js';
5
+ import 'temporal-polyfill';
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ import { default as default2 } from "./utils/isAfter.js";
2
+ import { default as default3 } from "./utils/isSamePlainDate.js";
3
+ import { default as default4 } from "./utils/isValidPlainDate.js";
4
+ import { default as default5 } from "./utils/parsePlainDate.js";
5
+ export {
6
+ default2 as isAfter,
7
+ default3 as isSamePlainDate,
8
+ default4 as isValidPlainDate,
9
+ default5 as parsePlainDate
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { default as isAfter } from \"./utils/isAfter.js\";\nexport { default as isSamePlainDate } from \"./utils/isSamePlainDate.js\";\nexport { default as isValidPlainDate } from \"./utils/isValidPlainDate.js\";\nexport { default as parsePlainDate } from \"./utils/parsePlainDate.js\";\n"],"mappings":"AAAA,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAkC;AAC3C,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAiC;","names":["default"]}
@@ -0,0 +1,3 @@
1
+ declare function envCheck(value: string | undefined, name: string): asserts value is string;
2
+
3
+ export { envCheck as default };
@@ -0,0 +1,10 @@
1
+ function envCheck(value, name) {
2
+ if (value === void 0) {
3
+ throw Error(`Missing \`${name}\` environment variable.`);
4
+ }
5
+ }
6
+ var envCheck_default = envCheck;
7
+ export {
8
+ envCheck_default as default
9
+ };
10
+ //# sourceMappingURL=envCheck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/envCheck.ts"],"sourcesContent":["function envCheck(value: string | undefined, name: string): asserts value is string {\n if (value === undefined) {\n throw Error(`Missing \\`${name}\\` environment variable.`);\n }\n}\n\nexport default envCheck;\n"],"mappings":"AAAA,SAAS,SAAS,OAA2B,MAAuC;AAClF,MAAI,UAAU,QAAW;AACvB,UAAM,MAAM,aAAa,IAAI,0BAA0B;AAAA,EACzD;AACF;AAEA,IAAO,mBAAQ;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+
3
+ declare const isAfter: (a: Temporal.Instant, b: Temporal.Instant) => boolean;
4
+
5
+ export { isAfter as default };
@@ -0,0 +1,7 @@
1
+ import { Temporal } from "temporal-polyfill";
2
+ const isAfter = (a, b) => Temporal.Instant.compare(a, b) === 1;
3
+ var isAfter_default = isAfter;
4
+ export {
5
+ isAfter_default as default
6
+ };
7
+ //# sourceMappingURL=isAfter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/isAfter.ts"],"sourcesContent":["import { Temporal } from \"temporal-polyfill\";\n\nconst isAfter = (a: Temporal.Instant, b: Temporal.Instant) => Temporal.Instant.compare(a, b) === 1;\n\nexport default isAfter;\n"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,MAAM,UAAU,CAAC,GAAqB,MAAwB,SAAS,QAAQ,QAAQ,GAAG,CAAC,MAAM;AAEjG,IAAO,kBAAQ;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare const isSamePlainDate: (a: string | null | undefined, b: string | null | undefined) => boolean;
2
+
3
+ export { isSamePlainDate as default };
@@ -0,0 +1,13 @@
1
+ import parsePlainDate from "./parsePlainDate.js";
2
+ const isSamePlainDate = (a, b) => {
3
+ const dateA = parsePlainDate(a);
4
+ const dateB = parsePlainDate(b);
5
+ if (dateA === null && dateB === null) return true;
6
+ if (dateA === null || dateB === null) return false;
7
+ return dateA.equals(dateB);
8
+ };
9
+ var isSamePlainDate_default = isSamePlainDate;
10
+ export {
11
+ isSamePlainDate_default as default
12
+ };
13
+ //# sourceMappingURL=isSamePlainDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/isSamePlainDate.ts"],"sourcesContent":["import parsePlainDate from \"./parsePlainDate.js\";\n\nconst isSamePlainDate = (a: string | null | undefined, b: string | null | undefined): boolean => {\n const dateA = parsePlainDate(a);\n const dateB = parsePlainDate(b);\n if (dateA === null && dateB === null) return true;\n if (dateA === null || dateB === null) return false;\n return dateA.equals(dateB);\n};\n\nexport default isSamePlainDate;\n"],"mappings":"AAAA,OAAO,oBAAoB;AAE3B,MAAM,kBAAkB,CAAC,GAA8B,MAA0C;AAC/F,QAAM,QAAQ,eAAe,CAAC;AAC9B,QAAM,QAAQ,eAAe,CAAC;AAC9B,MAAI,UAAU,QAAQ,UAAU,KAAM,QAAO;AAC7C,MAAI,UAAU,QAAQ,UAAU,KAAM,QAAO;AAC7C,SAAO,MAAM,OAAO,KAAK;AAC3B;AAEA,IAAO,0BAAQ;","names":[]}
@@ -0,0 +1,3 @@
1
+ declare const isValidPlainDate: (date: string | null | undefined) => date is string;
2
+
3
+ export { isValidPlainDate as default };
@@ -0,0 +1,14 @@
1
+ import { Temporal } from "temporal-polyfill";
2
+ const isValidPlainDate = (date) => {
3
+ if (date === null || date === void 0) return false;
4
+ try {
5
+ return date === Temporal.PlainDate.from(date).toString();
6
+ } catch {
7
+ return false;
8
+ }
9
+ };
10
+ var isValidPlainDate_default = isValidPlainDate;
11
+ export {
12
+ isValidPlainDate_default as default
13
+ };
14
+ //# sourceMappingURL=isValidPlainDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/isValidPlainDate.ts"],"sourcesContent":["import { Temporal } from \"temporal-polyfill\";\n\nconst isValidPlainDate = (date: string | null | undefined): date is string => {\n if (date === null || date === undefined) return false;\n try {\n return date === Temporal.PlainDate.from(date).toString();\n } catch {\n return false;\n }\n};\n\nexport default isValidPlainDate;\n"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,MAAM,mBAAmB,CAAC,SAAoD;AAC5E,MAAI,SAAS,QAAQ,SAAS,OAAW,QAAO;AAChD,MAAI;AACF,WAAO,SAAS,SAAS,UAAU,KAAK,IAAI,EAAE,SAAS;AAAA,EACzD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,IAAO,2BAAQ;","names":[]}
@@ -0,0 +1,5 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+
3
+ declare const parsePlainDate: (date: string | null | undefined) => Temporal.PlainDate | null;
4
+
5
+ export { parsePlainDate as default };
@@ -0,0 +1,14 @@
1
+ import { Temporal } from "temporal-polyfill";
2
+ const parsePlainDate = (date) => {
3
+ if (date === null || date === void 0) return null;
4
+ try {
5
+ return Temporal.PlainDate.from(date);
6
+ } catch {
7
+ return null;
8
+ }
9
+ };
10
+ var parsePlainDate_default = parsePlainDate;
11
+ export {
12
+ parsePlainDate_default as default
13
+ };
14
+ //# sourceMappingURL=parsePlainDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/parsePlainDate.ts"],"sourcesContent":["import { Temporal } from \"temporal-polyfill\";\n\nconst parsePlainDate = (date: string | null | undefined): Temporal.PlainDate | null => {\n if (date === null || date === undefined) return null;\n try {\n return Temporal.PlainDate.from(date);\n } catch {\n return null;\n }\n};\n\nexport default parsePlainDate;\n"],"mappings":"AAAA,SAAS,gBAAgB;AAEzB,MAAM,iBAAiB,CAAC,SAA+D;AACrF,MAAI,SAAS,QAAQ,SAAS,OAAW,QAAO;AAChD,MAAI;AACF,WAAO,SAAS,UAAU,KAAK,IAAI;AAAA,EACrC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,IAAO,yBAAQ;","names":[]}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@worknice/utils",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "private": false,
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "LICENSE"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "require": "./dist/index.js"
19
+ },
20
+ "./*": {
21
+ "types": "./dist/*.d.ts",
22
+ "import": "./dist/*.js",
23
+ "require": "./dist/*.js"
24
+ }
25
+ },
26
+ "devDependencies": {
27
+ "@total-typescript/tsconfig": "^1.0.4",
28
+ "@typescript-eslint/eslint-plugin": "^8.7.0",
29
+ "@typescript-eslint/parser": "^8.7.0",
30
+ "eslint": "^8.57.1",
31
+ "temporal-polyfill": "^0.2.1",
32
+ "tsup": "^8.2.4",
33
+ "typescript": "~5.5.0"
34
+ },
35
+ "peerDependencies": {
36
+ "temporal-polyfill": "^0.2.1"
37
+ },
38
+ "scripts": {
39
+ "build": "rm -rf ./dist && tsup",
40
+ "dev": "rm -rf ./dist && tsup --watch",
41
+ "release": "pnpm dlx @jsdevtools/version-bump-prompt --commit \"chore(utils): release v%s\" --tag \"utils-v%s\"",
42
+ "test": "if [[ -z $TURBO_HASH ]]; then echo 'Use `pnpm turbo test` to run tests.\n' && exit 1; else exit 0; fi",
43
+ "test:lint": "eslint src --color",
44
+ "test:prettier": "prettier -c '**/*.{js,ts,tsx,css}'",
45
+ "test:types": "tsc --noEmit --pretty"
46
+ }
47
+ }