@collana-solutions/javascript-utils 0.0.0-stage → 2.6.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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 collana solutions AG (formerly Neolution AG)
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 CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # javascript-utils
2
+
3
+ This is a collection of utilities that we have created to help with our development process. We have decided to open source these utilities in the hopes that they will be useful to others.
4
+
5
+ ## Usage
6
+
7
+ To use these utilities, add the [@collana-solutions/javascript-utils](https://www.npmjs.com/package/@collana-solutions/javascript-utils) npm package to your project and use the desired functions in your source code.
8
+
9
+ ```shell
10
+ npm install @collana-solutions/javascript-utils
11
+ ```
12
+
13
+ ```ts
14
+ import { newGuid } from "@collana-solutions/javascript-utils";
15
+ ```
16
+
17
+ Versions up to 2.6.0 were published as `@neolution-ch/javascript-utils`. That name is deprecated and gets no new releases.
18
+
19
+ ## Contributing
20
+
21
+ If you would like to contribute to this project, please submit a pull request.
22
+
23
+ ### Guidelines
24
+
25
+ - Use a filename that fits what the utility is doing. If you introduce a new file, choose a name that fits your utility but is still generic enough to hold similar utilities that can be added later alongside your addition.
26
+ - Add tests to your utilities and strive to cover many different usage scenarios and parametrization and high code coverage.
27
+
28
+ ### Development
29
+
30
+ The repository uses pnpm through Corepack (`corepack enable`), with the version pinned in `package.json`. `pnpm run prepare-pr` formats, lints, builds and tests in one go.
31
+
32
+ ## Releases
33
+
34
+ Due to the nature of this project as a loosely connected collection of utilities, it's important to be strict about following [SemVer](https://semver.org/) to communicate possible breaking changes to the users of this library via version number.
35
+
36
+ Equally as important is to be precise about the changes made in each release, so users of this library can see easily where changes were made. Releases follow the [collana-solutions release playbook](https://github.com/collana-solutions/release-playbook) (Changesets, public npm variant):
37
+
38
+ 1. Add a changeset to your PR with `pnpm changeset`: pick the SemVer bump and describe the change for the users of this library. CI fails without one.
39
+ 2. Merging to `main` opens or updates a **chore: version packages** PR, which bumps the version and writes the [CHANGELOG.md](CHANGELOG.md).
40
+ 3. Merging that PR publishes the package to npm through trusted publishing and creates the GitHub Release.
41
+
42
+ Dependabot PRs get a changeset generated automatically. A manual dependency bump does not, so add one yourself.
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("date-fns");function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var r=t(require("uuid"));function n(e){return!e||"string"!=typeof e||0===e.length}function i(e){return n(e)||0===e.trim().length}function a(e,t){if(n(e)||n(t))return e;let r=0;for(;e.indexOf(t,r)===r;)r+=t.length;return e.slice(r)}function o(e,t){if(n(e)||n(t))return e;let r=e.length,i=-1;for(;i=e.lastIndexOf(t,r-1),-1!==i&&i+t.length===r;){if(0===i)return"";r=i}return e.slice(0,r)}function s(e,t){let r=e[t];return void 0===r&&c(e)&&(r=Object.keys(e)[Object.values(e).indexOf(t)]),r}function u(e,t){return e[t]}function c(e){for(const t in e)return!/^\d+$/.test(t);return!1}function f(t){return e.isDate(t)&&e.isValid(t)}const l=r.NIL,p=()=>{if("undefined"==typeof localStorage)throw new TypeError("localStorage not supported")};function m(e,t){const r=e.toLowerCase().trim();return r.startsWith(`${t}/`)&&r.length>t.length+1}const d=e=>!("object"!=typeof e||null===e||Array.isArray(e)||e instanceof RegExp||e instanceof Date),x=e=>{if(Array.isArray(e))for(const t of e)null===t?e[e.indexOf(t)]=void 0:d(t)&&x(t);else if(!d(e))return;for(const t of Object.keys(e)){const r=e[t];null===r?delete e[t]:(d(r)||Array.isArray(r))&&x(r)}};function g(e){if(i(e))return!1;const t=new RegExp(/^CH[0-9]{2} [0-9]{4} [0-9][A-Z0-9]{3} [A-Z0-9]{4} [A-Z0-9]{4} [A-Z0-9]$/),r=new RegExp(/^CH[0-9]{7}[A-Z0-9]{12}$/);if(!t.test(e)&&!r.test(e))return!1;const n=e.replaceAll(" ",""),a=(n.slice(4)+n.slice(0,4)).replaceAll(/[A-Z]/g,(e=>(e.codePointAt(0)-55).toString()));let o=0;for(const e of a)o=(10*o+Number(e))%97;return 1===o}function N(e){if(i(e))return!1;const t=new RegExp(/^756\.\d{4}\.\d{4}\.\d{2}$/),r=new RegExp(/^756\d{10}$/);if(!t.test(e)&&!r.test(e))return!1;const n=e.replaceAll(".",""),a=[...[...n.slice(0,-1)].reverse().join("")];let o=0;for(const[e,t]of a.entries())o+=e%2==0?3*Number(t):1*Number(t);return(10-o%10)%10===Number.parseInt(n.slice(-1))}exports.CacheProvider=class{enumVariable;cacheName;cache=new Map;constructor(e,t){this.enumVariable=e,this.cacheName=t}createCacheKey(e,t){let r=s(this.enumVariable,e);return t&&!i(t)&&(r=`${r}_${t}`),`${this.cacheName}:${r}`}getObject(e,t){return this.cache.get(this.createCacheKey(e,t))}setObject(e,t,r){this.cache.set(this.createCacheKey(e,t),r)}reset(e,t){this.cache.delete(this.createCacheKey(e,t))}},exports.addQuarters=function(t,r){return f(t)?e.addQuarters(t,r):new Date(Number.NaN)},exports.capitalize=function(e){return!e||i(e)?e:e.charAt(0).toUpperCase()+e.slice(1)},exports.clamp=function(e,t,r){if(t>r)throw new Error(`'${t}' cannot be greater than '${r}'.`);return Math.min(Math.max(e,t),r)},exports.convertNullToUndefined=x,exports.dateDifferenceInDays=function(t,r){return f(t)&&f(r)?Math.abs(e.differenceInCalendarDays(t,r)):Number.NaN},exports.dateIsFirstDayOfMonth=function(t){return f(t)&&e.isFirstDayOfMonth(t)},exports.dateIsLastDayOfMonth=function(t){return f(t)&&e.isLastDayOfMonth(t)},exports.dateIsLeapYear=function(t){return f(t)&&e.isLeapYear(t)},exports.dateIsValid=f,exports.dateIsWeekend=function(t){return f(t)&&e.isWeekend(t)},exports.emptyGuid=l,exports.getDateAddTimeZone=function(e){return f(e)?new Date(e.getTime()+6e4*e.getTimezoneOffset()):new Date(Number.NaN)},exports.getDateWithoutTimeZone=function(e){return f(e)?new Date(e.getTime()-6e4*e.getTimezoneOffset()):new Date(Number.NaN)},exports.getEndOfDay=function(t){return f(t)?e.endOfDay(t):new Date(Number.NaN)},exports.getEnumNameFromValue=s,exports.getEnumNames=function(e){const t=Object.values(e);return c(e)?Object.keys(e):t.slice(0,t.length/2)},exports.getEnumValueFromName=u,exports.getEnumValues=function(e){const t=Object.keys(e);return c(e)?Object.values(e):t.slice(0,t.length/2).map((e=>Number.parseInt(e)))},exports.getFirstDayOfYear=function(e){return f(e)?new Date(e.getFullYear(),0,1):new Date(Number.NaN)},exports.getLastDayOfYear=function(t){return f(t)?e.lastDayOfYear(t):new Date(Number.NaN)},exports.getLocalStorageItem=function(e){p();const t=localStorage.getItem(e);if(!t)return;const r=JSON.parse(t);if(r.expirationDate){const t=new Date(r.expirationDate);if(f(t)&&t<new Date)return void localStorage.removeItem(e)}return r.data},exports.getNextBusinessDate=function(t){return f(t)?e.addBusinessDays(t,1):new Date(Number.NaN)},exports.getQuarter=function(t){return f(t)?e.getQuarter(t):Number.NaN},exports.getStartOfDay=function(t){return f(t)?e.startOfDay(t):new Date(Number.NaN)},exports.isApplicationMimeType=function(e){return!n(e)&&m(e,"application")},exports.isAudioMimeType=function(e){return!n(e)&&m(e,"audio")},exports.isImageMimeType=function(e){return!n(e)&&m(e,"image")},exports.isNullOrEmpty=n,exports.isNullOrWhitespace=i,exports.isObject=d,exports.isPdfMimeType=function(e){return!n(e)&&"application/pdf"===e.toLowerCase().trim()},exports.isTextMimeType=function(e){return!n(e)&&m(e,"text")},exports.isValidGuid=function(e){return"string"==typeof e&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)},exports.isValidSwissIbanNumber=g,exports.isValidSwissSocialInsuranceNumber=N,exports.isVideoMimeType=function(e){return!n(e)&&m(e,"video")},exports.newGuid=function(){return r.v4()},exports.parseBool=function(e){return!n(e)&&"true"===e?.replace(/[\s\0]/g,"").toLowerCase()},exports.parseEnum=function(e,t){if(c(e)||!Number.isNaN(Number(t)))return u(e,s(e,t))},exports.removeLocalStorageItem=function(e){p(),localStorage.removeItem(e)},exports.roundPrecision=function(e,t){const r=Math.pow(10,t);return Math.round(e*r)/r},exports.setLocalStorageItem=function(e,t,r){p(),localStorage.setItem(e,JSON.stringify({data:t,expirationDate:r}))},exports.splitLines=function(e,t=!1,r=!1){if(n(e))return[];let i=e.split(/\r\n|\r|\n/);return r&&(i=i.map((e=>e.trim()))),t&&(i=i.filter((e=>e.length>0))),i},exports.trim=function(e,t){return o(a(e,t),t)},exports.trimEnd=o,exports.trimStart=a,exports.truncate=function(e,t,r=""){return!e||i(e)||e.length<=t?e:`${e.slice(0,t)}${r}`},exports.tryParseSwissIbanNumber=function(e){if(i(e))return{isValid:!1};const t=e.replaceAll(/[^A-Z0-9]/gi,"").toUpperCase(),r=g(t);return{isValid:r,iban:r?t:void 0,ibanFormatted:r?t.match(/.{1,4}/g)?.join(" "):void 0}},exports.tryParseSwissSocialInsuranceNumber=function(e){if(i(e))return{isValid:!1};const t=e.replaceAll(/\D/g,""),r=N(t);return{isValid:r,swissSocialInsuranceNumber:r?t:void 0,swissSocialInsuranceNumberFormatted:r?t.replace(/^(\d{3})(\d{4})(\d{4})(\d{2})$/,"$1.$2.$3.$4"):void 0}},exports.uncapitalize=function(e){return!e||i(e)?e:e.charAt(0).toLowerCase()+e.slice(1)};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/lib/string.ts","../src/lib/enum.ts","../src/lib/date.ts","../src/lib/guid.ts","../src/lib/localStorage.ts","../src/lib/mimeType.ts","../src/lib/object.ts","../src/lib/swissStandards.ts","../src/lib/cacheProvider.ts","../src/lib/number.ts","../src/lib/boolean.ts"],"sourcesContent":["/**\r\n * Indicates whether a specified string is null/undefined or empty\r\n * @param value The string to test\r\n * @returns true if the value parameter is null/undefined or empty\r\n */\r\nexport function isNullOrEmpty(value?: string): boolean {\r\n if (!value || typeof value !== \"string\") {\r\n return true;\r\n }\r\n\r\n return value.length === 0;\r\n}\r\n\r\n/**\r\n * Indicates whether a specified string is null/undefined, empty, or consists only of white-space characters\r\n * @param value The string to test\r\n * @returns true if the value parameter is null/undefined, Empty, or if value consists exclusively of white-space characters\r\n */\r\nexport function isNullOrWhitespace(value?: string): boolean {\r\n return isNullOrEmpty(value) || (value as string).trim().length === 0;\r\n}\r\n\r\n/**\r\n * Capitalize the string\r\n * @param value The string to capitalize\r\n * @returns The capitalized string\r\n */\r\nexport function capitalize(value?: string): string | undefined {\r\n if (!value || isNullOrWhitespace(value)) {\r\n return value;\r\n }\r\n\r\n return value.charAt(0).toUpperCase() + value.slice(1);\r\n}\r\n\r\n/**\r\n * Uncapitalize the string\r\n * @param value The string to uncapitalize\r\n * @returns The uncapitalized string\r\n */\r\nexport function uncapitalize(value?: string): string | undefined {\r\n if (!value || isNullOrWhitespace(value)) {\r\n return value;\r\n }\r\n\r\n return value.charAt(0).toLowerCase() + value.slice(1);\r\n}\r\n\r\n/**\r\n * Truncates a string to a maximum length, adding a suffix if truncated\r\n * @param value The string to truncate\r\n * @param maxLength The maximum length of the resulting string\r\n * @param suffix The suffix to append if truncated (default: \"\")\r\n * @returns The truncated string\r\n */\r\nexport function truncate(value: string | undefined, maxLength: number, suffix = \"\"): string | undefined {\r\n if (!value || isNullOrWhitespace(value)) {\r\n return value;\r\n }\r\n\r\n if (value.length <= maxLength) {\r\n return value;\r\n }\r\n\r\n return `${value.slice(0, maxLength)}${suffix}`;\r\n}\r\n\r\n/**\r\n * Removes all occurrences of needle from the start of haystack\r\n * @param haystack string to trim\r\n * @param needle the thing to trim\r\n * @returns the string trimmed from the left side\r\n */\r\nexport function trimStart(haystack: string, needle: string): string {\r\n if (isNullOrEmpty(haystack) || isNullOrEmpty(needle)) {\r\n return haystack;\r\n }\r\n\r\n let offset = 0;\r\n\r\n while (haystack.indexOf(needle, offset) === offset) {\r\n offset = offset + needle.length;\r\n }\r\n return haystack.slice(offset);\r\n}\r\n\r\n/**\r\n * Removes all occurrences of needle from the end of haystack\r\n * @param haystack string to trim\r\n * @param needle the thing to trim\r\n * @returns the string trimmed from the right side\r\n */\r\nexport function trimEnd(haystack: string, needle: string): string {\r\n if (isNullOrEmpty(haystack) || isNullOrEmpty(needle)) {\r\n return haystack;\r\n }\r\n\r\n let offset = haystack.length,\r\n idx = -1;\r\n\r\n while (true) {\r\n idx = haystack.lastIndexOf(needle, offset - 1);\r\n if (idx === -1 || idx + needle.length !== offset) {\r\n break;\r\n }\r\n if (idx === 0) {\r\n return \"\";\r\n }\r\n offset = idx;\r\n }\r\n\r\n return haystack.slice(0, offset);\r\n}\r\n\r\n/**\r\n * Removes all occurrences of needle from the start and the end of haystack\r\n * @param haystack string to trim\r\n * @param needle the thing to trim\r\n * @returns the string trimmed from the right and left side\r\n */\r\nexport function trim(haystack: string, needle: string): string {\r\n const trimmed = trimStart(haystack, needle);\r\n return trimEnd(trimmed, needle);\r\n}\r\n\r\n/**\r\n * Splits the string at line breaks\r\n * @param str the string to split\r\n * @param removeEmptyEntries the option to remove empty entries\r\n * @param trimEntries the option to trim the entries\r\n * @returns the individual lines as an array\r\n */\r\nexport function splitLines(str: string, removeEmptyEntries: boolean = false, trimEntries: boolean = false): string[] {\r\n if (isNullOrEmpty(str)) {\r\n return [];\r\n }\r\n\r\n let splitted = str.split(/\\r\\n|\\r|\\n/);\r\n\r\n if (trimEntries) {\r\n splitted = splitted.map((x) => x.trim());\r\n }\r\n\r\n if (removeEmptyEntries) {\r\n splitted = splitted.filter((line) => line.length > 0);\r\n }\r\n\r\n return splitted;\r\n}\r\n","/**\r\n * The standard enum type\r\n */\r\nexport type StandardEnum<T> = {\r\n [id: string]: T | string;\r\n [nu: number]: string;\r\n};\r\n\r\n/**\r\n * Returns the name of an enum from its value\r\n * @param enumVariable The enum for which you want to get the name\r\n * @param enumValue The value of the enum for which you want to get the name\r\n * @returns A string containing the name of the enum\r\n */\r\nexport function getEnumNameFromValue<T>(enumVariable: StandardEnum<T>, enumValue: T): string {\r\n let result = enumVariable[enumValue as keyof StandardEnum<T>] as string;\r\n\r\n if (result === undefined && isEnumString(enumVariable)) {\r\n result = Object.keys(enumVariable)[Object.values(enumVariable).indexOf(enumValue)];\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Returns the value of an enum from its name\r\n * @param enumVariable The enum for which you want to get the value\r\n * @param enumName The name of the enum for which you want to get the value\r\n * @returns A string containing the value of the enum\r\n */\r\nexport function getEnumValueFromName<T>(enumVariable: StandardEnum<T>, enumName: string): T {\r\n return enumVariable[enumName as keyof StandardEnum<T>] as T;\r\n}\r\n\r\n/**\r\n * Returns all the names of an enum\r\n * @param enumVariable The enum for which you want to get the names\r\n * @returns A string array containing the names of the enum\r\n */\r\nexport function getEnumNames<T>(enumVariable: StandardEnum<T>) {\r\n const names = Object.values(enumVariable);\r\n\r\n // If enum is with values integer, object.values returns a list of [names, values].\r\n return isEnumString(enumVariable) ? Object.keys(enumVariable) : names.slice(0, names.length / 2);\r\n}\r\n\r\n/**\r\n * Returns all the values of an enum\r\n * @param enumVariable The enum for which you want to get the values\r\n * @returns A string or number array containing the values of the enum\r\n */\r\nexport function getEnumValues<T>(enumVariable: StandardEnum<T>): T[] {\r\n const keys = Object.keys(enumVariable);\r\n\r\n // If enum is with values integer, object.keys returns a list of [values, names].\r\n return (\r\n isEnumString(enumVariable) ? Object.values(enumVariable) : keys.slice(0, keys.length / 2).map((value) => Number.parseInt(value))\r\n ) as T[];\r\n}\r\n\r\n/**\r\n * Parses a string to an enum value\r\n * @param enumVariable The enum for which you want to get the values\r\n * @param value The string to parse\r\n * @returns The enum value corresponding to the string, or undefined if not found\r\n */\r\nexport function parseEnum<T>(enumVariable: StandardEnum<T>, value: string): T | undefined {\r\n if (!isEnumString(enumVariable) && Number.isNaN(Number(value))) {\r\n return undefined;\r\n }\r\n\r\n return getEnumValueFromName(enumVariable, getEnumNameFromValue(enumVariable, value as T));\r\n}\r\n\r\n/**\r\n * Returns if it's a enum with string value\r\n * @param enumVariable The enum\r\n * @returns A bool\r\n */\r\nfunction isEnumString<T>(enumVariable: StandardEnum<T>) {\r\n for (const key in enumVariable) {\r\n return !/^\\d+$/.test(key);\r\n }\r\n\r\n return false;\r\n}\r\n","import {\r\n isDate,\r\n isValid,\r\n isFirstDayOfMonth,\r\n isLastDayOfMonth,\r\n isLeapYear,\r\n isWeekend,\r\n differenceInCalendarDays,\r\n addBusinessDays,\r\n startOfDay,\r\n endOfDay,\r\n lastDayOfYear,\r\n getQuarter as getQuarterInternal,\r\n addQuarters as addQuartersInternal,\r\n} from \"date-fns\";\r\n\r\n/**\r\n * Check whether the date is valid\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is valid\r\n */\r\nexport function dateIsValid(date: Date): boolean {\r\n return isDate(date) && isValid(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is the first day of the month\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is the first day of the month\r\n */\r\nexport function dateIsFirstDayOfMonth(date: Date): boolean {\r\n return dateIsValid(date) && isFirstDayOfMonth(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is the last day of the month\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is the last day of the month\r\n */\r\nexport function dateIsLastDayOfMonth(date: Date): boolean {\r\n return dateIsValid(date) && isLastDayOfMonth(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is a leap year\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is a leap year\r\n */\r\nexport function dateIsLeapYear(date: Date): boolean {\r\n return dateIsValid(date) && isLeapYear(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is a weekend\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is a weekend\r\n */\r\nexport function dateIsWeekend(date: Date): boolean {\r\n return dateIsValid(date) && isWeekend(date);\r\n}\r\n\r\n/**\r\n * Calculate the difference in days between two dates\r\n * The order is not relevant hence the result is always positive\r\n * @param from The start date\r\n * @param to The end date\r\n * @returns The difference in days between two dates\r\n */\r\nexport function dateDifferenceInDays(from: Date, to: Date): number {\r\n return dateIsValid(from) && dateIsValid(to) ? Math.abs(differenceInCalendarDays(from, to)) : Number.NaN;\r\n}\r\n\r\n/**\r\n * Get the next business date\r\n * @param date The date\r\n * @returns The next business date\r\n */\r\nexport function getNextBusinessDate(date: Date): Date {\r\n return dateIsValid(date) ? addBusinessDays(date, 1) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the start of a day for the given date\r\n * @param date The date\r\n * @returns The start of a day date\r\n */\r\nexport function getStartOfDay(date: Date): Date {\r\n return dateIsValid(date) ? startOfDay(date) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the end of a day for the given date\r\n * @param date The date\r\n * @returns The end of a day date\r\n */\r\nexport function getEndOfDay(date: Date): Date {\r\n return dateIsValid(date) ? endOfDay(date) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the first day of a year for the given date\r\n * @param date The date\r\n * @returns The first day of the date year\r\n */\r\nexport function getFirstDayOfYear(date: Date): Date {\r\n return dateIsValid(date) ? new Date(date.getFullYear(), 0, 1) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the last day of a year for the given date\r\n * @param date The date\r\n * @returns The last day of the date year\r\n */\r\nexport function getLastDayOfYear(date: Date): Date {\r\n return dateIsValid(date) ? lastDayOfYear(date) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the year quarter for the given date\r\n * @param date The date\r\n * @returns The year quarter\r\n */\r\nexport function getQuarter(date: Date): number {\r\n return dateIsValid(date) ? getQuarterInternal(date) : Number.NaN;\r\n}\r\n\r\n/**\r\n * Shifts a date by a given number of quarters.\r\n * @param date The date\r\n * @param amount Number of quarters to shift by (negative values shift the date backwards)\r\n * @returns A new Date shifted by the specified number of quarters\r\n */\r\nexport function addQuarters(date: Date, amount: number): Date {\r\n return dateIsValid(date) ? addQuartersInternal(date, amount) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the date removing the time-zone offset\r\n * @param date The date\r\n * @returns the given date removing the time-zone offset\r\n */\r\nexport function getDateWithoutTimeZone(date: Date): Date {\r\n return dateIsValid(date) ? new Date(date.getTime() - date.getTimezoneOffset() * 60_000) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the date adding the time-zone offset\r\n * @param date The date\r\n * @returns the given date adding the time-zone offset\r\n */\r\nexport function getDateAddTimeZone(date: Date): Date {\r\n return dateIsValid(date) ? new Date(date.getTime() + date.getTimezoneOffset() * 60_000) : new Date(Number.NaN);\r\n}\r\n","import * as uuid from \"uuid\";\r\n\r\n/**\r\n * Create a new Guid (version 4 UUID)\r\n * @returns A new Guid\r\n */\r\nexport function newGuid() {\r\n return uuid.v4();\r\n}\r\n\r\n/**\r\n * Check whether a string it is a valid Guid\r\n * @param str The string to test whether it is a valid Guid\r\n * @returns A value indicating whether the string is a valid Guid\r\n */\r\nexport function isValidGuid(str: string) {\r\n const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\r\n return typeof str === \"string\" && regex.test(str);\r\n}\r\n\r\n/**\r\n * The empty Guid (an identifier containing all zeros)\r\n */\r\nexport const emptyGuid: string = uuid.NIL;\r\n","import { dateIsValid } from \"./date\";\r\n\r\n/**\r\n * The localStorage item\r\n */\r\ninterface LocalStorageItem<T> {\r\n /**\r\n * The data\r\n */\r\n data: T;\r\n\r\n /**\r\n * The expiration date\r\n */\r\n expirationDate?: Date;\r\n}\r\n\r\n/**\r\n * Check if the localStorage is supported\r\n */\r\nconst checkLocalStorageSupport = () => {\r\n if (typeof localStorage === \"undefined\") {\r\n throw new TypeError(\"localStorage not supported\");\r\n }\r\n};\r\n\r\n/**\r\n * Get an item from the localStorage\r\n * @param key The key\r\n * @returns The item\r\n */\r\nexport function getLocalStorageItem<T>(key: string): T | undefined {\r\n checkLocalStorageSupport();\r\n\r\n const item = localStorage.getItem(key);\r\n if (!item) {\r\n return undefined;\r\n }\r\n\r\n const parsedItem = JSON.parse(item) as LocalStorageItem<T>;\r\n\r\n if (parsedItem.expirationDate) {\r\n const revivedExpirationDate = new Date(parsedItem.expirationDate);\r\n if (dateIsValid(revivedExpirationDate) && revivedExpirationDate < new Date()) {\r\n localStorage.removeItem(key);\r\n return undefined;\r\n }\r\n }\r\n\r\n return parsedItem.data;\r\n}\r\n\r\n/**\r\n * Set an item in the localStorage\r\n * @param key The key\r\n * @param data The item data\r\n * @param expirationDate The expiration date\r\n */\r\nexport function setLocalStorageItem<T>(key: string, data: T, expirationDate?: Date): void {\r\n checkLocalStorageSupport();\r\n localStorage.setItem(key, JSON.stringify({ data, expirationDate }));\r\n}\r\n\r\n/**\r\n * Remove an item from the localStorage\r\n * @param key The key\r\n */\r\nexport function removeLocalStorageItem(key: string): void {\r\n checkLocalStorageSupport();\r\n localStorage.removeItem(key);\r\n}\r\n","import { isNullOrEmpty } from \"./string\";\r\n\r\n/**\r\n * Private helper function to check if a MIME type matches a main type pattern\r\n * @param mimeType The MIME type to check\r\n * @param mainType The main MIME type (e.g., \"image\", \"video\")\r\n * @returns true if the MIME type matches the pattern\r\n */\r\nfunction isMainMimeType(mimeType: string, mainType: string): boolean {\r\n const normalizedMimeType = mimeType.toLowerCase().trim();\r\n return normalizedMimeType.startsWith(`${mainType}/`) && normalizedMimeType.length > mainType.length + 1;\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents an image\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for an image\r\n */\r\nexport function isImageMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"image\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents a PDF document\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for a PDF document\r\n */\r\nexport function isPdfMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n const normalizedMimeType = mimeType!.toLowerCase().trim();\r\n return normalizedMimeType === \"application/pdf\";\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents a video\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for a video\r\n */\r\nexport function isVideoMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"video\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents an audio file\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for an audio file\r\n */\r\nexport function isAudioMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"audio\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents a text file\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for a text file\r\n */\r\nexport function isTextMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"text\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents an application file\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for an application file\r\n */\r\nexport function isApplicationMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"application\");\r\n}\r\n","/**\r\n * Check whether the provided parameter is of type `object` but not `null`, an `array`, a `regexp`, nor a `date`\r\n * @param obj The object\r\n * @returns A boolean indicating whether the parameter is an object\r\n */\r\nexport const isObject = (obj: object): boolean =>\r\n typeof obj === \"object\" && obj !== null && !Array.isArray(obj) && !(obj instanceof RegExp) && !(obj instanceof Date);\r\n\r\n/**\r\n * Convert null properties to undefined\r\n * @param obj The object\r\n */\r\nexport const convertNullToUndefined = (obj: object | object[]): void => {\r\n if (Array.isArray(obj)) {\r\n for (const item of obj as unknown as object[]) {\r\n if (item === null) {\r\n obj[obj.indexOf(item)] = undefined;\r\n } else if (isObject(item)) {\r\n convertNullToUndefined(item);\r\n }\r\n }\r\n } else if (!isObject(obj)) {\r\n return;\r\n }\r\n\r\n for (const key of Object.keys(obj)) {\r\n const value = obj[key as keyof typeof obj];\r\n if (value === null) {\r\n delete obj[key as keyof typeof obj];\r\n } else if (isObject(value) || Array.isArray(value)) {\r\n convertNullToUndefined(value);\r\n }\r\n }\r\n};\r\n","import { isNullOrWhitespace } from \"./string\";\r\n\r\n/**\r\n * Checks if the provided string is a valid swiss IBAN number\r\n * @param ibanNumber The provided IBAN number to check\r\n * Must be in one of the following formats:\r\n * - \"CHXX XXXX XXXX XXXX XXXX X\" with whitespaces\r\n * - \"CHXXXXXXXXXXXXXXXXXXX\" without whitespaces\r\n * @returns The result of the IBAN number check\r\n */\r\nexport function isValidSwissIbanNumber(ibanNumber: string): boolean {\r\n // 1. Reject null, undefined or whitespace-only strings\r\n if (isNullOrWhitespace(ibanNumber)) {\r\n return false;\r\n }\r\n\r\n // 2. Define allowed strict formats\r\n // - with spaces: \"CHXX XXXX XXXX XXXX XXXX X\"\r\n const compactIbanNumberWithWhiteSpaces = new RegExp(/^CH[0-9]{2} [0-9]{4} [0-9][A-Z0-9]{3} [A-Z0-9]{4} [A-Z0-9]{4} [A-Z0-9]$/);\r\n // - without spaces: \"CHXXXXXXXXXXXXXXXXXXX\"\r\n const compactIbanNumberWithoutWhiteSpaces = new RegExp(/^CH[0-9]{7}[A-Z0-9]{12}$/);\r\n\r\n // 3. Check if the input matches one of the allowed formats\r\n if (!(compactIbanNumberWithWhiteSpaces.test(ibanNumber) || compactIbanNumberWithoutWhiteSpaces.test(ibanNumber))) {\r\n return false;\r\n }\r\n\r\n // 4. Remove all spaces to get a compact IBAN string\r\n const compactIbanNumber = ibanNumber.replaceAll(\" \", \"\");\r\n\r\n // 5. Rearrange IBAN for checksum calculation\r\n // - move first 4 characters (CH + 2 check digits) to the end\r\n const rearrangedIban = compactIbanNumber.slice(4) + compactIbanNumber.slice(0, 4);\r\n\r\n // 6. Replace letters with numbers (A=10, B=11, ..., Z=35)\r\n const numericStr = rearrangedIban.replaceAll(/[A-Z]/g, (ch) => (ch.codePointAt(0)! - 55).toString());\r\n\r\n // 7. Perform modulo 97 calculation to validate IBAN\r\n let restOfCalculation = 0;\r\n for (const digit of numericStr) {\r\n restOfCalculation = (restOfCalculation * 10 + Number(digit)) % 97;\r\n }\r\n\r\n // 8. IBAN is valid only if the remainder equals 1\r\n return restOfCalculation === 1;\r\n}\r\n\r\n/**\r\n * Validation of a social insurance number with checking the checksum\r\n * Validation according to https://www.sozialversicherungsnummer.ch/aufbau-neu.htm\r\n * @param socialInsuranceNumber The social insurance number to check\r\n * Must be in one of the following formats:\r\n * - \"756.XXXX.XXXX.XX\" with dots as separators\r\n * - \"756XXXXXXXXXX\" with digits only\r\n * @returns The result if the social insurance number is valid or not\r\n */\r\nexport function isValidSwissSocialInsuranceNumber(socialInsuranceNumber: string): boolean {\r\n // 1. Check if the input is empty or only a whitespace\r\n if (isNullOrWhitespace(socialInsuranceNumber)) {\r\n return false;\r\n }\r\n\r\n /**\r\n * 2. Check if the input matches one of the accepted formats:\r\n * - With dots: 756.XXXX.XXXX.XX\r\n * - Without dots: 756XXXXXXXXXX\r\n */\r\n const socialInsuranceNumberWithDots = new RegExp(/^756\\.\\d{4}\\.\\d{4}\\.\\d{2}$/);\r\n const socialInsuranceNumberWithoutDots = new RegExp(/^756\\d{10}$/);\r\n\r\n if (!socialInsuranceNumberWithDots.test(socialInsuranceNumber) && !socialInsuranceNumberWithoutDots.test(socialInsuranceNumber)) {\r\n return false;\r\n }\r\n\r\n // 3. Remove all dots → get a string of 13 digits\r\n const compactNumber = socialInsuranceNumber.replaceAll(\".\", \"\");\r\n\r\n /**\r\n * 4. Separate digits for checksum calculation\r\n * - first 12 digits: used to calculate checksum\r\n * - last digit: actual check digit\r\n */\r\n const digits = compactNumber.slice(0, -1);\r\n const reversedDigits = [...digits].reverse().join(\"\");\r\n const reversedDigitsArray = [...reversedDigits];\r\n\r\n /*\r\n * 5. Calculate weighted sum for checksum\r\n * - Even positions (after reversing) ×3\r\n * - Odd positions ×1\r\n */\r\n let sum = 0;\r\n for (const [i, element] of reversedDigitsArray.entries()) {\r\n sum += i % 2 === 0 ? Number(element) * 3 : Number(element) * 1;\r\n }\r\n\r\n /*\r\n * 6. Calculate expected check digit\r\n * - Check digit = value to reach next multiple of 10\r\n */\r\n const checksum = (10 - (sum % 10)) % 10;\r\n const checknumber = Number.parseInt(compactNumber.slice(-1));\r\n\r\n /*\r\n * 7. Compare calculated check digit with actual last digit\r\n * - If equal → valid AHV number\r\n */\r\n return checksum === checknumber;\r\n}\r\n\r\n/**\r\n * Attempts to parse and validate a Swiss IBAN.\r\n * @param unformattedIbanNumber - The unformatted IBAN as a string\r\n * @returns The result object with the following properties:\r\n * @property {boolean} isValid - Indicates whether the IBAN is valid or not\r\n * @property {string} iban - The cleaned IBAN, only present if valid\r\n * @property {string} ibanFormatted - The formatted IBAN, only present if valid\r\n */\r\nexport function tryParseSwissIbanNumber(unformattedIbanNumber?: string): {\r\n /**\r\n * Indicates whether the IBAN is valid or not\r\n */\r\n isValid: boolean;\r\n /**\r\n * The cleaned IBAN, only present if valid\r\n */\r\n iban?: string;\r\n /**\r\n * The formatted IBAN, only present if valid\r\n */\r\n ibanFormatted?: string;\r\n} {\r\n if (isNullOrWhitespace(unformattedIbanNumber)) {\r\n return { isValid: false };\r\n }\r\n\r\n const iban = unformattedIbanNumber!.replaceAll(/[^A-Z0-9]/gi, \"\").toUpperCase();\r\n const isValid = isValidSwissIbanNumber(iban);\r\n\r\n return {\r\n isValid: isValid,\r\n iban: isValid ? iban : undefined,\r\n ibanFormatted: isValid ? iban.match(/.{1,4}/g)?.join(\" \") : undefined,\r\n };\r\n}\r\n\r\n/**\r\n * Attempts to parse and validate a Swiss social insurance number.\r\n * @param unformattedInsuranceNumber - The unformatted Swiss social insurance number\r\n * @returns The result object with the following properties:\r\n * @property {boolean} isValid - Indicates whether the Swiss social insurance number is valid or not\r\n * @property {string} swissSocialInsuranceNumber - The cleaned Swiss social insurance number, only present if valid\r\n * @property {string} swissSocialInsuranceNumberFormatted - The formatted Swiss social insurance number, only present if valid\r\n */\r\nexport function tryParseSwissSocialInsuranceNumber(unformattedInsuranceNumber?: string): {\r\n /**\r\n * Indicates whether the Swiss social insurance number is valid or not\r\n */\r\n isValid: boolean;\r\n /**\r\n * The cleaned Swiss social insurance number, only present if valid\r\n */\r\n swissSocialInsuranceNumber?: string;\r\n /**\r\n * The formatted Swiss social insurance number, only present if valid\r\n */\r\n swissSocialInsuranceNumberFormatted?: string;\r\n} {\r\n if (isNullOrWhitespace(unformattedInsuranceNumber)) {\r\n return { isValid: false };\r\n }\r\n\r\n const insuranceNumber = unformattedInsuranceNumber!.replaceAll(/\\D/g, \"\");\r\n const isValid = isValidSwissSocialInsuranceNumber(insuranceNumber);\r\n\r\n return {\r\n isValid: isValid,\r\n swissSocialInsuranceNumber: isValid ? insuranceNumber : undefined,\r\n swissSocialInsuranceNumberFormatted: isValid ? insuranceNumber.replace(/^(\\d{3})(\\d{4})(\\d{4})(\\d{2})$/, \"$1.$2.$3.$4\") : undefined,\r\n };\r\n}\r\n","import { getEnumNameFromValue, StandardEnum } from \"./enum\";\r\nimport { isNullOrWhitespace } from \"./string\";\r\n\r\n/**\r\n * Methods to help caching data of any type.\r\n * Data is put in containers and may be identified by a string key.\r\n * Data can be saved, retrieved and reset.\r\n * Based on Neolution.Abstractions.Caching.CacheProvider<TEnum>\r\n * Ref: https://github.com/neolution-ch/Neolution.Abstractions/blob/main/Neolution.Abstractions/Caching/CacheProvider.cs\r\n */\r\nexport class CacheProvider<TEnum> {\r\n /**\r\n * The enum variable\r\n */\r\n private readonly enumVariable: StandardEnum<TEnum>;\r\n\r\n /**\r\n * The name of the cache\r\n */\r\n private readonly cacheName: string;\r\n\r\n /**\r\n * The cache\r\n */\r\n private readonly cache = new Map<string, object>();\r\n\r\n /**\r\n * Initializes a new instance of the CacheProvider<TEnum> class\r\n * @param enumVariable The enum variable\r\n * @param cacheName The name of the cache\r\n */\r\n constructor(enumVariable: StandardEnum<TEnum>, cacheName: string) {\r\n this.enumVariable = enumVariable;\r\n this.cacheName = cacheName;\r\n }\r\n\r\n /**\r\n * Creates the cache key\r\n * @param container The container\r\n * @param key The key\r\n * @returns The cache key\r\n */\r\n private createCacheKey(container: TEnum, key?: string): string {\r\n let containerName = getEnumNameFromValue(this.enumVariable, container);\r\n\r\n if (key && !isNullOrWhitespace(key)) {\r\n containerName = `${containerName}_${key}`;\r\n }\r\n\r\n return `${this.cacheName}:${containerName}`;\r\n }\r\n\r\n /**\r\n * Gets cached data from the specified container\r\n * @param container The container\r\n * @param key The key\r\n * @returns The data from cache\r\n */\r\n getObject<T>(container: TEnum, key?: string): T | undefined {\r\n return this.cache.get(this.createCacheKey(container, key)) as T;\r\n }\r\n\r\n /**\r\n * Sets cached data identified by a key in the specified container\r\n * @param container The container\r\n * @param key The key\r\n * @param cacheObject The cache object\r\n */\r\n setObject<T>(container: TEnum, key: string | undefined, cacheObject: T): void {\r\n this.cache.set(this.createCacheKey(container, key), cacheObject as object);\r\n }\r\n\r\n /**\r\n * Resets cached data identified by a key of the specified container\r\n * @param container The container\r\n * @param key The key\r\n */\r\n reset(container: TEnum, key?: string): void {\r\n this.cache.delete(this.createCacheKey(container, key));\r\n }\r\n}\r\n","/**\r\n * Returns a number whose value is limited to the given range\r\n * @param value The initial value\r\n * @param min The lower boundary\r\n * @param max The upper boundary\r\n * @returns A number in the range (min, max)\r\n */\r\nexport function clamp(value: number, min: number, max: number): number {\r\n if (min > max) {\r\n throw new Error(`'${min}' cannot be greater than '${max}'.`);\r\n }\r\n return Math.min(Math.max(value, min), max);\r\n}\r\n\r\n/**\r\n * Round a number with the specified precision\r\n * @param value The number to round\r\n * @param precision The desired precision\r\n * @returns The number rounded with the specified precision\r\n */\r\nexport function roundPrecision(value: number, precision: number): number {\r\n const multiplier = Math.pow(10, precision);\r\n return Math.round(value * multiplier) / multiplier;\r\n}\r\n","import { isNullOrEmpty } from \"./string\";\r\n\r\n/**\r\n * Converts a string to a boolean\r\n * @param value The string to convert\r\n * @returns The parsed boolean\r\n */\r\nexport function parseBool(value?: string): boolean {\r\n // Similar to C# implementation that trims also null characters\r\n // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Boolean.cs#L277\r\n return !isNullOrEmpty(value) && value?.replace(/[\\s\\0]/g, \"\").toLowerCase() === \"true\";\r\n}\r\n"],"names":["isNullOrEmpty","value","length","isNullOrWhitespace","trim","trimStart","haystack","needle","offset","indexOf","slice","trimEnd","idx","lastIndexOf","getEnumNameFromValue","enumVariable","enumValue","result","undefined","isEnumString","Object","keys","values","getEnumValueFromName","enumName","key","test","dateIsValid","date","isDate","isValid","emptyGuid","uuid","NIL","checkLocalStorageSupport","localStorage","TypeError","isMainMimeType","mimeType","mainType","normalizedMimeType","toLowerCase","startsWith","isObject","obj","Array","isArray","RegExp","Date","convertNullToUndefined","item","isValidSwissIbanNumber","ibanNumber","compactIbanNumberWithWhiteSpaces","compactIbanNumberWithoutWhiteSpaces","compactIbanNumber","replaceAll","numericStr","ch","codePointAt","toString","restOfCalculation","digit","Number","isValidSwissSocialInsuranceNumber","socialInsuranceNumber","socialInsuranceNumberWithDots","socialInsuranceNumberWithoutDots","compactNumber","reversedDigitsArray","reverse","join","sum","i","element","entries","parseInt","cacheName","cache","Map","constructor","this","createCacheKey","container","containerName","getObject","get","setObject","cacheObject","set","reset","delete","amount","addQuartersInternal","NaN","charAt","toUpperCase","min","max","Error","Math","from","to","abs","differenceInCalendarDays","isFirstDayOfMonth","isLastDayOfMonth","isLeapYear","isWeekend","getTime","getTimezoneOffset","endOfDay","names","map","getFullYear","lastDayOfYear","getItem","parsedItem","JSON","parse","expirationDate","revivedExpirationDate","removeItem","data","addBusinessDays","getQuarterInternal","startOfDay","str","v4","replace","isNaN","precision","multiplier","pow","round","setItem","stringify","removeEmptyEntries","trimEntries","splitted","split","x","filter","line","maxLength","suffix","unformattedIbanNumber","iban","ibanFormatted","match","unformattedInsuranceNumber","insuranceNumber","swissSocialInsuranceNumber","swissSocialInsuranceNumberFormatted"],"mappings":"+VAKM,SAAUA,EAAcC,GAC5B,OAAKA,GAA0B,iBAAVA,GAIG,IAAjBA,EAAMC,MACf,CAOM,SAAUC,EAAmBF,GACjC,OAAOD,EAAcC,IAA8C,IAAnCA,EAAiBG,OAAOF,MAC1D,CAqDgB,SAAAG,EAAUC,EAAkBC,GAC1C,GAAIP,EAAcM,IAAaN,EAAcO,GAC3C,OAAOD,EAGT,IAAIE,EAAS,EAEb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B,GAC3B,OAAKA,GAASE,EAAmBF,GACxBA,EAGFA,EAAM8F,OAAO,GAAGtD,cAAgBxC,EAAMS,MAAM,EACrD"}
@@ -0,0 +1,2 @@
1
+ import{isDate as e,isValid as t,isFirstDayOfMonth as n,isLastDayOfMonth as r,isLeapYear as i,isWeekend as u,differenceInCalendarDays as o,addBusinessDays as a,startOfDay as c,endOfDay as s,lastDayOfYear as f,getQuarter as l,addQuarters as m}from"date-fns";import*as N from"uuid";function h(e){return!e||"string"!=typeof e||0===e.length}function d(e){return h(e)||0===e.trim().length}function g(e){return!e||d(e)?e:e.charAt(0).toUpperCase()+e.slice(1)}function p(e){return!e||d(e)?e:e.charAt(0).toLowerCase()+e.slice(1)}function b(e,t,n=""){return!e||d(e)||e.length<=t?e:`${e.slice(0,t)}${n}`}function w(e,t){if(h(e)||h(t))return e;let n=0;for(;e.indexOf(t,n)===n;)n+=t.length;return e.slice(n)}function A(e,t){if(h(e)||h(t))return e;let n=e.length,r=-1;for(;r=e.lastIndexOf(t,n-1),-1!==r&&r+t.length===n;){if(0===r)return"";n=r}return e.slice(0,n)}function y(e,t){return A(w(e,t),t)}function $(e,t=!1,n=!1){if(h(e))return[];let r=e.split(/\r\n|\r|\n/);return n&&(r=r.map((e=>e.trim()))),t&&(r=r.filter((e=>e.length>0))),r}function D(e){return!h(e)&&"true"===e?.replace(/[\s\0]/g,"").toLowerCase()}function O(e,t){let n=e[t];return void 0===n&&S(e)&&(n=Object.keys(e)[Object.values(e).indexOf(t)]),n}function v(e,t){return e[t]}function x(e){const t=Object.values(e);return S(e)?Object.keys(e):t.slice(0,t.length/2)}function j(e){const t=Object.keys(e);return S(e)?Object.values(e):t.slice(0,t.length/2).map((e=>Number.parseInt(e)))}function C(e,t){if(S(e)||!Number.isNaN(Number(t)))return v(e,O(e,t))}function S(e){for(const t in e)return!/^\d+$/.test(t);return!1}class I{enumVariable;cacheName;cache=new Map;constructor(e,t){this.enumVariable=e,this.cacheName=t}createCacheKey(e,t){let n=O(this.enumVariable,e);return t&&!d(t)&&(n=`${n}_${t}`),`${this.cacheName}:${n}`}getObject(e,t){return this.cache.get(this.createCacheKey(e,t))}setObject(e,t,n){this.cache.set(this.createCacheKey(e,t),n)}reset(e,t){this.cache.delete(this.createCacheKey(e,t))}}function E(n){return e(n)&&t(n)}function V(e){return E(e)&&n(e)}function Z(e){return E(e)&&r(e)}function M(e){return E(e)&&i(e)}function L(e){return E(e)&&u(e)}function R(e,t){return E(e)&&E(t)?Math.abs(o(e,t)):Number.NaN}function T(e){return E(e)?a(e,1):new Date(Number.NaN)}function k(e){return E(e)?c(e):new Date(Number.NaN)}function K(e){return E(e)?s(e):new Date(Number.NaN)}function F(e){return E(e)?new Date(e.getFullYear(),0,1):new Date(Number.NaN)}function z(e){return E(e)?f(e):new Date(Number.NaN)}function H(e){return E(e)?l(e):Number.NaN}function J(e,t){return E(e)?m(e,t):new Date(Number.NaN)}function Q(e){return E(e)?new Date(e.getTime()-6e4*e.getTimezoneOffset()):new Date(Number.NaN)}function U(e){return E(e)?new Date(e.getTime()+6e4*e.getTimezoneOffset()):new Date(Number.NaN)}function P(){return N.v4()}function W(e){return"string"==typeof e&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)}const Y=N.NIL,_=()=>{if("undefined"==typeof localStorage)throw new TypeError("localStorage not supported")};function q(e){_();const t=localStorage.getItem(e);if(!t)return;const n=JSON.parse(t);if(n.expirationDate){const t=new Date(n.expirationDate);if(E(t)&&t<new Date)return void localStorage.removeItem(e)}return n.data}function B(e,t,n){_(),localStorage.setItem(e,JSON.stringify({data:t,expirationDate:n}))}function G(e){_(),localStorage.removeItem(e)}function X(e,t){const n=e.toLowerCase().trim();return n.startsWith(`${t}/`)&&n.length>t.length+1}function ee(e){return!h(e)&&X(e,"image")}function te(e){if(h(e))return!1;return"application/pdf"===e.toLowerCase().trim()}function ne(e){return!h(e)&&X(e,"video")}function re(e){return!h(e)&&X(e,"audio")}function ie(e){return!h(e)&&X(e,"text")}function ue(e){return!h(e)&&X(e,"application")}function oe(e,t,n){if(t>n)throw new Error(`'${t}' cannot be greater than '${n}'.`);return Math.min(Math.max(e,t),n)}function ae(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}const ce=e=>!("object"!=typeof e||null===e||Array.isArray(e)||e instanceof RegExp||e instanceof Date),se=e=>{if(Array.isArray(e))for(const t of e)null===t?e[e.indexOf(t)]=void 0:ce(t)&&se(t);else if(!ce(e))return;for(const t of Object.keys(e)){const n=e[t];null===n?delete e[t]:(ce(n)||Array.isArray(n))&&se(n)}};function fe(e){if(d(e))return!1;const t=new RegExp(/^CH[0-9]{2} [0-9]{4} [0-9][A-Z0-9]{3} [A-Z0-9]{4} [A-Z0-9]{4} [A-Z0-9]$/),n=new RegExp(/^CH[0-9]{7}[A-Z0-9]{12}$/);if(!t.test(e)&&!n.test(e))return!1;const r=e.replaceAll(" ",""),i=(r.slice(4)+r.slice(0,4)).replaceAll(/[A-Z]/g,(e=>(e.codePointAt(0)-55).toString()));let u=0;for(const e of i)u=(10*u+Number(e))%97;return 1===u}function le(e){if(d(e))return!1;const t=new RegExp(/^756\.\d{4}\.\d{4}\.\d{2}$/),n=new RegExp(/^756\d{10}$/);if(!t.test(e)&&!n.test(e))return!1;const r=e.replaceAll(".",""),i=[...[...r.slice(0,-1)].reverse().join("")];let u=0;for(const[e,t]of i.entries())u+=e%2==0?3*Number(t):1*Number(t);return(10-u%10)%10===Number.parseInt(r.slice(-1))}function me(e){if(d(e))return{isValid:!1};const t=e.replaceAll(/[^A-Z0-9]/gi,"").toUpperCase(),n=fe(t);return{isValid:n,iban:n?t:void 0,ibanFormatted:n?t.match(/.{1,4}/g)?.join(" "):void 0}}function Ne(e){if(d(e))return{isValid:!1};const t=e.replaceAll(/\D/g,""),n=le(t);return{isValid:n,swissSocialInsuranceNumber:n?t:void 0,swissSocialInsuranceNumberFormatted:n?t.replace(/^(\d{3})(\d{4})(\d{4})(\d{2})$/,"$1.$2.$3.$4"):void 0}}export{I as CacheProvider,J as addQuarters,g as capitalize,oe as clamp,se as convertNullToUndefined,R as dateDifferenceInDays,V as dateIsFirstDayOfMonth,Z as dateIsLastDayOfMonth,M as dateIsLeapYear,E as dateIsValid,L as dateIsWeekend,Y as emptyGuid,U as getDateAddTimeZone,Q as getDateWithoutTimeZone,K as getEndOfDay,O as getEnumNameFromValue,x as getEnumNames,v as getEnumValueFromName,j as getEnumValues,F as getFirstDayOfYear,z as getLastDayOfYear,q as getLocalStorageItem,T as getNextBusinessDate,H as getQuarter,k as getStartOfDay,ue as isApplicationMimeType,re as isAudioMimeType,ee as isImageMimeType,h as isNullOrEmpty,d as isNullOrWhitespace,ce as isObject,te as isPdfMimeType,ie as isTextMimeType,W as isValidGuid,fe as isValidSwissIbanNumber,le as isValidSwissSocialInsuranceNumber,ne as isVideoMimeType,P as newGuid,D as parseBool,C as parseEnum,G as removeLocalStorageItem,ae as roundPrecision,B as setLocalStorageItem,$ as splitLines,y as trim,A as trimEnd,w as trimStart,b as truncate,me as tryParseSwissIbanNumber,Ne as tryParseSwissSocialInsuranceNumber,p as uncapitalize};
2
+ //# sourceMappingURL=index.modern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.modern.js","sources":["../src/lib/string.ts","../src/lib/boolean.ts","../src/lib/enum.ts","../src/lib/cacheProvider.ts","../src/lib/date.ts","../src/lib/guid.ts","../src/lib/localStorage.ts","../src/lib/mimeType.ts","../src/lib/number.ts","../src/lib/object.ts","../src/lib/swissStandards.ts"],"sourcesContent":["/**\r\n * Indicates whether a specified string is null/undefined or empty\r\n * @param value The string to test\r\n * @returns true if the value parameter is null/undefined or empty\r\n */\r\nexport function isNullOrEmpty(value?: string): boolean {\r\n if (!value || typeof value !== \"string\") {\r\n return true;\r\n }\r\n\r\n return value.length === 0;\r\n}\r\n\r\n/**\r\n * Indicates whether a specified string is null/undefined, empty, or consists only of white-space characters\r\n * @param value The string to test\r\n * @returns true if the value parameter is null/undefined, Empty, or if value consists exclusively of white-space characters\r\n */\r\nexport function isNullOrWhitespace(value?: string): boolean {\r\n return isNullOrEmpty(value) || (value as string).trim().length === 0;\r\n}\r\n\r\n/**\r\n * Capitalize the string\r\n * @param value The string to capitalize\r\n * @returns The capitalized string\r\n */\r\nexport function capitalize(value?: string): string | undefined {\r\n if (!value || isNullOrWhitespace(value)) {\r\n return value;\r\n }\r\n\r\n return value.charAt(0).toUpperCase() + value.slice(1);\r\n}\r\n\r\n/**\r\n * Uncapitalize the string\r\n * @param value The string to uncapitalize\r\n * @returns The uncapitalized string\r\n */\r\nexport function uncapitalize(value?: string): string | undefined {\r\n if (!value || isNullOrWhitespace(value)) {\r\n return value;\r\n }\r\n\r\n return value.charAt(0).toLowerCase() + value.slice(1);\r\n}\r\n\r\n/**\r\n * Truncates a string to a maximum length, adding a suffix if truncated\r\n * @param value The string to truncate\r\n * @param maxLength The maximum length of the resulting string\r\n * @param suffix The suffix to append if truncated (default: \"\")\r\n * @returns The truncated string\r\n */\r\nexport function truncate(value: string | undefined, maxLength: number, suffix = \"\"): string | undefined {\r\n if (!value || isNullOrWhitespace(value)) {\r\n return value;\r\n }\r\n\r\n if (value.length <= maxLength) {\r\n return value;\r\n }\r\n\r\n return `${value.slice(0, maxLength)}${suffix}`;\r\n}\r\n\r\n/**\r\n * Removes all occurrences of needle from the start of haystack\r\n * @param haystack string to trim\r\n * @param needle the thing to trim\r\n * @returns the string trimmed from the left side\r\n */\r\nexport function trimStart(haystack: string, needle: string): string {\r\n if (isNullOrEmpty(haystack) || isNullOrEmpty(needle)) {\r\n return haystack;\r\n }\r\n\r\n let offset = 0;\r\n\r\n while (haystack.indexOf(needle, offset) === offset) {\r\n offset = offset + needle.length;\r\n }\r\n return haystack.slice(offset);\r\n}\r\n\r\n/**\r\n * Removes all occurrences of needle from the end of haystack\r\n * @param haystack string to trim\r\n * @param needle the thing to trim\r\n * @returns the string trimmed from the right side\r\n */\r\nexport function trimEnd(haystack: string, needle: string): string {\r\n if (isNullOrEmpty(haystack) || isNullOrEmpty(needle)) {\r\n return haystack;\r\n }\r\n\r\n let offset = haystack.length,\r\n idx = -1;\r\n\r\n while (true) {\r\n idx = haystack.lastIndexOf(needle, offset - 1);\r\n if (idx === -1 || idx + needle.length !== offset) {\r\n break;\r\n }\r\n if (idx === 0) {\r\n return \"\";\r\n }\r\n offset = idx;\r\n }\r\n\r\n return haystack.slice(0, offset);\r\n}\r\n\r\n/**\r\n * Removes all occurrences of needle from the start and the end of haystack\r\n * @param haystack string to trim\r\n * @param needle the thing to trim\r\n * @returns the string trimmed from the right and left side\r\n */\r\nexport function trim(haystack: string, needle: string): string {\r\n const trimmed = trimStart(haystack, needle);\r\n return trimEnd(trimmed, needle);\r\n}\r\n\r\n/**\r\n * Splits the string at line breaks\r\n * @param str the string to split\r\n * @param removeEmptyEntries the option to remove empty entries\r\n * @param trimEntries the option to trim the entries\r\n * @returns the individual lines as an array\r\n */\r\nexport function splitLines(str: string, removeEmptyEntries: boolean = false, trimEntries: boolean = false): string[] {\r\n if (isNullOrEmpty(str)) {\r\n return [];\r\n }\r\n\r\n let splitted = str.split(/\\r\\n|\\r|\\n/);\r\n\r\n if (trimEntries) {\r\n splitted = splitted.map((x) => x.trim());\r\n }\r\n\r\n if (removeEmptyEntries) {\r\n splitted = splitted.filter((line) => line.length > 0);\r\n }\r\n\r\n return splitted;\r\n}\r\n","import { isNullOrEmpty } from \"./string\";\r\n\r\n/**\r\n * Converts a string to a boolean\r\n * @param value The string to convert\r\n * @returns The parsed boolean\r\n */\r\nexport function parseBool(value?: string): boolean {\r\n // Similar to C# implementation that trims also null characters\r\n // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Boolean.cs#L277\r\n return !isNullOrEmpty(value) && value?.replace(/[\\s\\0]/g, \"\").toLowerCase() === \"true\";\r\n}\r\n","/**\r\n * The standard enum type\r\n */\r\nexport type StandardEnum<T> = {\r\n [id: string]: T | string;\r\n [nu: number]: string;\r\n};\r\n\r\n/**\r\n * Returns the name of an enum from its value\r\n * @param enumVariable The enum for which you want to get the name\r\n * @param enumValue The value of the enum for which you want to get the name\r\n * @returns A string containing the name of the enum\r\n */\r\nexport function getEnumNameFromValue<T>(enumVariable: StandardEnum<T>, enumValue: T): string {\r\n let result = enumVariable[enumValue as keyof StandardEnum<T>] as string;\r\n\r\n if (result === undefined && isEnumString(enumVariable)) {\r\n result = Object.keys(enumVariable)[Object.values(enumVariable).indexOf(enumValue)];\r\n }\r\n\r\n return result;\r\n}\r\n\r\n/**\r\n * Returns the value of an enum from its name\r\n * @param enumVariable The enum for which you want to get the value\r\n * @param enumName The name of the enum for which you want to get the value\r\n * @returns A string containing the value of the enum\r\n */\r\nexport function getEnumValueFromName<T>(enumVariable: StandardEnum<T>, enumName: string): T {\r\n return enumVariable[enumName as keyof StandardEnum<T>] as T;\r\n}\r\n\r\n/**\r\n * Returns all the names of an enum\r\n * @param enumVariable The enum for which you want to get the names\r\n * @returns A string array containing the names of the enum\r\n */\r\nexport function getEnumNames<T>(enumVariable: StandardEnum<T>) {\r\n const names = Object.values(enumVariable);\r\n\r\n // If enum is with values integer, object.values returns a list of [names, values].\r\n return isEnumString(enumVariable) ? Object.keys(enumVariable) : names.slice(0, names.length / 2);\r\n}\r\n\r\n/**\r\n * Returns all the values of an enum\r\n * @param enumVariable The enum for which you want to get the values\r\n * @returns A string or number array containing the values of the enum\r\n */\r\nexport function getEnumValues<T>(enumVariable: StandardEnum<T>): T[] {\r\n const keys = Object.keys(enumVariable);\r\n\r\n // If enum is with values integer, object.keys returns a list of [values, names].\r\n return (\r\n isEnumString(enumVariable) ? Object.values(enumVariable) : keys.slice(0, keys.length / 2).map((value) => Number.parseInt(value))\r\n ) as T[];\r\n}\r\n\r\n/**\r\n * Parses a string to an enum value\r\n * @param enumVariable The enum for which you want to get the values\r\n * @param value The string to parse\r\n * @returns The enum value corresponding to the string, or undefined if not found\r\n */\r\nexport function parseEnum<T>(enumVariable: StandardEnum<T>, value: string): T | undefined {\r\n if (!isEnumString(enumVariable) && Number.isNaN(Number(value))) {\r\n return undefined;\r\n }\r\n\r\n return getEnumValueFromName(enumVariable, getEnumNameFromValue(enumVariable, value as T));\r\n}\r\n\r\n/**\r\n * Returns if it's a enum with string value\r\n * @param enumVariable The enum\r\n * @returns A bool\r\n */\r\nfunction isEnumString<T>(enumVariable: StandardEnum<T>) {\r\n for (const key in enumVariable) {\r\n return !/^\\d+$/.test(key);\r\n }\r\n\r\n return false;\r\n}\r\n","import { getEnumNameFromValue, StandardEnum } from \"./enum\";\r\nimport { isNullOrWhitespace } from \"./string\";\r\n\r\n/**\r\n * Methods to help caching data of any type.\r\n * Data is put in containers and may be identified by a string key.\r\n * Data can be saved, retrieved and reset.\r\n * Based on Neolution.Abstractions.Caching.CacheProvider<TEnum>\r\n * Ref: https://github.com/neolution-ch/Neolution.Abstractions/blob/main/Neolution.Abstractions/Caching/CacheProvider.cs\r\n */\r\nexport class CacheProvider<TEnum> {\r\n /**\r\n * The enum variable\r\n */\r\n private readonly enumVariable: StandardEnum<TEnum>;\r\n\r\n /**\r\n * The name of the cache\r\n */\r\n private readonly cacheName: string;\r\n\r\n /**\r\n * The cache\r\n */\r\n private readonly cache = new Map<string, object>();\r\n\r\n /**\r\n * Initializes a new instance of the CacheProvider<TEnum> class\r\n * @param enumVariable The enum variable\r\n * @param cacheName The name of the cache\r\n */\r\n constructor(enumVariable: StandardEnum<TEnum>, cacheName: string) {\r\n this.enumVariable = enumVariable;\r\n this.cacheName = cacheName;\r\n }\r\n\r\n /**\r\n * Creates the cache key\r\n * @param container The container\r\n * @param key The key\r\n * @returns The cache key\r\n */\r\n private createCacheKey(container: TEnum, key?: string): string {\r\n let containerName = getEnumNameFromValue(this.enumVariable, container);\r\n\r\n if (key && !isNullOrWhitespace(key)) {\r\n containerName = `${containerName}_${key}`;\r\n }\r\n\r\n return `${this.cacheName}:${containerName}`;\r\n }\r\n\r\n /**\r\n * Gets cached data from the specified container\r\n * @param container The container\r\n * @param key The key\r\n * @returns The data from cache\r\n */\r\n getObject<T>(container: TEnum, key?: string): T | undefined {\r\n return this.cache.get(this.createCacheKey(container, key)) as T;\r\n }\r\n\r\n /**\r\n * Sets cached data identified by a key in the specified container\r\n * @param container The container\r\n * @param key The key\r\n * @param cacheObject The cache object\r\n */\r\n setObject<T>(container: TEnum, key: string | undefined, cacheObject: T): void {\r\n this.cache.set(this.createCacheKey(container, key), cacheObject as object);\r\n }\r\n\r\n /**\r\n * Resets cached data identified by a key of the specified container\r\n * @param container The container\r\n * @param key The key\r\n */\r\n reset(container: TEnum, key?: string): void {\r\n this.cache.delete(this.createCacheKey(container, key));\r\n }\r\n}\r\n","import {\r\n isDate,\r\n isValid,\r\n isFirstDayOfMonth,\r\n isLastDayOfMonth,\r\n isLeapYear,\r\n isWeekend,\r\n differenceInCalendarDays,\r\n addBusinessDays,\r\n startOfDay,\r\n endOfDay,\r\n lastDayOfYear,\r\n getQuarter as getQuarterInternal,\r\n addQuarters as addQuartersInternal,\r\n} from \"date-fns\";\r\n\r\n/**\r\n * Check whether the date is valid\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is valid\r\n */\r\nexport function dateIsValid(date: Date): boolean {\r\n return isDate(date) && isValid(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is the first day of the month\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is the first day of the month\r\n */\r\nexport function dateIsFirstDayOfMonth(date: Date): boolean {\r\n return dateIsValid(date) && isFirstDayOfMonth(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is the last day of the month\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is the last day of the month\r\n */\r\nexport function dateIsLastDayOfMonth(date: Date): boolean {\r\n return dateIsValid(date) && isLastDayOfMonth(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is a leap year\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is a leap year\r\n */\r\nexport function dateIsLeapYear(date: Date): boolean {\r\n return dateIsValid(date) && isLeapYear(date);\r\n}\r\n\r\n/**\r\n * Check whether the date is a weekend\r\n * @param date The date\r\n * @returns A boolean indicating whether the date is a weekend\r\n */\r\nexport function dateIsWeekend(date: Date): boolean {\r\n return dateIsValid(date) && isWeekend(date);\r\n}\r\n\r\n/**\r\n * Calculate the difference in days between two dates\r\n * The order is not relevant hence the result is always positive\r\n * @param from The start date\r\n * @param to The end date\r\n * @returns The difference in days between two dates\r\n */\r\nexport function dateDifferenceInDays(from: Date, to: Date): number {\r\n return dateIsValid(from) && dateIsValid(to) ? Math.abs(differenceInCalendarDays(from, to)) : Number.NaN;\r\n}\r\n\r\n/**\r\n * Get the next business date\r\n * @param date The date\r\n * @returns The next business date\r\n */\r\nexport function getNextBusinessDate(date: Date): Date {\r\n return dateIsValid(date) ? addBusinessDays(date, 1) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the start of a day for the given date\r\n * @param date The date\r\n * @returns The start of a day date\r\n */\r\nexport function getStartOfDay(date: Date): Date {\r\n return dateIsValid(date) ? startOfDay(date) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the end of a day for the given date\r\n * @param date The date\r\n * @returns The end of a day date\r\n */\r\nexport function getEndOfDay(date: Date): Date {\r\n return dateIsValid(date) ? endOfDay(date) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the first day of a year for the given date\r\n * @param date The date\r\n * @returns The first day of the date year\r\n */\r\nexport function getFirstDayOfYear(date: Date): Date {\r\n return dateIsValid(date) ? new Date(date.getFullYear(), 0, 1) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the last day of a year for the given date\r\n * @param date The date\r\n * @returns The last day of the date year\r\n */\r\nexport function getLastDayOfYear(date: Date): Date {\r\n return dateIsValid(date) ? lastDayOfYear(date) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the year quarter for the given date\r\n * @param date The date\r\n * @returns The year quarter\r\n */\r\nexport function getQuarter(date: Date): number {\r\n return dateIsValid(date) ? getQuarterInternal(date) : Number.NaN;\r\n}\r\n\r\n/**\r\n * Shifts a date by a given number of quarters.\r\n * @param date The date\r\n * @param amount Number of quarters to shift by (negative values shift the date backwards)\r\n * @returns A new Date shifted by the specified number of quarters\r\n */\r\nexport function addQuarters(date: Date, amount: number): Date {\r\n return dateIsValid(date) ? addQuartersInternal(date, amount) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the date removing the time-zone offset\r\n * @param date The date\r\n * @returns the given date removing the time-zone offset\r\n */\r\nexport function getDateWithoutTimeZone(date: Date): Date {\r\n return dateIsValid(date) ? new Date(date.getTime() - date.getTimezoneOffset() * 60_000) : new Date(Number.NaN);\r\n}\r\n\r\n/**\r\n * Get the date adding the time-zone offset\r\n * @param date The date\r\n * @returns the given date adding the time-zone offset\r\n */\r\nexport function getDateAddTimeZone(date: Date): Date {\r\n return dateIsValid(date) ? new Date(date.getTime() + date.getTimezoneOffset() * 60_000) : new Date(Number.NaN);\r\n}\r\n","import * as uuid from \"uuid\";\r\n\r\n/**\r\n * Create a new Guid (version 4 UUID)\r\n * @returns A new Guid\r\n */\r\nexport function newGuid() {\r\n return uuid.v4();\r\n}\r\n\r\n/**\r\n * Check whether a string it is a valid Guid\r\n * @param str The string to test whether it is a valid Guid\r\n * @returns A value indicating whether the string is a valid Guid\r\n */\r\nexport function isValidGuid(str: string) {\r\n const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\r\n return typeof str === \"string\" && regex.test(str);\r\n}\r\n\r\n/**\r\n * The empty Guid (an identifier containing all zeros)\r\n */\r\nexport const emptyGuid: string = uuid.NIL;\r\n","import { dateIsValid } from \"./date\";\r\n\r\n/**\r\n * The localStorage item\r\n */\r\ninterface LocalStorageItem<T> {\r\n /**\r\n * The data\r\n */\r\n data: T;\r\n\r\n /**\r\n * The expiration date\r\n */\r\n expirationDate?: Date;\r\n}\r\n\r\n/**\r\n * Check if the localStorage is supported\r\n */\r\nconst checkLocalStorageSupport = () => {\r\n if (typeof localStorage === \"undefined\") {\r\n throw new TypeError(\"localStorage not supported\");\r\n }\r\n};\r\n\r\n/**\r\n * Get an item from the localStorage\r\n * @param key The key\r\n * @returns The item\r\n */\r\nexport function getLocalStorageItem<T>(key: string): T | undefined {\r\n checkLocalStorageSupport();\r\n\r\n const item = localStorage.getItem(key);\r\n if (!item) {\r\n return undefined;\r\n }\r\n\r\n const parsedItem = JSON.parse(item) as LocalStorageItem<T>;\r\n\r\n if (parsedItem.expirationDate) {\r\n const revivedExpirationDate = new Date(parsedItem.expirationDate);\r\n if (dateIsValid(revivedExpirationDate) && revivedExpirationDate < new Date()) {\r\n localStorage.removeItem(key);\r\n return undefined;\r\n }\r\n }\r\n\r\n return parsedItem.data;\r\n}\r\n\r\n/**\r\n * Set an item in the localStorage\r\n * @param key The key\r\n * @param data The item data\r\n * @param expirationDate The expiration date\r\n */\r\nexport function setLocalStorageItem<T>(key: string, data: T, expirationDate?: Date): void {\r\n checkLocalStorageSupport();\r\n localStorage.setItem(key, JSON.stringify({ data, expirationDate }));\r\n}\r\n\r\n/**\r\n * Remove an item from the localStorage\r\n * @param key The key\r\n */\r\nexport function removeLocalStorageItem(key: string): void {\r\n checkLocalStorageSupport();\r\n localStorage.removeItem(key);\r\n}\r\n","import { isNullOrEmpty } from \"./string\";\r\n\r\n/**\r\n * Private helper function to check if a MIME type matches a main type pattern\r\n * @param mimeType The MIME type to check\r\n * @param mainType The main MIME type (e.g., \"image\", \"video\")\r\n * @returns true if the MIME type matches the pattern\r\n */\r\nfunction isMainMimeType(mimeType: string, mainType: string): boolean {\r\n const normalizedMimeType = mimeType.toLowerCase().trim();\r\n return normalizedMimeType.startsWith(`${mainType}/`) && normalizedMimeType.length > mainType.length + 1;\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents an image\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for an image\r\n */\r\nexport function isImageMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"image\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents a PDF document\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for a PDF document\r\n */\r\nexport function isPdfMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n const normalizedMimeType = mimeType!.toLowerCase().trim();\r\n return normalizedMimeType === \"application/pdf\";\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents a video\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for a video\r\n */\r\nexport function isVideoMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"video\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents an audio file\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for an audio file\r\n */\r\nexport function isAudioMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"audio\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents a text file\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for a text file\r\n */\r\nexport function isTextMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"text\");\r\n}\r\n\r\n/**\r\n * Check if the MIME type represents an application file\r\n * @param mimeType The MIME type to check\r\n * @returns true if the MIME type is for an application file\r\n */\r\nexport function isApplicationMimeType(mimeType?: string): boolean {\r\n if (isNullOrEmpty(mimeType)) {\r\n return false;\r\n }\r\n\r\n return isMainMimeType(mimeType!, \"application\");\r\n}\r\n","/**\r\n * Returns a number whose value is limited to the given range\r\n * @param value The initial value\r\n * @param min The lower boundary\r\n * @param max The upper boundary\r\n * @returns A number in the range (min, max)\r\n */\r\nexport function clamp(value: number, min: number, max: number): number {\r\n if (min > max) {\r\n throw new Error(`'${min}' cannot be greater than '${max}'.`);\r\n }\r\n return Math.min(Math.max(value, min), max);\r\n}\r\n\r\n/**\r\n * Round a number with the specified precision\r\n * @param value The number to round\r\n * @param precision The desired precision\r\n * @returns The number rounded with the specified precision\r\n */\r\nexport function roundPrecision(value: number, precision: number): number {\r\n const multiplier = Math.pow(10, precision);\r\n return Math.round(value * multiplier) / multiplier;\r\n}\r\n","/**\r\n * Check whether the provided parameter is of type `object` but not `null`, an `array`, a `regexp`, nor a `date`\r\n * @param obj The object\r\n * @returns A boolean indicating whether the parameter is an object\r\n */\r\nexport const isObject = (obj: object): boolean =>\r\n typeof obj === \"object\" && obj !== null && !Array.isArray(obj) && !(obj instanceof RegExp) && !(obj instanceof Date);\r\n\r\n/**\r\n * Convert null properties to undefined\r\n * @param obj The object\r\n */\r\nexport const convertNullToUndefined = (obj: object | object[]): void => {\r\n if (Array.isArray(obj)) {\r\n for (const item of obj as unknown as object[]) {\r\n if (item === null) {\r\n obj[obj.indexOf(item)] = undefined;\r\n } else if (isObject(item)) {\r\n convertNullToUndefined(item);\r\n }\r\n }\r\n } else if (!isObject(obj)) {\r\n return;\r\n }\r\n\r\n for (const key of Object.keys(obj)) {\r\n const value = obj[key as keyof typeof obj];\r\n if (value === null) {\r\n delete obj[key as keyof typeof obj];\r\n } else if (isObject(value) || Array.isArray(value)) {\r\n convertNullToUndefined(value);\r\n }\r\n }\r\n};\r\n","import { isNullOrWhitespace } from \"./string\";\r\n\r\n/**\r\n * Checks if the provided string is a valid swiss IBAN number\r\n * @param ibanNumber The provided IBAN number to check\r\n * Must be in one of the following formats:\r\n * - \"CHXX XXXX XXXX XXXX XXXX X\" with whitespaces\r\n * - \"CHXXXXXXXXXXXXXXXXXXX\" without whitespaces\r\n * @returns The result of the IBAN number check\r\n */\r\nexport function isValidSwissIbanNumber(ibanNumber: string): boolean {\r\n // 1. Reject null, undefined or whitespace-only strings\r\n if (isNullOrWhitespace(ibanNumber)) {\r\n return false;\r\n }\r\n\r\n // 2. Define allowed strict formats\r\n // - with spaces: \"CHXX XXXX XXXX XXXX XXXX X\"\r\n const compactIbanNumberWithWhiteSpaces = new RegExp(/^CH[0-9]{2} [0-9]{4} [0-9][A-Z0-9]{3} [A-Z0-9]{4} [A-Z0-9]{4} [A-Z0-9]$/);\r\n // - without spaces: \"CHXXXXXXXXXXXXXXXXXXX\"\r\n const compactIbanNumberWithoutWhiteSpaces = new RegExp(/^CH[0-9]{7}[A-Z0-9]{12}$/);\r\n\r\n // 3. Check if the input matches one of the allowed formats\r\n if (!(compactIbanNumberWithWhiteSpaces.test(ibanNumber) || compactIbanNumberWithoutWhiteSpaces.test(ibanNumber))) {\r\n return false;\r\n }\r\n\r\n // 4. Remove all spaces to get a compact IBAN string\r\n const compactIbanNumber = ibanNumber.replaceAll(\" \", \"\");\r\n\r\n // 5. Rearrange IBAN for checksum calculation\r\n // - move first 4 characters (CH + 2 check digits) to the end\r\n const rearrangedIban = compactIbanNumber.slice(4) + compactIbanNumber.slice(0, 4);\r\n\r\n // 6. Replace letters with numbers (A=10, B=11, ..., Z=35)\r\n const numericStr = rearrangedIban.replaceAll(/[A-Z]/g, (ch) => (ch.codePointAt(0)! - 55).toString());\r\n\r\n // 7. Perform modulo 97 calculation to validate IBAN\r\n let restOfCalculation = 0;\r\n for (const digit of numericStr) {\r\n restOfCalculation = (restOfCalculation * 10 + Number(digit)) % 97;\r\n }\r\n\r\n // 8. IBAN is valid only if the remainder equals 1\r\n return restOfCalculation === 1;\r\n}\r\n\r\n/**\r\n * Validation of a social insurance number with checking the checksum\r\n * Validation according to https://www.sozialversicherungsnummer.ch/aufbau-neu.htm\r\n * @param socialInsuranceNumber The social insurance number to check\r\n * Must be in one of the following formats:\r\n * - \"756.XXXX.XXXX.XX\" with dots as separators\r\n * - \"756XXXXXXXXXX\" with digits only\r\n * @returns The result if the social insurance number is valid or not\r\n */\r\nexport function isValidSwissSocialInsuranceNumber(socialInsuranceNumber: string): boolean {\r\n // 1. Check if the input is empty or only a whitespace\r\n if (isNullOrWhitespace(socialInsuranceNumber)) {\r\n return false;\r\n }\r\n\r\n /**\r\n * 2. Check if the input matches one of the accepted formats:\r\n * - With dots: 756.XXXX.XXXX.XX\r\n * - Without dots: 756XXXXXXXXXX\r\n */\r\n const socialInsuranceNumberWithDots = new RegExp(/^756\\.\\d{4}\\.\\d{4}\\.\\d{2}$/);\r\n const socialInsuranceNumberWithoutDots = new RegExp(/^756\\d{10}$/);\r\n\r\n if (!socialInsuranceNumberWithDots.test(socialInsuranceNumber) && !socialInsuranceNumberWithoutDots.test(socialInsuranceNumber)) {\r\n return false;\r\n }\r\n\r\n // 3. Remove all dots → get a string of 13 digits\r\n const compactNumber = socialInsuranceNumber.replaceAll(\".\", \"\");\r\n\r\n /**\r\n * 4. Separate digits for checksum calculation\r\n * - first 12 digits: used to calculate checksum\r\n * - last digit: actual check digit\r\n */\r\n const digits = compactNumber.slice(0, -1);\r\n const reversedDigits = [...digits].reverse().join(\"\");\r\n const reversedDigitsArray = [...reversedDigits];\r\n\r\n /*\r\n * 5. Calculate weighted sum for checksum\r\n * - Even positions (after reversing) ×3\r\n * - Odd positions ×1\r\n */\r\n let sum = 0;\r\n for (const [i, element] of reversedDigitsArray.entries()) {\r\n sum += i % 2 === 0 ? Number(element) * 3 : Number(element) * 1;\r\n }\r\n\r\n /*\r\n * 6. Calculate expected check digit\r\n * - Check digit = value to reach next multiple of 10\r\n */\r\n const checksum = (10 - (sum % 10)) % 10;\r\n const checknumber = Number.parseInt(compactNumber.slice(-1));\r\n\r\n /*\r\n * 7. Compare calculated check digit with actual last digit\r\n * - If equal → valid AHV number\r\n */\r\n return checksum === checknumber;\r\n}\r\n\r\n/**\r\n * Attempts to parse and validate a Swiss IBAN.\r\n * @param unformattedIbanNumber - The unformatted IBAN as a string\r\n * @returns The result object with the following properties:\r\n * @property {boolean} isValid - Indicates whether the IBAN is valid or not\r\n * @property {string} iban - The cleaned IBAN, only present if valid\r\n * @property {string} ibanFormatted - The formatted IBAN, only present if valid\r\n */\r\nexport function tryParseSwissIbanNumber(unformattedIbanNumber?: string): {\r\n /**\r\n * Indicates whether the IBAN is valid or not\r\n */\r\n isValid: boolean;\r\n /**\r\n * The cleaned IBAN, only present if valid\r\n */\r\n iban?: string;\r\n /**\r\n * The formatted IBAN, only present if valid\r\n */\r\n ibanFormatted?: string;\r\n} {\r\n if (isNullOrWhitespace(unformattedIbanNumber)) {\r\n return { isValid: false };\r\n }\r\n\r\n const iban = unformattedIbanNumber!.replaceAll(/[^A-Z0-9]/gi, \"\").toUpperCase();\r\n const isValid = isValidSwissIbanNumber(iban);\r\n\r\n return {\r\n isValid: isValid,\r\n iban: isValid ? iban : undefined,\r\n ibanFormatted: isValid ? iban.match(/.{1,4}/g)?.join(\" \") : undefined,\r\n };\r\n}\r\n\r\n/**\r\n * Attempts to parse and validate a Swiss social insurance number.\r\n * @param unformattedInsuranceNumber - The unformatted Swiss social insurance number\r\n * @returns The result object with the following properties:\r\n * @property {boolean} isValid - Indicates whether the Swiss social insurance number is valid or not\r\n * @property {string} swissSocialInsuranceNumber - The cleaned Swiss social insurance number, only present if valid\r\n * @property {string} swissSocialInsuranceNumberFormatted - The formatted Swiss social insurance number, only present if valid\r\n */\r\nexport function tryParseSwissSocialInsuranceNumber(unformattedInsuranceNumber?: string): {\r\n /**\r\n * Indicates whether the Swiss social insurance number is valid or not\r\n */\r\n isValid: boolean;\r\n /**\r\n * The cleaned Swiss social insurance number, only present if valid\r\n */\r\n swissSocialInsuranceNumber?: string;\r\n /**\r\n * The formatted Swiss social insurance number, only present if valid\r\n */\r\n swissSocialInsuranceNumberFormatted?: string;\r\n} {\r\n if (isNullOrWhitespace(unformattedInsuranceNumber)) {\r\n return { isValid: false };\r\n }\r\n\r\n const insuranceNumber = unformattedInsuranceNumber!.replaceAll(/\\D/g, \"\");\r\n const isValid = isValidSwissSocialInsuranceNumber(insuranceNumber);\r\n\r\n return {\r\n isValid: isValid,\r\n swissSocialInsuranceNumber: isValid ? insuranceNumber : undefined,\r\n swissSocialInsuranceNumberFormatted: isValid ? insuranceNumber.replace(/^(\\d{3})(\\d{4})(\\d{4})(\\d{2})$/, \"$1.$2.$3.$4\") : undefined,\r\n };\r\n}\r\n"],"names":["isNullOrEmpty","value","length","isNullOrWhitespace","trim","capitalize","charAt","toUpperCase","slice","uncapitalize","toLowerCase","truncate","maxLength","suffix","trimStart","haystack","needle","offset","indexOf","trimEnd","idx","lastIndexOf","splitLines","str","removeEmptyEntries","trimEntries","splitted","split","map","x","filter","line","parseBool","replace","getEnumNameFromValue","enumVariable","enumValue","result","undefined","isEnumString","Object","keys","values","getEnumValueFromName","enumName","getEnumNames","names","getEnumValues","Number","parseInt","parseEnum","isNaN","key","test","CacheProvider","cacheName","cache","Map","constructor","this","createCacheKey","container","containerName","getObject","get","setObject","cacheObject","set","reset","delete","dateIsValid","date","isDate","isValid","dateIsFirstDayOfMonth","isFirstDayOfMonth","dateIsLastDayOfMonth","isLastDayOfMonth","dateIsLeapYear","isLeapYear","dateIsWeekend","isWeekend","dateDifferenceInDays","from","to","Math","abs","differenceInCalendarDays","NaN","getNextBusinessDate","addBusinessDays","Date","getStartOfDay","startOfDay","getEndOfDay","endOfDay","getFirstDayOfYear","getFullYear","getLastDayOfYear","lastDayOfYear","getQuarter","getQuarterInternal","addQuarters","amount","addQuartersInternal","getDateWithoutTimeZone","getTime","getTimezoneOffset","getDateAddTimeZone","newGuid","uuid","v4","isValidGuid","emptyGuid","NIL","checkLocalStorageSupport","localStorage","TypeError","getLocalStorageItem","item","getItem","parsedItem","JSON","parse","expirationDate","revivedExpirationDate","removeItem","data","setLocalStorageItem","setItem","stringify","removeLocalStorageItem","isMainMimeType","mimeType","mainType","normalizedMimeType","startsWith","isImageMimeType","isPdfMimeType","isVideoMimeType","isAudioMimeType","isTextMimeType","isApplicationMimeType","clamp","min","max","Error","roundPrecision","precision","multiplier","pow","round","isObject","obj","Array","isArray","RegExp","convertNullToUndefined","isValidSwissIbanNumber","ibanNumber","compactIbanNumberWithWhiteSpaces","compactIbanNumberWithoutWhiteSpaces","compactIbanNumber","replaceAll","numericStr","ch","codePointAt","toString","restOfCalculation","digit","isValidSwissSocialInsuranceNumber","socialInsuranceNumber","socialInsuranceNumberWithDots","socialInsuranceNumberWithoutDots","compactNumber","reversedDigitsArray","reverse","join","sum","i","element","entries","tryParseSwissIbanNumber","unformattedIbanNumber","iban","ibanFormatted","match","tryParseSwissSocialInsuranceNumber","unformattedInsuranceNumber","insuranceNumber","swissSocialInsuranceNumber","swissSocialInsuranceNumberFormatted"],"mappings":"uRAKM,SAAUA,EAAcC,GAC5B,OAAKA,GAA0B,iBAAVA,GAIG,IAAjBA,EAAMC,MACf,CAOM,SAAUC,EAAmBF,GACjC,OAAOD,EAAcC,IAA8C,IAAnCA,EAAiBG,OAAOF,MAC1D,CAOM,SAAUG,EAAWJ,GACzB,OAAKA,GAASE,EAAmBF,GACxBA,EAGFA,EAAMK,OAAO,GAAGC,cAAgBN,EAAMO,MAAM,EACrD,CAOM,SAAUC,EAAaR,GAC3B,OAAKA,GAASE,EAAmBF,GACxBA,EAGFA,EAAMK,OAAO,GAAGI,cAAgBT,EAAMO,MAAM,EACrD,CASM,SAAUG,EAASV,EAA2BW,EAAmBC,EAAS,IAC9E,OAAKZ,GAASE,EAAmBF,IAI7BA,EAAMC,QAAUU,EAHXX,EAOF,GAAGA,EAAMO,MAAM,EAAGI,KAAaC,GACxC,CAQgB,SAAAC,EAAUC,EAAkBC,GAC1C,GAAIhB,EAAce,IAAaf,EAAcgB,GAC3C,OAAOD,EAGT,IAAIE,EAAS,EAEb,KAAOF,EAASG,QAAQF,EAAQC,KAAYA,GAC1CA,GAAkBD,EAAOd,OAE3B,OAAOa,EAASP,MAAMS,EACxB,CAQgB,SAAAE,EAAQJ,EAAkBC,GACxC,GAAIhB,EAAce,IAAaf,EAAcgB,GAC3C,OAAOD,EAGT,IAAIE,E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KsH,KAA2BE,EAAiCxH,KAAKsH,GACvG,OAAO,EAIT,MAAMG,EAAgBH,EAAsBR,WAAW,IAAK,IAStDY,EAAsB,IADL,IADRD,EAActK,MAAM,GAAI,IACJwK,UAAUC,KAAK,KAQlD,IAAIC,EAAM,EACV,IAAK,MAAOC,EAAGC,KAAYL,EAAoBM,UAC7CH,GAAOC,EAAI,GAAM,EAAsB,EAAlBnI,OAAOoI,GAAiC,EAAlBpI,OAAOoI,GAcpD,OAPkB,GAAMF,EAAM,IAAO,KACjBlI,OAAOC,SAAS6H,EAActK,OAAO,GAO3D,CAUM,SAAU8K,GAAwBC,GActC,GAAIpL,EAAmBoL,GACrB,MAAO,CAAE9G,SAAS,GAGpB,MAAM+G,EAAOD,EAAuBpB,WAAW,cAAe,IAAI5J,cAC5DkE,EAAUqF,GAAuB0B,GAEvC,MAAO,CACL/G,QAASA,EACT+G,KAAM/G,EAAU+G,OAAOlJ,EACvBmJ,cAAehH,EAAU+G,EAAKE,MAAM,YAAYT,KAAK,UAAO3I,EAEhE,CAUM,SAAUqJ,GAAmCC,GAcjD,GAAIzL,EAAmByL,GACrB,MAAO,CAAEnH,SAAS,GAGpB,MAAMoH,EAAkBD,EAA4BzB,WAAW,MAAO,IAChE1F,EAAUiG,GAAkCmB,GAElD,MAAO,CACLpH,QAASA,EACTqH,2BAA4BrH,EAAUoH,OAAkBvJ,EACxDyJ,oCAAqCtH,EAAUoH,EAAgB5J,QAAQ,iCAAkC,oBAAiBK,EAE9H"}
@@ -0,0 +1,11 @@
1
+ export * from "./lib/boolean";
2
+ export * from "./lib/cacheProvider";
3
+ export * from "./lib/date";
4
+ export * from "./lib/enum";
5
+ export * from "./lib/guid";
6
+ export * from "./lib/localStorage";
7
+ export * from "./lib/mimeType";
8
+ export * from "./lib/number";
9
+ export * from "./lib/object";
10
+ export * from "./lib/string";
11
+ export * from "./lib/swissStandards";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a string to a boolean
3
+ * @param value The string to convert
4
+ * @returns The parsed boolean
5
+ */
6
+ export declare function parseBool(value?: string): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,55 @@
1
+ import { StandardEnum } from "./enum";
2
+ /**
3
+ * Methods to help caching data of any type.
4
+ * Data is put in containers and may be identified by a string key.
5
+ * Data can be saved, retrieved and reset.
6
+ * Based on Neolution.Abstractions.Caching.CacheProvider<TEnum>
7
+ * Ref: https://github.com/neolution-ch/Neolution.Abstractions/blob/main/Neolution.Abstractions/Caching/CacheProvider.cs
8
+ */
9
+ export declare class CacheProvider<TEnum> {
10
+ /**
11
+ * The enum variable
12
+ */
13
+ private readonly enumVariable;
14
+ /**
15
+ * The name of the cache
16
+ */
17
+ private readonly cacheName;
18
+ /**
19
+ * The cache
20
+ */
21
+ private readonly cache;
22
+ /**
23
+ * Initializes a new instance of the CacheProvider<TEnum> class
24
+ * @param enumVariable The enum variable
25
+ * @param cacheName The name of the cache
26
+ */
27
+ constructor(enumVariable: StandardEnum<TEnum>, cacheName: string);
28
+ /**
29
+ * Creates the cache key
30
+ * @param container The container
31
+ * @param key The key
32
+ * @returns The cache key
33
+ */
34
+ private createCacheKey;
35
+ /**
36
+ * Gets cached data from the specified container
37
+ * @param container The container
38
+ * @param key The key
39
+ * @returns The data from cache
40
+ */
41
+ getObject<T>(container: TEnum, key?: string): T | undefined;
42
+ /**
43
+ * Sets cached data identified by a key in the specified container
44
+ * @param container The container
45
+ * @param key The key
46
+ * @param cacheObject The cache object
47
+ */
48
+ setObject<T>(container: TEnum, key: string | undefined, cacheObject: T): void;
49
+ /**
50
+ * Resets cached data identified by a key of the specified container
51
+ * @param container The container
52
+ * @param key The key
53
+ */
54
+ reset(container: TEnum, key?: string): void;
55
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Check whether the date is valid
3
+ * @param date The date
4
+ * @returns A boolean indicating whether the date is valid
5
+ */
6
+ export declare function dateIsValid(date: Date): boolean;
7
+ /**
8
+ * Check whether the date is the first day of the month
9
+ * @param date The date
10
+ * @returns A boolean indicating whether the date is the first day of the month
11
+ */
12
+ export declare function dateIsFirstDayOfMonth(date: Date): boolean;
13
+ /**
14
+ * Check whether the date is the last day of the month
15
+ * @param date The date
16
+ * @returns A boolean indicating whether the date is the last day of the month
17
+ */
18
+ export declare function dateIsLastDayOfMonth(date: Date): boolean;
19
+ /**
20
+ * Check whether the date is a leap year
21
+ * @param date The date
22
+ * @returns A boolean indicating whether the date is a leap year
23
+ */
24
+ export declare function dateIsLeapYear(date: Date): boolean;
25
+ /**
26
+ * Check whether the date is a weekend
27
+ * @param date The date
28
+ * @returns A boolean indicating whether the date is a weekend
29
+ */
30
+ export declare function dateIsWeekend(date: Date): boolean;
31
+ /**
32
+ * Calculate the difference in days between two dates
33
+ * The order is not relevant hence the result is always positive
34
+ * @param from The start date
35
+ * @param to The end date
36
+ * @returns The difference in days between two dates
37
+ */
38
+ export declare function dateDifferenceInDays(from: Date, to: Date): number;
39
+ /**
40
+ * Get the next business date
41
+ * @param date The date
42
+ * @returns The next business date
43
+ */
44
+ export declare function getNextBusinessDate(date: Date): Date;
45
+ /**
46
+ * Get the start of a day for the given date
47
+ * @param date The date
48
+ * @returns The start of a day date
49
+ */
50
+ export declare function getStartOfDay(date: Date): Date;
51
+ /**
52
+ * Get the end of a day for the given date
53
+ * @param date The date
54
+ * @returns The end of a day date
55
+ */
56
+ export declare function getEndOfDay(date: Date): Date;
57
+ /**
58
+ * Get the first day of a year for the given date
59
+ * @param date The date
60
+ * @returns The first day of the date year
61
+ */
62
+ export declare function getFirstDayOfYear(date: Date): Date;
63
+ /**
64
+ * Get the last day of a year for the given date
65
+ * @param date The date
66
+ * @returns The last day of the date year
67
+ */
68
+ export declare function getLastDayOfYear(date: Date): Date;
69
+ /**
70
+ * Get the year quarter for the given date
71
+ * @param date The date
72
+ * @returns The year quarter
73
+ */
74
+ export declare function getQuarter(date: Date): number;
75
+ /**
76
+ * Shifts a date by a given number of quarters.
77
+ * @param date The date
78
+ * @param amount Number of quarters to shift by (negative values shift the date backwards)
79
+ * @returns A new Date shifted by the specified number of quarters
80
+ */
81
+ export declare function addQuarters(date: Date, amount: number): Date;
82
+ /**
83
+ * Get the date removing the time-zone offset
84
+ * @param date The date
85
+ * @returns the given date removing the time-zone offset
86
+ */
87
+ export declare function getDateWithoutTimeZone(date: Date): Date;
88
+ /**
89
+ * Get the date adding the time-zone offset
90
+ * @param date The date
91
+ * @returns the given date adding the time-zone offset
92
+ */
93
+ export declare function getDateAddTimeZone(date: Date): Date;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The standard enum type
3
+ */
4
+ export type StandardEnum<T> = {
5
+ [id: string]: T | string;
6
+ [nu: number]: string;
7
+ };
8
+ /**
9
+ * Returns the name of an enum from its value
10
+ * @param enumVariable The enum for which you want to get the name
11
+ * @param enumValue The value of the enum for which you want to get the name
12
+ * @returns A string containing the name of the enum
13
+ */
14
+ export declare function getEnumNameFromValue<T>(enumVariable: StandardEnum<T>, enumValue: T): string;
15
+ /**
16
+ * Returns the value of an enum from its name
17
+ * @param enumVariable The enum for which you want to get the value
18
+ * @param enumName The name of the enum for which you want to get the value
19
+ * @returns A string containing the value of the enum
20
+ */
21
+ export declare function getEnumValueFromName<T>(enumVariable: StandardEnum<T>, enumName: string): T;
22
+ /**
23
+ * Returns all the names of an enum
24
+ * @param enumVariable The enum for which you want to get the names
25
+ * @returns A string array containing the names of the enum
26
+ */
27
+ export declare function getEnumNames<T>(enumVariable: StandardEnum<T>): (string | T)[];
28
+ /**
29
+ * Returns all the values of an enum
30
+ * @param enumVariable The enum for which you want to get the values
31
+ * @returns A string or number array containing the values of the enum
32
+ */
33
+ export declare function getEnumValues<T>(enumVariable: StandardEnum<T>): T[];
34
+ /**
35
+ * Parses a string to an enum value
36
+ * @param enumVariable The enum for which you want to get the values
37
+ * @param value The string to parse
38
+ * @returns The enum value corresponding to the string, or undefined if not found
39
+ */
40
+ export declare function parseEnum<T>(enumVariable: StandardEnum<T>, value: string): T | undefined;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Create a new Guid (version 4 UUID)
3
+ * @returns A new Guid
4
+ */
5
+ export declare function newGuid(): string;
6
+ /**
7
+ * Check whether a string it is a valid Guid
8
+ * @param str The string to test whether it is a valid Guid
9
+ * @returns A value indicating whether the string is a valid Guid
10
+ */
11
+ export declare function isValidGuid(str: string): boolean;
12
+ /**
13
+ * The empty Guid (an identifier containing all zeros)
14
+ */
15
+ export declare const emptyGuid: string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Get an item from the localStorage
3
+ * @param key The key
4
+ * @returns The item
5
+ */
6
+ export declare function getLocalStorageItem<T>(key: string): T | undefined;
7
+ /**
8
+ * Set an item in the localStorage
9
+ * @param key The key
10
+ * @param data The item data
11
+ * @param expirationDate The expiration date
12
+ */
13
+ export declare function setLocalStorageItem<T>(key: string, data: T, expirationDate?: Date): void;
14
+ /**
15
+ * Remove an item from the localStorage
16
+ * @param key The key
17
+ */
18
+ export declare function removeLocalStorageItem(key: string): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Check if the MIME type represents an image
3
+ * @param mimeType The MIME type to check
4
+ * @returns true if the MIME type is for an image
5
+ */
6
+ export declare function isImageMimeType(mimeType?: string): boolean;
7
+ /**
8
+ * Check if the MIME type represents a PDF document
9
+ * @param mimeType The MIME type to check
10
+ * @returns true if the MIME type is for a PDF document
11
+ */
12
+ export declare function isPdfMimeType(mimeType?: string): boolean;
13
+ /**
14
+ * Check if the MIME type represents a video
15
+ * @param mimeType The MIME type to check
16
+ * @returns true if the MIME type is for a video
17
+ */
18
+ export declare function isVideoMimeType(mimeType?: string): boolean;
19
+ /**
20
+ * Check if the MIME type represents an audio file
21
+ * @param mimeType The MIME type to check
22
+ * @returns true if the MIME type is for an audio file
23
+ */
24
+ export declare function isAudioMimeType(mimeType?: string): boolean;
25
+ /**
26
+ * Check if the MIME type represents a text file
27
+ * @param mimeType The MIME type to check
28
+ * @returns true if the MIME type is for a text file
29
+ */
30
+ export declare function isTextMimeType(mimeType?: string): boolean;
31
+ /**
32
+ * Check if the MIME type represents an application file
33
+ * @param mimeType The MIME type to check
34
+ * @returns true if the MIME type is for an application file
35
+ */
36
+ export declare function isApplicationMimeType(mimeType?: string): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Returns a number whose value is limited to the given range
3
+ * @param value The initial value
4
+ * @param min The lower boundary
5
+ * @param max The upper boundary
6
+ * @returns A number in the range (min, max)
7
+ */
8
+ export declare function clamp(value: number, min: number, max: number): number;
9
+ /**
10
+ * Round a number with the specified precision
11
+ * @param value The number to round
12
+ * @param precision The desired precision
13
+ * @returns The number rounded with the specified precision
14
+ */
15
+ export declare function roundPrecision(value: number, precision: number): number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Check whether the provided parameter is of type `object` but not `null`, an `array`, a `regexp`, nor a `date`
3
+ * @param obj The object
4
+ * @returns A boolean indicating whether the parameter is an object
5
+ */
6
+ export declare const isObject: (obj: object) => boolean;
7
+ /**
8
+ * Convert null properties to undefined
9
+ * @param obj The object
10
+ */
11
+ export declare const convertNullToUndefined: (obj: object | object[]) => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Indicates whether a specified string is null/undefined or empty
3
+ * @param value The string to test
4
+ * @returns true if the value parameter is null/undefined or empty
5
+ */
6
+ export declare function isNullOrEmpty(value?: string): boolean;
7
+ /**
8
+ * Indicates whether a specified string is null/undefined, empty, or consists only of white-space characters
9
+ * @param value The string to test
10
+ * @returns true if the value parameter is null/undefined, Empty, or if value consists exclusively of white-space characters
11
+ */
12
+ export declare function isNullOrWhitespace(value?: string): boolean;
13
+ /**
14
+ * Capitalize the string
15
+ * @param value The string to capitalize
16
+ * @returns The capitalized string
17
+ */
18
+ export declare function capitalize(value?: string): string | undefined;
19
+ /**
20
+ * Uncapitalize the string
21
+ * @param value The string to uncapitalize
22
+ * @returns The uncapitalized string
23
+ */
24
+ export declare function uncapitalize(value?: string): string | undefined;
25
+ /**
26
+ * Truncates a string to a maximum length, adding a suffix if truncated
27
+ * @param value The string to truncate
28
+ * @param maxLength The maximum length of the resulting string
29
+ * @param suffix The suffix to append if truncated (default: "")
30
+ * @returns The truncated string
31
+ */
32
+ export declare function truncate(value: string | undefined, maxLength: number, suffix?: string): string | undefined;
33
+ /**
34
+ * Removes all occurrences of needle from the start of haystack
35
+ * @param haystack string to trim
36
+ * @param needle the thing to trim
37
+ * @returns the string trimmed from the left side
38
+ */
39
+ export declare function trimStart(haystack: string, needle: string): string;
40
+ /**
41
+ * Removes all occurrences of needle from the end of haystack
42
+ * @param haystack string to trim
43
+ * @param needle the thing to trim
44
+ * @returns the string trimmed from the right side
45
+ */
46
+ export declare function trimEnd(haystack: string, needle: string): string;
47
+ /**
48
+ * Removes all occurrences of needle from the start and the end of haystack
49
+ * @param haystack string to trim
50
+ * @param needle the thing to trim
51
+ * @returns the string trimmed from the right and left side
52
+ */
53
+ export declare function trim(haystack: string, needle: string): string;
54
+ /**
55
+ * Splits the string at line breaks
56
+ * @param str the string to split
57
+ * @param removeEmptyEntries the option to remove empty entries
58
+ * @param trimEntries the option to trim the entries
59
+ * @returns the individual lines as an array
60
+ */
61
+ export declare function splitLines(str: string, removeEmptyEntries?: boolean, trimEntries?: boolean): string[];
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Checks if the provided string is a valid swiss IBAN number
3
+ * @param ibanNumber The provided IBAN number to check
4
+ * Must be in one of the following formats:
5
+ * - "CHXX XXXX XXXX XXXX XXXX X" with whitespaces
6
+ * - "CHXXXXXXXXXXXXXXXXXXX" without whitespaces
7
+ * @returns The result of the IBAN number check
8
+ */
9
+ export declare function isValidSwissIbanNumber(ibanNumber: string): boolean;
10
+ /**
11
+ * Validation of a social insurance number with checking the checksum
12
+ * Validation according to https://www.sozialversicherungsnummer.ch/aufbau-neu.htm
13
+ * @param socialInsuranceNumber The social insurance number to check
14
+ * Must be in one of the following formats:
15
+ * - "756.XXXX.XXXX.XX" with dots as separators
16
+ * - "756XXXXXXXXXX" with digits only
17
+ * @returns The result if the social insurance number is valid or not
18
+ */
19
+ export declare function isValidSwissSocialInsuranceNumber(socialInsuranceNumber: string): boolean;
20
+ /**
21
+ * Attempts to parse and validate a Swiss IBAN.
22
+ * @param unformattedIbanNumber - The unformatted IBAN as a string
23
+ * @returns The result object with the following properties:
24
+ * @property {boolean} isValid - Indicates whether the IBAN is valid or not
25
+ * @property {string} iban - The cleaned IBAN, only present if valid
26
+ * @property {string} ibanFormatted - The formatted IBAN, only present if valid
27
+ */
28
+ export declare function tryParseSwissIbanNumber(unformattedIbanNumber?: string): {
29
+ /**
30
+ * Indicates whether the IBAN is valid or not
31
+ */
32
+ isValid: boolean;
33
+ /**
34
+ * The cleaned IBAN, only present if valid
35
+ */
36
+ iban?: string;
37
+ /**
38
+ * The formatted IBAN, only present if valid
39
+ */
40
+ ibanFormatted?: string;
41
+ };
42
+ /**
43
+ * Attempts to parse and validate a Swiss social insurance number.
44
+ * @param unformattedInsuranceNumber - The unformatted Swiss social insurance number
45
+ * @returns The result object with the following properties:
46
+ * @property {boolean} isValid - Indicates whether the Swiss social insurance number is valid or not
47
+ * @property {string} swissSocialInsuranceNumber - The cleaned Swiss social insurance number, only present if valid
48
+ * @property {string} swissSocialInsuranceNumberFormatted - The formatted Swiss social insurance number, only present if valid
49
+ */
50
+ export declare function tryParseSwissSocialInsuranceNumber(unformattedInsuranceNumber?: string): {
51
+ /**
52
+ * Indicates whether the Swiss social insurance number is valid or not
53
+ */
54
+ isValid: boolean;
55
+ /**
56
+ * The cleaned Swiss social insurance number, only present if valid
57
+ */
58
+ swissSocialInsuranceNumber?: string;
59
+ /**
60
+ * The formatted Swiss social insurance number, only present if valid
61
+ */
62
+ swissSocialInsuranceNumberFormatted?: string;
63
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,84 @@
1
- {
2
- "name": "@collana-solutions/javascript-utils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
1
+ {
2
+ "name": "@collana-solutions/javascript-utils",
3
+ "version": "2.6.0",
4
+ "description": "This is a collection of utilities that we have created to help with our development process.",
5
+ "homepage": "https://github.com/collana-solutions/javascript-utils#readme",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/collana-solutions/javascript-utils"
9
+ },
10
+ "license": "MIT",
11
+ "author": "collana solutions AG",
12
+ "sideEffects": false,
13
+ "exports": {
14
+ "./package.json": "./package.json",
15
+ ".": {
16
+ "types": "./dist/src/index.d.ts",
17
+ "import": "./dist/index.modern.js",
18
+ "require": "./dist/index.js"
19
+ }
20
+ },
21
+ "main": "dist/index.js",
22
+ "module": "dist/index.modern.js",
23
+ "source": "src/index.ts",
24
+ "jsnext:main": "dist/index.modern.js",
25
+ "types": "dist/src/index.d.ts",
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "build": "rollup -c --configPlugin rollup-plugin-typescript2",
31
+ "lint": "eslint --cache",
32
+ "prepack": "pnpm run build",
33
+ "prepare-pr": "pnpm exec prettier . --write && pnpm run lint && pnpm run build && pnpm run test",
34
+ "prettier-check": "prettier --check .",
35
+ "prettier-write": "prettier --write .",
36
+ "start": "rollup -c -w",
37
+ "test": "cross-env TZ=Europe/Zurich jest",
38
+ "start-all": "concurrently \"pnpm run start\" \"pnpm run start-yalc\"",
39
+ "start-yalc": "nodemon --watch dist -x \"yalc push\"",
40
+ "changeset": "changeset",
41
+ "version-packages": "changeset version",
42
+ "release": "changeset publish"
43
+ },
44
+ "dependencies": {
45
+ "date-fns": "^2.30.0",
46
+ "uuid": "^11.1.1"
47
+ },
48
+ "devDependencies": {
49
+ "@changesets/changelog-github": "^1.0.1",
50
+ "@changesets/cli": "^3.0.3",
51
+ "@jest/types": "^29.6.1",
52
+ "@neolution-ch/eslint-config-neolution": "^2.1.0",
53
+ "@rollup/plugin-commonjs": "^24.1.0",
54
+ "@rollup/plugin-node-resolve": "^15.0.2",
55
+ "@rollup/plugin-terser": "^0.4.1",
56
+ "@types/jest": "^29.5.3",
57
+ "@types/node": "^18.16.3",
58
+ "@types/rollup-plugin-peer-deps-external": "^2.2.5",
59
+ "concurrently": "^8.0.1",
60
+ "cross-env": "^7.0.3",
61
+ "eslint": "^9.24.0",
62
+ "jest": "^29.6.1",
63
+ "jest-localstorage-mock": "^2.4.26",
64
+ "jiti": "^2.4.2",
65
+ "nodemon": "^2.0.22",
66
+ "pkg-pr-new": "^0.0.93",
67
+ "prettier": "^3.5.3",
68
+ "rollup": "^3.21.4",
69
+ "rollup-plugin-peer-deps-external": "^2.2.4",
70
+ "rollup-plugin-typescript2": "^0.34.1",
71
+ "ts-jest": "^29.1.1",
72
+ "ts-node": "^10.9.2",
73
+ "typescript": "^5.1.6",
74
+ "yalc": "^1.0.0-pre.53"
75
+ },
76
+ "engines": {
77
+ "node": ">=18"
78
+ },
79
+ "publishConfig": {
80
+ "access": "public",
81
+ "registry": "https://registry.npmjs.org"
82
+ },
83
+ "packageManager": "pnpm@11.22.0"
84
+ }