@pallasoft/ps-utilities 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ Pallasoft Proprietary License
2
+
3
+ Version 1.0, 23-Jan-2024
4
+
5
+ 1. Grant of License:
6
+ Pallasoft grants you a non-exclusive, non-transferable, revocable license to use the software, solely for internal business purposes.
7
+
8
+ 2. Restrictions:
9
+ You may not:
10
+ a. Distribute or sublicense the software to third parties.
11
+ b. Reverse engineer, decompile, or disassemble the software.
12
+ c. Remove or alter any proprietary notices or labels on the software.
13
+
14
+ 3. Ownership:
15
+ Pallasoft retains all right, title, and interest in and to the software, including all intellectual property rights.
16
+
17
+ 4. Confidentiality:
18
+ You agree to keep the software confidential and not disclose it to third parties.
19
+
20
+ 5. Support and Updates:
21
+ This license does not entitle you to support or updates. Pallasoft may, at its discretion, provide support and updates.
22
+
23
+ 6. Termination:
24
+ This license is effective until terminated. Pallasoft may terminate the license at any time if you breach any terms. Upon termination, you must cease using the software.
25
+
26
+ 7. Governing Law:
27
+ This license is governed by the Canadian Laws. Any disputes arising out of this license shall be resolved in the courts of Canada.
28
+
29
+ 8. Contact Information:
30
+ For inquiries regarding this license, contact operations@pallasoft.com.
31
+
32
+ [End of License]
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # PS-Utilities
2
+
3
+ [![License: Pallasoft Proprietary](https://img.shields.io/badge/License-Pallasoft_Proprietary-blue.svg)](LICENSE)
4
+
5
+ #### This library contains all the shared services used in Pallasoft's apps
@@ -0,0 +1,11 @@
1
+ import { Dayjs } from 'dayjs';
2
+ export declare class DateService {
3
+ static getDate(date?: string | number): Dayjs;
4
+ static getToday(): string;
5
+ static getTomorrow(): string;
6
+ static calculateTimeRemaining(date: string | number, placeholder: string): string;
7
+ static getNextWeek(): string;
8
+ static getNextMonth(): string;
9
+ static formatDateToString(date: string | number, short?: boolean): string;
10
+ static diffInMins(startDate: string | number, endDate: string | number): number;
11
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DateService = void 0;
7
+ var dayjs_1 = __importDefault(require("dayjs"));
8
+ var timezone_js_1 = __importDefault(require("dayjs/plugin/timezone.js"));
9
+ var utc_js_1 = __importDefault(require("dayjs/plugin/utc.js"));
10
+ dayjs_1.default.extend(utc_js_1.default);
11
+ dayjs_1.default.extend(timezone_js_1.default);
12
+ var DateService = /** @class */ (function () {
13
+ function DateService() {
14
+ }
15
+ DateService.getDate = function (date) {
16
+ if (date)
17
+ return (0, dayjs_1.default)(date);
18
+ return (0, dayjs_1.default)();
19
+ };
20
+ DateService.getToday = function () {
21
+ return (0, dayjs_1.default)().toISOString();
22
+ };
23
+ DateService.getTomorrow = function () {
24
+ return (0, dayjs_1.default)().add(1, 'day').toISOString();
25
+ };
26
+ DateService.calculateTimeRemaining = function (date, placeholder) {
27
+ var currentDate = (0, dayjs_1.default)();
28
+ var targetDate = (0, dayjs_1.default)(date);
29
+ var diffSeconds = targetDate.diff(currentDate, 'second');
30
+ if (diffSeconds <= 0) {
31
+ return placeholder;
32
+ }
33
+ var hours = Math.floor(diffSeconds / 3600);
34
+ var minutes = Math.floor((diffSeconds % 3600) / 60);
35
+ var seconds = diffSeconds % 60;
36
+ if (hours)
37
+ return "".concat(hours, "h ").concat(minutes, "m ").concat(seconds, "s");
38
+ if (minutes)
39
+ return "".concat(minutes, "m ").concat(seconds, "s");
40
+ return "".concat(seconds, "s");
41
+ };
42
+ DateService.getNextWeek = function () {
43
+ return (0, dayjs_1.default)().add(1, 'week').toISOString();
44
+ };
45
+ DateService.getNextMonth = function () {
46
+ return (0, dayjs_1.default)().add(1, 'month').toISOString();
47
+ };
48
+ DateService.formatDateToString = function (date, short) {
49
+ return (0, dayjs_1.default)(date).format(short ? 'DD MMM, YYYY' : 'DD MMMM, YYYY');
50
+ };
51
+ DateService.diffInMins = function (startDate, endDate) {
52
+ var start = (0, dayjs_1.default)(startDate);
53
+ var end = (0, dayjs_1.default)(endDate);
54
+ return end.diff(start, 'minutes');
55
+ };
56
+ return DateService;
57
+ }());
58
+ exports.DateService = DateService;
@@ -0,0 +1,3 @@
1
+ export * from './date-service';
2
+ export * from './url-service';
3
+ export * from './string-service';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./date-service"), exports);
18
+ __exportStar(require("./url-service"), exports);
19
+ __exportStar(require("./string-service"), exports);
@@ -0,0 +1,3 @@
1
+ export declare class StringService {
2
+ static cleanString(value: string): string;
3
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StringService = void 0;
4
+ var StringService = /** @class */ (function () {
5
+ function StringService() {
6
+ }
7
+ StringService.cleanString = function (value) {
8
+ return value.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
9
+ };
10
+ return StringService;
11
+ }());
12
+ exports.StringService = StringService;
@@ -0,0 +1,3 @@
1
+ export declare class TransformService {
2
+ static isArray(input: string): boolean;
3
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformService = void 0;
4
+ var TransformService = /** @class */ (function () {
5
+ function TransformService() {
6
+ }
7
+ TransformService.isArray = function (input) {
8
+ try {
9
+ var parsed = JSON.parse(input);
10
+ return Array.isArray(parsed);
11
+ }
12
+ catch (error) {
13
+ console.error(error);
14
+ return false;
15
+ }
16
+ };
17
+ return TransformService;
18
+ }());
19
+ exports.TransformService = TransformService;
@@ -0,0 +1,4 @@
1
+ export declare class URLService {
2
+ static updatePath: (key: string, value: string, doRemoveParams?: boolean) => string;
3
+ static saveToQueryParams(key: string, value: string | number): void;
4
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.URLService = void 0;
4
+ var URLService = /** @class */ (function () {
5
+ function URLService() {
6
+ }
7
+ URLService.saveToQueryParams = function (key, value) {
8
+ var url = this.updatePath(key, value.toString(), true);
9
+ window.history.replaceState({}, '', url);
10
+ };
11
+ URLService.updatePath = function (key, value, doRemoveParams) {
12
+ var queryParams = new URLSearchParams(location.search);
13
+ if (doRemoveParams && !value) {
14
+ queryParams.delete(key);
15
+ }
16
+ else
17
+ queryParams.set(key, value);
18
+ return "".concat(location.pathname, "?").concat(queryParams.toString());
19
+ };
20
+ return URLService;
21
+ }());
22
+ exports.URLService = URLService;
@@ -0,0 +1 @@
1
+ export * as Common from './common';
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Common = void 0;
37
+ exports.Common = __importStar(require("./common"));
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@pallasoft/ps-utilities",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "export": "/dist/index.js",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/pallasoft/ps-utilities.git"
12
+ },
13
+ "files": [
14
+ "/dist"
15
+ ],
16
+ "scripts": {
17
+ "husky:prepare": "npx husky",
18
+ "build": "tsc",
19
+ "lint": "npm run lint:eslint",
20
+ "lint:fix": "npm run lint:eslint:fix",
21
+ "format:check": "npx prettier --check --ignore-unknown \"src/**/*.{js,ts,json,md}\"",
22
+ "format:prettier": "npx prettier --write \"**/*.{js,ts,json,md}\"",
23
+ "lint:eslint": "npx eslint \"**/*.{js,ts}\"",
24
+ "lint:eslint:fix": "npx eslint --fix \"**/*.{js,ts}\""
25
+ },
26
+ "devDependencies": {
27
+ "@commitlint/cli": "^19.6.0",
28
+ "@commitlint/config-conventional": "^19.6.0",
29
+ "@eslint/compat": "^1.2.4",
30
+ "@ianvs/prettier-plugin-sort-imports": "^4.4.0",
31
+ "@typescript-eslint/eslint-plugin": "^8.17.0",
32
+ "@typescript-eslint/parser": "^8.17.0",
33
+ "commitlint": "^19.6.0",
34
+ "eslint": "^9.16.0",
35
+ "eslint-config-prettier": "^9.1.0",
36
+ "eslint-plugin-import": "^2.31.0",
37
+ "eslint-plugin-prettier": "^5.2.1",
38
+ "husky": "^9.1.7",
39
+ "lint-staged": "^15.2.10",
40
+ "prettier": "^3.4.2",
41
+ "ts-node": "^10.9.2",
42
+ "typescript": "^5.7.2"
43
+ },
44
+ "dependencies": {
45
+ "@esbuild-plugins/tsconfig-paths": "^0.1.2",
46
+ "dayjs": "^1.11.13",
47
+ "esbuild": "^0.24.0"
48
+ }
49
+ }