@lichens-innovation/ts-common 1.2.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +58 -0
  3. package/dist/index.d.ts +2 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/utils/date.utils.d.ts +9 -0
  8. package/dist/utils/date.utils.d.ts.map +1 -0
  9. package/dist/utils/date.utils.js +24 -0
  10. package/dist/utils/date.utils.js.map +1 -0
  11. package/dist/utils/errors.utils.d.ts +2 -0
  12. package/dist/utils/errors.utils.d.ts.map +1 -0
  13. package/dist/utils/errors.utils.js +13 -0
  14. package/dist/utils/errors.utils.js.map +1 -0
  15. package/dist/utils/http.utils.d.ts +4 -0
  16. package/dist/utils/http.utils.d.ts.map +1 -0
  17. package/dist/utils/http.utils.js +20 -0
  18. package/dist/utils/http.utils.js.map +1 -0
  19. package/dist/utils/index.d.ts +11 -0
  20. package/dist/utils/index.d.ts.map +1 -0
  21. package/dist/utils/index.js +11 -0
  22. package/dist/utils/index.js.map +1 -0
  23. package/dist/utils/number.utils.d.ts +2 -0
  24. package/dist/utils/number.utils.d.ts.map +1 -0
  25. package/dist/utils/number.utils.js +13 -0
  26. package/dist/utils/number.utils.js.map +1 -0
  27. package/dist/utils/regex.d.ts +2 -0
  28. package/dist/utils/regex.d.ts.map +1 -0
  29. package/dist/utils/regex.js +2 -0
  30. package/dist/utils/regex.js.map +1 -0
  31. package/dist/utils/string.utils.d.ts +17 -0
  32. package/dist/utils/string.utils.d.ts.map +1 -0
  33. package/dist/utils/string.utils.js +30 -0
  34. package/dist/utils/string.utils.js.map +1 -0
  35. package/dist/utils/thread.utils.d.ts +2 -0
  36. package/dist/utils/thread.utils.d.ts.map +1 -0
  37. package/dist/utils/thread.utils.js +2 -0
  38. package/dist/utils/thread.utils.js.map +1 -0
  39. package/dist/utils/time.utils.d.ts +7 -0
  40. package/dist/utils/time.utils.d.ts.map +1 -0
  41. package/dist/utils/time.utils.js +11 -0
  42. package/dist/utils/time.utils.js.map +1 -0
  43. package/dist/utils/types.utils.d.ts +5 -0
  44. package/dist/utils/types.utils.d.ts.map +1 -0
  45. package/dist/utils/types.utils.js +24 -0
  46. package/dist/utils/types.utils.js.map +1 -0
  47. package/dist/utils/units.utils.d.ts +16 -0
  48. package/dist/utils/units.utils.d.ts.map +1 -0
  49. package/dist/utils/units.utils.js +37 -0
  50. package/dist/utils/units.utils.js.map +1 -0
  51. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Lichens Innovation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # ts-common
2
+
3
+ Reusable generic typescript utilities, types, constants, helpers
4
+
5
+ [![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue.svg?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-LTS-green.svg?style=flat-square&logo=node.js)](https://nodejs.org/)
8
+ [![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
9
+ [![Vitest](https://img.shields.io/badge/Vitest-4.0-6E9F18.svg?style=flat-square&logo=vitest)](https://vitest.dev/)
10
+ [![Yarn](https://img.shields.io/badge/Yarn-1.22+-2C8EBB.svg?style=flat-square&logo=yarn)](https://yarnpkg.com/)
11
+
12
+ Table of content
13
+ - [ts-common](#ts-common)
14
+ - [Prerequisites](#prerequisites)
15
+ - [Scripts](#scripts)
16
+ - [Contributions](#contributions)
17
+ - [Unit tests](#unit-tests)
18
+ - [Library semantic versioning](#library-semantic-versioning)
19
+ - [Project coding guidelines](#project-coding-guidelines)
20
+
21
+ ## Prerequisites
22
+
23
+ - Node.js (LTS or higher)
24
+ - Yarn
25
+
26
+ ## Scripts
27
+
28
+ | Command | Description |
29
+ |------------------------------|-----------------------------------------------------------------------------|
30
+ | `yarn build` | Cleans the dist folder and compiles TypeScript |
31
+ | `yarn clean:node` | Removes node_modules directories and yarn.lock file |
32
+ | `yarn clean:dist` | Removes the dist directory |
33
+ | `yarn typecheck` | Checks TypeScript types without emitting files |
34
+ | `yarn test` | Runs tests using Vitest |
35
+ | `yarn test:coverage` | Runs tests with coverage report using Vitest |
36
+ | `yarn test:watch` | Runs tests in watch mode using Vitest |
37
+
38
+ ## Contributions
39
+
40
+ Contributions to the project are made by simply improving the current codebase and then creating a Pull Request. If the version field in `package.json` is incremented, the build will be automatically triggered when the PR is merged into the `main` branch, and the new version will be published to our enterprise Git repository.
41
+
42
+ ## Unit tests
43
+
44
+ Test coverage must be maintained at 80% or higher. It is therefore important to always attempt to cover new code that is added with appropriate tests.
45
+
46
+ ## Library semantic versioning
47
+
48
+ When there is a breaking change, [Semantic Versioning](https://semver.org/#summary) must be used to indicate that a major behavior has changed. Semantic Versioning follows the `MAJOR.MINOR.PATCH` format:
49
+
50
+ * `MAJOR` version when you make incompatible API changes
51
+ * `MINOR` version when you add functionality in a backward compatible manner
52
+ * `PATCH` version when you make backward compatible bug fixes
53
+
54
+ ## Project coding guidelines
55
+
56
+ Adhering to established coding guidelines is essential for developing efficient, maintainable, and scalable software. These guidelines promote consistency across codebases, making it easier for teams to collaborate and for new developers to understand existing code. By following standardized patterns, such as those outlined in the [Coding guidelines](https://github.com/amwebexpert/chrome-extensions-collection/blob/master/packages/coding-guide-helper/public/markdowns/table-of-content.md), developers can reduce errors and enhance code readability.
57
+
58
+ * [Coding guidelines](https://github.com/amwebexpert/chrome-extensions-collection/blob/master/packages/coding-guide-helper/public/markdowns/table-of-content.md)
@@ -0,0 +1,2 @@
1
+ export * from "./utils";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./utils";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ export type DateInput = Date | string | number | null;
2
+ export declare const dateAs_HHMMSS: (value?: DateInput) => string;
3
+ export declare const dateAs_YYYYMMDD: (value?: DateInput) => string;
4
+ export declare const dateAs_YYYYMMDD_HHMMSS: (value?: DateInput) => string;
5
+ export declare const nowAsTime: () => string;
6
+ export declare const nowAsDate: () => string;
7
+ export declare const nowAsDateTime: () => string;
8
+ export declare const nowAsDateTimeForFilename: () => string;
9
+ //# sourceMappingURL=date.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.utils.d.ts","sourceRoot":"","sources":["../../src/utils/date.utils.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAEtD,eAAO,MAAM,aAAa,GAAI,QAAQ,SAAS,WAG9C,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,QAAQ,SAAS,WAGhD,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,SAAS,WAGvD,CAAC;AAEF,eAAO,MAAM,SAAS,cAAkC,CAAC;AACzD,eAAO,MAAM,SAAS,cAAoC,CAAC;AAC3D,eAAO,MAAM,aAAa,cAA2C,CAAC;AAEtE,eAAO,MAAM,wBAAwB,cAEpC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { format } from "date-fns";
2
+ import { isNullish } from "./types.utils";
3
+ export const dateAs_HHMMSS = (value) => {
4
+ if (isNullish(value))
5
+ return "";
6
+ return format(value, "HH:mm:ss");
7
+ };
8
+ export const dateAs_YYYYMMDD = (value) => {
9
+ if (isNullish(value))
10
+ return "";
11
+ return format(value, "yyyy-MM-dd");
12
+ };
13
+ export const dateAs_YYYYMMDD_HHMMSS = (value) => {
14
+ if (isNullish(value))
15
+ return "";
16
+ return format(value, "yyyy-MM-dd HH:mm:ss");
17
+ };
18
+ export const nowAsTime = () => dateAs_HHMMSS(new Date());
19
+ export const nowAsDate = () => dateAs_YYYYMMDD(new Date());
20
+ export const nowAsDateTime = () => dateAs_YYYYMMDD_HHMMSS(new Date());
21
+ export const nowAsDateTimeForFilename = () => {
22
+ return format(new Date(), "yyyy-MM-dd_HH-mm-ss");
23
+ };
24
+ //# sourceMappingURL=date.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.utils.js","sourceRoot":"","sources":["../../src/utils/date.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAI1C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAiB,EAAE,EAAE;IACjD,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAE,EAAE;IACnD,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAiB,EAAE,EAAE;IAC1D,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,OAAO,MAAM,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,sBAAsB,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;AAEtE,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,OAAO,MAAM,CAAC,IAAI,IAAI,EAAE,EAAE,qBAAqB,CAAC,CAAC;AACnD,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const getErrorMessage: (error: unknown) => string;
2
+ //# sourceMappingURL=errors.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.utils.d.ts","sourceRoot":"","sources":["../../src/utils/errors.utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAchD,CAAC"}
@@ -0,0 +1,13 @@
1
+ export const getErrorMessage = (error) => {
2
+ if (!error) {
3
+ return "";
4
+ }
5
+ if (typeof error === "string") {
6
+ return error;
7
+ }
8
+ if (typeof error === "object" && "message" in error) {
9
+ return error.message;
10
+ }
11
+ return JSON.stringify(error);
12
+ };
13
+ //# sourceMappingURL=errors.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.utils.js","sourceRoot":"","sources":["../../src/utils/errors.utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAAU,EAAE;IACxD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;QACpD,OAAQ,KAA6B,CAAC,OAAO,CAAC;IAChD,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const isHttpSuccessStatus: (status?: number | null) => boolean;
2
+ export declare const isHttpClientErrorStatus: (status?: number | null) => boolean;
3
+ export declare const isHttpServerErrorStatus: (status?: number | null) => boolean;
4
+ //# sourceMappingURL=http.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.utils.d.ts","sourceRoot":"","sources":["../../src/utils/http.utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,GAAG,IAAI,KAAG,OAM5D,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,SAAS,MAAM,GAAG,IAAI,KAAG,OAMhE,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAI,SAAS,MAAM,GAAG,IAAI,KAAG,OAMhE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { isNullish } from './types.utils';
2
+ export const isHttpSuccessStatus = (status) => {
3
+ if (isNullish(status)) {
4
+ return false;
5
+ }
6
+ return status >= 200 && status < 300;
7
+ };
8
+ export const isHttpClientErrorStatus = (status) => {
9
+ if (isNullish(status)) {
10
+ return false;
11
+ }
12
+ return status >= 400 && status < 500;
13
+ };
14
+ export const isHttpServerErrorStatus = (status) => {
15
+ if (isNullish(status)) {
16
+ return false;
17
+ }
18
+ return status >= 500;
19
+ };
20
+ //# sourceMappingURL=http.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.utils.js","sourceRoot":"","sources":["../../src/utils/http.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAsB,EAAW,EAAE;IACrE,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAsB,EAAW,EAAE;IACzE,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC;AACvC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAsB,EAAW,EAAE;IACzE,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,MAAM,IAAI,GAAG,CAAC;AACvB,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ export * from './date.utils';
2
+ export * from './errors.utils';
3
+ export * from './http.utils';
4
+ export * from './number.utils';
5
+ export * from './regex';
6
+ export * from './string.utils';
7
+ export * from './thread.utils';
8
+ export * from './time.utils';
9
+ export * from './types.utils';
10
+ export * from './units.utils';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,11 @@
1
+ export * from './date.utils';
2
+ export * from './errors.utils';
3
+ export * from './http.utils';
4
+ export * from './number.utils';
5
+ export * from './regex';
6
+ export * from './string.utils';
7
+ export * from './thread.utils';
8
+ export * from './time.utils';
9
+ export * from './types.utils';
10
+ export * from './units.utils';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const toFixed: (value?: number | null, decimals?: number) => number;
2
+ //# sourceMappingURL=number.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.utils.d.ts","sourceRoot":"","sources":["../../src/utils/number.utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,GAAI,QAAQ,MAAM,GAAG,IAAI,EAAE,iBAAY,KAAG,MAO7D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { isNullish } from "./types.utils";
2
+ // Example: toFixed(3.14159, 3) // 3.142
3
+ export const toFixed = (value, decimals = 0) => {
4
+ if (isNullish(value))
5
+ return 0;
6
+ if (decimals < 0)
7
+ throw new Error("[toFixed] decimals must be >= 0");
8
+ if (decimals === 0)
9
+ return Math.round(value);
10
+ const multiplier = Math.pow(10, decimals);
11
+ return Math.round(value * multiplier) / multiplier;
12
+ };
13
+ //# sourceMappingURL=number.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.utils.js","sourceRoot":"","sources":["../../src/utils/number.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,wCAAwC;AACxC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAqB,EAAE,QAAQ,GAAG,CAAC,EAAU,EAAE;IACrE,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC/B,IAAI,QAAQ,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrE,IAAI,QAAQ,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAE7C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC1C,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;AACrD,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const REGEX_ALPHANUMERIC: RegExp;
2
+ //# sourceMappingURL=regex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/utils/regex.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,QAAgC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const REGEX_ALPHANUMERIC = /^[a-zA-Z0-9-_ $%#(){}:/.]+$/;
2
+ //# sourceMappingURL=regex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex.js","sourceRoot":"","sources":["../../src/utils/regex.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,6BAA6B,CAAC"}
@@ -0,0 +1,17 @@
1
+ export declare const isBlank: (str?: string | null) => str is null | undefined | "";
2
+ export declare const isNotBlank: (str?: string | null) => str is string;
3
+ export declare const isAlphanumeric: (value: string) => boolean;
4
+ /**
5
+ * Removes diacritical marks (e.g., accents, umlauts) from a string.
6
+ * This method normalizes the input string to its canonical decomposition
7
+ * form (NFD) and removes any combining diacritical marks.
8
+ *
9
+ * @param {string} value - The input string to normalize.
10
+ * @returns {string} - The normalized string with diacritical marks removed.
11
+ *
12
+ * @example
13
+ * const result = removeDiacriticalMarks("Ça va très bien, n'est-ce pas?");
14
+ * console.log(result); // "Ca va tres bien, n'est-ce pas?"
15
+ */
16
+ export declare const removeDiacriticalMarks: (value: string) => string;
17
+ //# sourceMappingURL=string.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.utils.d.ts","sourceRoot":"","sources":["../../src/utils/string.utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,GAAI,MAAM,MAAM,GAAG,IAAI,KAAG,GAAG,IAAI,IAAI,GAAG,SAAS,GAAG,EAEvE,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,GAAG,IAAI,KAAG,GAAG,IAAI,MAEvD,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,OAE9C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,KAAG,MAMtD,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { REGEX_ALPHANUMERIC } from './regex';
2
+ import { isNullish } from './types.utils';
3
+ export const isBlank = (str) => {
4
+ return isNullish(str) || str?.trim() === '';
5
+ };
6
+ export const isNotBlank = (str) => {
7
+ return !isBlank(str);
8
+ };
9
+ export const isAlphanumeric = (value) => {
10
+ return REGEX_ALPHANUMERIC.test(value);
11
+ };
12
+ /**
13
+ * Removes diacritical marks (e.g., accents, umlauts) from a string.
14
+ * This method normalizes the input string to its canonical decomposition
15
+ * form (NFD) and removes any combining diacritical marks.
16
+ *
17
+ * @param {string} value - The input string to normalize.
18
+ * @returns {string} - The normalized string with diacritical marks removed.
19
+ *
20
+ * @example
21
+ * const result = removeDiacriticalMarks("Ça va très bien, n'est-ce pas?");
22
+ * console.log(result); // "Ca va tres bien, n'est-ce pas?"
23
+ */
24
+ export const removeDiacriticalMarks = (value) => {
25
+ if (!value) {
26
+ return '';
27
+ }
28
+ return value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
29
+ };
30
+ //# sourceMappingURL=string.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../src/utils/string.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAmB,EAAgC,EAAE;IAC3E,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC9C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAmB,EAAiB,EAAE;IAC/D,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAW,EAAE;IACvD,OAAO,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAU,EAAE;IAC9D,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AAChE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const sleep: (milliseconds: number) => Promise<unknown>;
2
+ //# sourceMappingURL=thread.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.utils.d.ts","sourceRoot":"","sources":["../../src/utils/thread.utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,cAAc,MAAM,qBACmB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
2
+ //# sourceMappingURL=thread.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.utils.js","sourceRoot":"","sources":["../../src/utils/thread.utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,YAAoB,EAAE,EAAE,CAC5C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const PeriodsInMS: {
2
+ readonly oneSecond: 1000;
3
+ readonly oneMinute: number;
4
+ readonly oneHour: number;
5
+ readonly oneDay: number;
6
+ };
7
+ //# sourceMappingURL=time.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.utils.d.ts","sourceRoot":"","sources":["../../src/utils/time.utils.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW;;;;;CAKd,CAAC"}
@@ -0,0 +1,11 @@
1
+ const ONE_SECOND_IN_MS = 1000;
2
+ const ONE_MINUTE_IN_MS = 60 * ONE_SECOND_IN_MS;
3
+ const ONE_HOUR_IN_MS = 60 * ONE_MINUTE_IN_MS;
4
+ const ONE_DAY_IN_MS = 24 * ONE_HOUR_IN_MS;
5
+ export const PeriodsInMS = {
6
+ oneSecond: ONE_SECOND_IN_MS,
7
+ oneMinute: ONE_MINUTE_IN_MS,
8
+ oneHour: ONE_HOUR_IN_MS,
9
+ oneDay: ONE_DAY_IN_MS,
10
+ };
11
+ //# sourceMappingURL=time.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.utils.js","sourceRoot":"","sources":["../../src/utils/time.utils.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,gBAAgB,GAAG,EAAE,GAAG,gBAAgB,CAAC;AAC/C,MAAM,cAAc,GAAG,EAAE,GAAG,gBAAgB,CAAC;AAC7C,MAAM,aAAa,GAAG,EAAE,GAAG,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,SAAS,EAAE,gBAAgB;IAC3B,SAAS,EAAE,gBAAgB;IAC3B,OAAO,EAAE,cAAc;IACvB,MAAM,EAAE,aAAa;CACb,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const NO_OP: () => void;
2
+ export declare const isNullish: (value: unknown) => value is null | undefined;
3
+ export declare const isNumber: (value?: unknown | null) => value is number;
4
+ export declare const isString: (value?: unknown | null) => value is string;
5
+ //# sourceMappingURL=types.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.utils.d.ts","sourceRoot":"","sources":["../../src/utils/types.utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,EAAE,MAAM,IAAe,CAAC;AAE1C,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,IAAI,GAAG,SAAkD,CAAC;AAE9G,eAAO,MAAM,QAAQ,GAAI,QAAQ,OAAO,GAAG,IAAI,KAAG,KAAK,IAAI,MAc1D,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,QAAQ,OAAO,GAAG,IAAI,KAAG,KAAK,IAAI,MAU1D,CAAC"}
@@ -0,0 +1,24 @@
1
+ export const NO_OP = () => { };
2
+ export const isNullish = (value) => value === null || value === undefined;
3
+ export const isNumber = (value) => {
4
+ if (isNullish(value)) {
5
+ return false;
6
+ }
7
+ if (typeof value !== 'number') {
8
+ return false;
9
+ }
10
+ if (isNaN(value)) {
11
+ return false;
12
+ }
13
+ return true;
14
+ };
15
+ export const isString = (value) => {
16
+ if (isNullish(value)) {
17
+ return false;
18
+ }
19
+ if (typeof value !== 'string') {
20
+ return false;
21
+ }
22
+ return true;
23
+ };
24
+ //# sourceMappingURL=types.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.utils.js","sourceRoot":"","sources":["../../src/utils/types.utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAe,GAAG,EAAE,GAAE,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAA6B,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAE9G,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAsB,EAAmB,EAAE;IAClE,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAsB,EAAmB,EAAE;IAClE,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ /** m³/s to gallons per minute */
2
+ export declare const M3PS_TO_GPM = 15850.3;
3
+ /** Pascals to feet of head (1 Pa = 1 N/m²) */
4
+ export declare const PA_TO_FT = 0.000334553;
5
+ /** Watts to Horsepower */
6
+ export declare const W_TO_HP = 0.00134102;
7
+ /** meters to inches */
8
+ export declare const M_TO_INCHES = 39.3701;
9
+ /** Hz to RPM (for synchronous speed) */
10
+ export declare const HZ_TO_RPM = 60;
11
+ export declare const fromM3psToGPM: (value?: number | null) => number;
12
+ export declare const fromPaToFt: (value?: number | null) => number;
13
+ export declare const fromWToHp: (value?: number | null) => number;
14
+ export declare const fromMToInches: (value?: number | null) => number;
15
+ export declare const fromHzToRpm: (value?: number | null) => number;
16
+ //# sourceMappingURL=units.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.utils.d.ts","sourceRoot":"","sources":["../../src/utils/units.utils.ts"],"names":[],"mappings":"AAEA,iCAAiC;AACjC,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,8CAA8C;AAC9C,eAAO,MAAM,QAAQ,cAAc,CAAC;AAEpC,0BAA0B;AAC1B,eAAO,MAAM,OAAO,aAAa,CAAC;AAElC,uBAAuB;AACvB,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,wCAAwC;AACxC,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,GAAG,IAAI,KAAG,MAIrD,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,GAAG,IAAI,KAAG,MAIlD,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,GAAG,IAAI,KAAG,MAIjD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,GAAG,IAAI,KAAG,MAIrD,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,GAAG,IAAI,KAAG,MAInD,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { isNullish } from "./types.utils";
2
+ /** m³/s to gallons per minute */
3
+ export const M3PS_TO_GPM = 15850.3;
4
+ /** Pascals to feet of head (1 Pa = 1 N/m²) */
5
+ export const PA_TO_FT = 0.000334553;
6
+ /** Watts to Horsepower */
7
+ export const W_TO_HP = 0.00134102;
8
+ /** meters to inches */
9
+ export const M_TO_INCHES = 39.3701;
10
+ /** Hz to RPM (for synchronous speed) */
11
+ export const HZ_TO_RPM = 60;
12
+ export const fromM3psToGPM = (value) => {
13
+ if (isNullish(value))
14
+ return 0;
15
+ return value * M3PS_TO_GPM;
16
+ };
17
+ export const fromPaToFt = (value) => {
18
+ if (isNullish(value))
19
+ return 0;
20
+ return value * PA_TO_FT;
21
+ };
22
+ export const fromWToHp = (value) => {
23
+ if (isNullish(value))
24
+ return 0;
25
+ return value * W_TO_HP;
26
+ };
27
+ export const fromMToInches = (value) => {
28
+ if (isNullish(value))
29
+ return 0;
30
+ return value * M_TO_INCHES;
31
+ };
32
+ export const fromHzToRpm = (value) => {
33
+ if (isNullish(value))
34
+ return 0;
35
+ return value * HZ_TO_RPM;
36
+ };
37
+ //# sourceMappingURL=units.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.utils.js","sourceRoot":"","sources":["../../src/utils/units.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,iCAAiC;AACjC,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC;AAEpC,0BAA0B;AAC1B,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC;AAElC,uBAAuB;AACvB,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,wCAAwC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC7D,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAE/B,OAAO,KAAK,GAAG,WAAW,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC1D,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAE/B,OAAO,KAAK,GAAG,QAAQ,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAqB,EAAU,EAAE;IACzD,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAE/B,OAAO,KAAK,GAAG,OAAO,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC7D,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAE/B,OAAO,KAAK,GAAG,WAAW,CAAC;AAC7B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC3D,IAAI,SAAS,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAE/B,OAAO,KAAK,GAAG,SAAS,CAAC;AAC3B,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@lichens-innovation/ts-common",
3
+ "version": "1.2.1",
4
+ "description": "Reusable generic typescript utilities, types, constants, helpers",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "repository": "git@github.com:Lichens-Innovation/ts-common.git",
11
+ "author": "Lichens Innovation",
12
+ "license": "MIT",
13
+ "type": "module",
14
+ "scripts": {
15
+ "clean:node": "npx rimraf node_modules yarn.lock",
16
+ "clean:dist": "npx rimraf dist",
17
+ "typecheck": "npx tsc --noEmit",
18
+ "build": "npm run clean:dist && tsc",
19
+ "test": "vitest run --coverage",
20
+ "test:watch": "vitest",
21
+ "test:coverage": "vitest run --coverage"
22
+ },
23
+ "dependencies": {
24
+ "date-fns": "^3.0.0"
25
+ },
26
+ "devDependencies": {
27
+ "@eslint/js": "^9.39.1",
28
+ "@faker-js/faker": "^10.1.0",
29
+ "@types/node": "^24.10.0",
30
+ "@vitest/coverage-v8": "4.0.8",
31
+ "commitlint": "^20.1.0",
32
+ "cross-env": "^10.1.0",
33
+ "eslint": "^9.39.1",
34
+ "husky": "^9.1.7",
35
+ "prettier": "^3.6.2",
36
+ "rimraf": "^6.1.0",
37
+ "typescript": "~5.9.3",
38
+ "typescript-eslint": "^8.46.3",
39
+ "vite": "^7.2.2",
40
+ "vite-tsconfig-paths": "^5.1.4",
41
+ "vitest": "^4.0.8"
42
+ }
43
+ }