@ngrdt/utils 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/index.cjs.d.ts +1 -0
  2. package/index.cjs.js +1 -0
  3. package/index.esm.d.ts +1 -0
  4. package/index.esm.js +1 -0
  5. package/package.json +6 -6
  6. package/src/lib/types/aria.d.ts +219 -0
  7. package/src/lib/types/encodings.d.ts +44 -0
  8. package/src/lib/types/keyboard.d.ts +36 -0
  9. package/src/lib/types/mime-types.d.ts +109 -0
  10. package/src/lib/types/{router.ts → router.d.ts} +1 -1
  11. package/src/lib/types/type.d.ts +13 -0
  12. package/src/lib/utils/array.d.ts +6 -0
  13. package/src/lib/utils/css.d.ts +19 -0
  14. package/src/lib/utils/date-format.d.ts +77 -0
  15. package/src/lib/utils/date.d.ts +60 -0
  16. package/src/lib/utils/file.d.ts +69 -0
  17. package/src/lib/utils/html.d.ts +4 -0
  18. package/src/lib/utils/model.d.ts +22 -0
  19. package/src/lib/utils/names.d.ts +19 -0
  20. package/src/lib/utils/object.d.ts +5 -0
  21. package/src/lib/utils/random.d.ts +4 -0
  22. package/src/lib/utils/rxjs.d.ts +6 -0
  23. package/src/lib/utils/string.d.ts +22 -0
  24. package/.swcrc +0 -29
  25. package/eslint.config.js +0 -22
  26. package/jest.config.ts +0 -30
  27. package/project.json +0 -29
  28. package/rollup.config.js +0 -20
  29. package/src/lib/__test__/array.utils.spec.ts +0 -13
  30. package/src/lib/__test__/css.utils.spec.ts +0 -27
  31. package/src/lib/__test__/date-format.spec.ts +0 -71
  32. package/src/lib/__test__/date.utils.spec.ts +0 -72
  33. package/src/lib/__test__/file-zip.utils.spec.ts +0 -14
  34. package/src/lib/__test__/object.utils.spec.ts +0 -23
  35. package/src/lib/__test__/random.utils.spec.ts +0 -7
  36. package/src/lib/__test__/string.utils.spec.ts +0 -17
  37. package/src/lib/types/aria.ts +0 -334
  38. package/src/lib/types/encodings.ts +0 -273
  39. package/src/lib/types/keyboard.ts +0 -29
  40. package/src/lib/types/mime-types.ts +0 -119
  41. package/src/lib/types/type.ts +0 -43
  42. package/src/lib/utils/array.ts +0 -30
  43. package/src/lib/utils/css.ts +0 -69
  44. package/src/lib/utils/date-format.ts +0 -580
  45. package/src/lib/utils/date.ts +0 -363
  46. package/src/lib/utils/file.ts +0 -258
  47. package/src/lib/utils/html.ts +0 -26
  48. package/src/lib/utils/model.ts +0 -73
  49. package/src/lib/utils/names.ts +0 -73
  50. package/src/lib/utils/object.ts +0 -58
  51. package/src/lib/utils/random.ts +0 -9
  52. package/src/lib/utils/rxjs.ts +0 -30
  53. package/src/lib/utils/string.ts +0 -123
  54. package/tsconfig.json +0 -22
  55. package/tsconfig.lib.json +0 -11
  56. package/tsconfig.spec.json +0 -14
  57. /package/src/{index.ts → index.d.ts} +0 -0
@@ -0,0 +1,19 @@
1
+ export declare class RdtCssUtils {
2
+ static normalizeColor(color: string): string | null;
3
+ private static normalizeHex;
4
+ private static normalizeRgb;
5
+ private static normalizeRgba;
6
+ private static isRgbColor;
7
+ private static isHexColor;
8
+ private static isRgbaColor;
9
+ private static rgbRegex;
10
+ private static rgbaRegex;
11
+ private static hexRegex;
12
+ }
13
+ export type RdtHorizontalDirection = 'left' | 'right';
14
+ export type RdtVerticalDirection = 'up' | 'down';
15
+ export interface RdtRgbColor {
16
+ r: number;
17
+ g: number;
18
+ b: number;
19
+ }
@@ -0,0 +1,77 @@
1
+ interface RdtNumericNode {
2
+ type: RdtFormatType.Day | RdtFormatType.Month | RdtFormatType.Year;
3
+ maxLength: number;
4
+ minLength: number;
5
+ }
6
+ declare enum RdtFormatType {
7
+ Day = "day",
8
+ Month = "month",
9
+ Year = "year",
10
+ Constant = "constant"
11
+ }
12
+ export declare const PRIMENG_DATE_FORMAT_META: Record<string, RdtNumericNode>;
13
+ export interface RdtDateInputConfig {
14
+ format: string;
15
+ yearInputMode: RdtYearInputMode;
16
+ twoDigitYearInputStrategy: RdtTwoDigitYearInputConversionStrategy;
17
+ leadingZeroMode: RdtLeadingZeroInputMode;
18
+ symbolMeta: Record<string, RdtNumericNode>;
19
+ insertMode: RdtInsertMode;
20
+ }
21
+ export declare enum RdtInsertMode {
22
+ Overwrite = 0,
23
+ Shift = 1
24
+ }
25
+ export declare enum RdtPasteMode {
26
+ Replace = 0,
27
+ Insert = 1
28
+ }
29
+ export declare enum RdtYearInputMode {
30
+ FourDigit = 1,
31
+ TwoDigit = 2,
32
+ Both = 3
33
+ }
34
+ export declare enum RdtLeadingZeroInputMode {
35
+ NoLeadingZero = 1,
36
+ LeadingZero = 2,
37
+ Both = 3
38
+ }
39
+ export type RdtTwoDigitYearInputConversionStrategy = 'past' | 'future';
40
+ export declare class RdtDateParser {
41
+ private cfg;
42
+ private _value;
43
+ private _inputValue;
44
+ private _parsedFormat;
45
+ private deleting;
46
+ private caretPosition;
47
+ constructor(cfg: RdtDateInputConfig);
48
+ set leadingZeroMode(mode: RdtLeadingZeroInputMode);
49
+ get leadingZeroMode(): RdtLeadingZeroInputMode;
50
+ set yearInputMode(mode: RdtYearInputMode);
51
+ get yearInputMode(): RdtYearInputMode;
52
+ set twoDigitYearInputStrategy(strategy: RdtTwoDigitYearInputConversionStrategy);
53
+ get twoDigitYearInputStrategy(): RdtTwoDigitYearInputConversionStrategy;
54
+ set insertMode(mode: RdtInsertMode);
55
+ get insertMode(): RdtInsertMode;
56
+ set format(format: string);
57
+ get format(): string;
58
+ onKeyDown(event: KeyboardEvent): void;
59
+ onKeyUp(event: KeyboardEvent): void;
60
+ onInput(event: InputEvent): void;
61
+ get value(): Date | null;
62
+ set value(d: Date | null);
63
+ set inputValue(value: string);
64
+ get inputValue(): string;
65
+ parse(input: string, caretPosition?: number, deleting?: boolean): {
66
+ prettyInput: string;
67
+ date: Date | null;
68
+ complete: boolean;
69
+ caret: number;
70
+ ambiguous: boolean;
71
+ };
72
+ private readNumber;
73
+ private parseFormat;
74
+ private useUpNumbersUntilNextSeparator;
75
+ private containsNonNumericCharacters;
76
+ }
77
+ export {};
@@ -0,0 +1,60 @@
1
+ import { Nullable } from '../types/type';
2
+ export declare class RdtDateUtils {
3
+ static readonly MS = 1;
4
+ static readonly SECOND: number;
5
+ static readonly MINUTE: number;
6
+ static readonly HOUR: number;
7
+ static readonly DAY: number;
8
+ /**
9
+ * Returns number of days between two dates.
10
+ * Returns zero in case dates are the same. Ignores time.
11
+ */
12
+ static getDays(a: Date | string | number, b: Date | string | number): number;
13
+ static checkDate(year: number, month: number, day: number): boolean;
14
+ static isValidDate(value: any): value is string | number | Date;
15
+ static startOfDay(input: Date | string): Date;
16
+ static endOfDay(input: Date | string): Date;
17
+ static startOfMonth(input: Date | string): Date;
18
+ static endOfMonth(input: Date | string): Date;
19
+ static startOfYear(year: number): Date;
20
+ static endOfYear(year: number): Date;
21
+ static beginningOfNextMonth(): Date;
22
+ static endOfNextMonth(): Date;
23
+ static beginningOfInThreeMonths(): Date;
24
+ static endOfInNextThreeMonths(): Date;
25
+ static minusOneDay(date: Date): Date;
26
+ static toISOLocal(d: Date): string;
27
+ static formatDate(date: any): string;
28
+ static timeToDate(time: string): Date | null;
29
+ static setTime(date: Date, time: string): Date;
30
+ static getTime(d: Date, showSeconds?: boolean): string;
31
+ static parseToDate(input: Nullable<string | Date>): Date | null;
32
+ static parse(input: Nullable<string | Date>): number | null;
33
+ static isEqual(d1: Date | null, d2: Date | null): boolean;
34
+ static isLeapYear(year: number): boolean;
35
+ static getDaysInYear(year: number): 365 | 366;
36
+ private static hhMmRegex;
37
+ private static hhMmSsRegex;
38
+ private static hhMmSsMsRegex;
39
+ private static daysUpToMonth;
40
+ private static daysUpToMonthLeapYear;
41
+ private static getDayOffset;
42
+ static doubleDigitYearToPast(year2: number): number;
43
+ static doubleDigitYearToFuture(year2: number): number;
44
+ static getCurrentYear(): number;
45
+ static calculateAge(birthDateStr: string, referenceDateStr: string): number;
46
+ }
47
+ export declare enum Month {
48
+ January = 0,
49
+ February = 1,
50
+ March = 2,
51
+ April = 3,
52
+ May = 4,
53
+ June = 5,
54
+ July = 6,
55
+ August = 7,
56
+ September = 8,
57
+ October = 9,
58
+ November = 10,
59
+ December = 11
60
+ }
@@ -0,0 +1,69 @@
1
+ import { HttpResponse } from '@angular/common/http';
2
+ import { RdtEncoding } from '../types/encodings';
3
+ import { RdtMimeType } from '../types/mime-types';
4
+ import { Nullable } from '../types/type';
5
+ export declare enum RdtMsOfficeAction {
6
+ Edit = "ofe|u|",
7
+ View = "ofv|u|"
8
+ }
9
+ export declare enum RdtMsOfficeApp {
10
+ Word = "ms-word",
11
+ Excel = "ms-excel",
12
+ PowerPoint = "ms-powerpoint"
13
+ }
14
+ export interface RdtMsOfficeConfig {
15
+ mimeType?: RdtMimeType;
16
+ app?: RdtMsOfficeApp;
17
+ action?: RdtMsOfficeAction;
18
+ }
19
+ export interface RdtDocumentFile<T = string> {
20
+ fileName: string;
21
+ content?: T;
22
+ url?: string;
23
+ mimeType?: RdtMimeType;
24
+ size?: number;
25
+ modified?: Date;
26
+ originalFile?: File;
27
+ }
28
+ export interface DokumentProtokol {
29
+ DokumentProtokol: {
30
+ filename: string;
31
+ content_data: string;
32
+ guid: string;
33
+ code: string;
34
+ };
35
+ }
36
+ export declare const Rdt_DEFAULT_MIME_TYPE = RdtMimeType.BIN;
37
+ export declare const Rdt_DEFAULT_MS_OFFICE_ACTION = RdtMsOfficeAction.View;
38
+ export declare enum FileSizeUnit {
39
+ B = "B",
40
+ KB = "KB",
41
+ MB = "MB",
42
+ GB = "GB",
43
+ TB = "TB",
44
+ PB = "PB",
45
+ EB = "EB",
46
+ ZB = "ZB",
47
+ YB = "YB"
48
+ }
49
+ export type RdtFileSize = `${number} ${FileSizeUnit}`;
50
+ export declare class FileUtils {
51
+ static getMsOfficeLink(url: string, config: RdtMsOfficeConfig): string;
52
+ static openFileFromRemoteUrl(url: string, config: RdtMsOfficeConfig): void;
53
+ static openFileInBrowser(stringData: string, mimeType?: RdtMimeType): void;
54
+ static fileAsArrayBuffer(file: Blob): Promise<ArrayBuffer>;
55
+ static fileAsText(file: Blob, encoding?: RdtEncoding): Promise<string>;
56
+ static downloadFileFromData(stringData: string, filename: string, mimeType?: RdtMimeType): void;
57
+ static downloadFileFromRemoteUrl(url: string, filename: string, mimeType?: RdtMimeType): void;
58
+ static getMimeTypeFromBase64(base64Data: string): RdtMimeType | undefined;
59
+ static getMimeTypeFromFileName(fileName: Nullable<string>): RdtMimeType;
60
+ static getFileName(filename: string, mimeType?: RdtMimeType): string;
61
+ static getBase64Link(base64Data: string, mimeType?: RdtMimeType): string;
62
+ static getMimeTypeFromResponse(resp: HttpResponse<Blob>): RdtMimeType;
63
+ static getFileNameFromResponse(resp: HttpResponse<Blob>): string;
64
+ static blobToDataUrl(file: Blob): Promise<string>;
65
+ static convertFromBytes(bytes: number, decimals?: number): string;
66
+ static convertToBytes(amount: number, unit: FileSizeUnit): number;
67
+ static fileSizeToBytes(fileSize: RdtFileSize): number | null;
68
+ static getMsOfficeAppByMimeType(mimeType: RdtMimeType | undefined): RdtMsOfficeApp | null;
69
+ }
@@ -0,0 +1,4 @@
1
+ export declare class RdtHTMLUtils {
2
+ static scrollIntoViewHorizontallyWithinParent(element: HTMLElement): void;
3
+ static setCaretPosition(element: HTMLInputElement, index: number): void;
4
+ }
@@ -0,0 +1,22 @@
1
+ export declare class RdtModelUtils {
2
+ static inferPropertyInfo(properties: {
3
+ key: string;
4
+ type: string;
5
+ }[], interfaceName: string): RdtModelProperty[];
6
+ static names(name: string): {
7
+ name: string;
8
+ className: string;
9
+ propertyName: string;
10
+ constantName: string;
11
+ fileName: string;
12
+ };
13
+ }
14
+ export interface RdtModelProperty {
15
+ key: string;
16
+ type: 'string' | 'number' | 'date' | 'boolean' | 'array' | 'object' | 'any';
17
+ formControlType: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'any';
18
+ required: boolean;
19
+ foreignKey: boolean;
20
+ primaryKey: boolean;
21
+ probablyBoolean: boolean;
22
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * From @nx/devkit because it has nodejs as dependency and won't transpile.
3
+ * Util function to generate different strings based off the provided name.
4
+ *
5
+ * Examples:
6
+ *
7
+ * ```typescript
8
+ * names("my-name") // {name: 'my-name', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
9
+ * names("myName") // {name: 'myName', className: 'MyName', propertyName: 'myName', constantName: 'MY_NAME', fileName: 'my-name'}
10
+ * ```
11
+ * @param name
12
+ */
13
+ export declare function names(name: string): {
14
+ name: string;
15
+ className: string;
16
+ propertyName: string;
17
+ constantName: string;
18
+ fileName: string;
19
+ };
@@ -0,0 +1,5 @@
1
+ export declare class RdtObjectUtils {
2
+ static pluck<T>(obj: T, path: string | (string | number)[]): any;
3
+ static notNullGuard<T>(value: T | undefined | null): value is T;
4
+ static expandKey(key: string, value: any): any;
5
+ }
@@ -0,0 +1,4 @@
1
+ export declare class RdtRandomUtils {
2
+ static randomId(): string;
3
+ static trueFalse(): boolean;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare class RdtRxUtils {
3
+ static repeatLatestWhen<T>(notifier$: Observable<any>): (source: Observable<T>) => Observable<T>;
4
+ static completeIfNull<T>(source$: Observable<T>): Observable<NonNullable<T>>;
5
+ static makeObservable<T>(value: T | Observable<T>): Observable<T>;
6
+ }
@@ -0,0 +1,22 @@
1
+ import { Params } from '@angular/router';
2
+ import { Nullable } from '../types/type';
3
+ export declare class RdtStringUtils {
4
+ static tokenize(value: string | undefined): string[];
5
+ static joinPaths(parent: string, child: string): string;
6
+ static isAlphabetCharacter(char: string): boolean;
7
+ static isNumericCharacter(char: string): boolean;
8
+ static capitalize(str: string): string;
9
+ static toDataTestId(str: string): string;
10
+ static removeAccents(str: string): string;
11
+ static stripTrailingSlash(url: string): string;
12
+ static createAbsoluteUrl(url: string, baseHref: string): string;
13
+ static appendQueryParams(url: string, params: Nullable<Params>): string;
14
+ static localeCompare(a: Nullable<string>, b: Nullable<string>, order?: 'asc' | 'desc'): number;
15
+ static komixcomlocalReplaceString(url: string): {
16
+ replaceString: string;
17
+ toReplace: string;
18
+ };
19
+ static swapChars(src: string, i: number, j: number): string;
20
+ static insertAt(src: string, index: number, value: string): string;
21
+ static getDataTestId(label: string, prefix?: Nullable<string>, suffix?: Nullable<string>): string;
22
+ }
package/.swcrc DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2017",
4
- "parser": {
5
- "syntax": "typescript",
6
- "decorators": true,
7
- "dynamicImport": true
8
- },
9
- "transform": {
10
- "decoratorMetadata": true,
11
- "legacyDecorator": true
12
- },
13
- "keepClassNames": true,
14
- "externalHelpers": true,
15
- "loose": true
16
- },
17
- "module": {
18
- "type": "es6"
19
- },
20
- "sourceMaps": true,
21
- "exclude": [
22
- "jest.config.ts",
23
- ".*\\.spec.tsx?$",
24
- ".*\\.test.tsx?$",
25
- "./src/jest-setup.ts$",
26
- "./**/jest-setup.ts$",
27
- ".*.js$"
28
- ]
29
- }
package/eslint.config.js DELETED
@@ -1,22 +0,0 @@
1
- const baseConfig = require('../../eslint.config.js');
2
-
3
- module.exports = [
4
- ...baseConfig,
5
- {
6
- files: ['**/*.json'],
7
- rules: {
8
- '@nx/dependency-checks': [
9
- 'error',
10
- {
11
- ignoredFiles: [
12
- '{projectRoot}/eslint.config.{js,cjs,mjs}',
13
- '{projectRoot}/rollup.config.{js,ts,mjs,mts}',
14
- ],
15
- },
16
- ],
17
- },
18
- languageOptions: {
19
- parser: require('jsonc-eslint-parser'),
20
- },
21
- },
22
- ];
package/jest.config.ts DELETED
@@ -1,30 +0,0 @@
1
- /* eslint-disable */
2
- import { readFileSync } from 'fs';
3
-
4
- // Reading the SWC compilation config and remove the "exclude"
5
- // for the test files to be compiled by SWC
6
- const { exclude: _, ...swcJestConfig } = JSON.parse(
7
- readFileSync(`${__dirname}/.swcrc`, 'utf-8')
8
- );
9
-
10
- // disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
11
- // If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
12
- if (swcJestConfig.swcrc === undefined) {
13
- swcJestConfig.swcrc = false;
14
- }
15
-
16
- // Uncomment if using global setup/teardown files being transformed via swc
17
- // https://nx.dev/nx-api/jest/documents/overview#global-setupteardown-with-nx-libraries
18
- // jest needs EsModule Interop to find the default exported setup/teardown functions
19
- // swcJestConfig.module.noInterop = false;
20
-
21
- export default {
22
- displayName: '@ngrdt/utils',
23
- preset: '../../jest.preset.js',
24
- transform: {
25
- '^.+\\.[tj]s$': ['@swc/jest', swcJestConfig],
26
- },
27
- moduleFileExtensions: ['ts', 'js', 'html'],
28
- testEnvironment: 'node',
29
- coverageDirectory: '../../coverage/@ngrdt/utils',
30
- };
package/project.json DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "name": "@ngrdt/utils",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "@ngrdt/utils/src",
5
- "projectType": "library",
6
- "release": {
7
- "version": {
8
- "generatorOptions": {
9
- "packageRoot": "dist/{projectRoot}",
10
- "currentVersionResolver": "git-tag"
11
- }
12
- }
13
- },
14
- "tags": [],
15
- "targets": {
16
- "nx-release-publish": {
17
- "options": {
18
- "packageRoot": "dist/{projectRoot}"
19
- }
20
- },
21
- "test": {
22
- "executor": "@nx/jest:jest",
23
- "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
24
- "options": {
25
- "jestConfig": "@ngrdt/utils/jest.config.ts"
26
- }
27
- }
28
- }
29
- }
package/rollup.config.js DELETED
@@ -1,20 +0,0 @@
1
- const { withNx } = require('@nx/rollup/with-nx');
2
- const { terser } = require('rollup-plugin-terser');
3
-
4
-
5
- module.exports = withNx(
6
- {
7
- main: './src/index.ts',
8
- outputPath: '../../dist/@ngrdt/utils',
9
- tsConfig: './tsconfig.lib.json',
10
- compiler: 'swc',
11
- format: ['cjs', 'esm'],
12
- assets: [{ input: './@ngrdt/utils', output: '.', glob: '*.md' }],
13
- },
14
- {
15
- plugins: [terser()]
16
- // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
17
- // e.g.
18
- // output: { sourcemap: true },
19
- }
20
- );
@@ -1,13 +0,0 @@
1
- import { ArrayUtils } from '../array';
2
-
3
- describe('ArrayUtils', () => {
4
- it('Should remove third element.', () => {
5
- const input = [0, 1, 2, 3, 4];
6
- const removed = ArrayUtils.removeAt(input, 2);
7
-
8
- expect(removed.length).toEqual(4);
9
- expect(removed[1]).toEqual(1);
10
- expect(removed[2]).toEqual(3);
11
- expect(removed[3]).toEqual(4);
12
- });
13
- });
@@ -1,27 +0,0 @@
1
- import { CssUtils } from '../css';
2
-
3
- describe('CssUtils', () => {
4
- it('Should normalize colors.', () => {
5
- expect(CssUtils.normalizeColor('#fff')).toEqual('#fff');
6
- expect(CssUtils.normalizeColor('fff')).toEqual('#fff');
7
- expect(CssUtils.normalizeColor('fffff')).toBeNull();
8
- expect(CssUtils.normalizeColor('232,241, 32')).toEqual('rgb(232,241,32)');
9
- expect(CssUtils.normalizeColor('rgb(232, 241, 32)')).toEqual(
10
- 'rgb(232,241,32)'
11
- );
12
- expect(CssUtils.normalizeColor('rgb(632, 241, 32)')).toBeNull();
13
- expect(CssUtils.normalizeColor(' 232 - 241, 32')).toEqual(
14
- 'rgb(232,241,32)'
15
- );
16
- expect(CssUtils.normalizeColor('rgba(232, 241, 32, 0.5)')).toEqual(
17
- 'rgba(232,241,32,0.5)'
18
- );
19
- expect(CssUtils.normalizeColor('rgba(232, 241, 32, 1.2)')).toBeNull();
20
- expect(CssUtils.normalizeColor('rgba(232, 241, 32, 1.0)')).toEqual(
21
- 'rgba(232,241,32,1.0)'
22
- );
23
- expect(CssUtils.normalizeColor('232, 241, 32 1.0)')).toEqual(
24
- 'rgba(232,241,32,1.0)'
25
- );
26
- });
27
- });
@@ -1,71 +0,0 @@
1
- import {
2
- DateInputConfig,
3
- DateParser,
4
- InsertMode,
5
- LeadingZeroInputMode,
6
- PRIMENG_DATE_FORMAT_META,
7
- YearInputMode,
8
- } from '../date-format';
9
-
10
- describe('DateFormat', () => {
11
- it('parse date.', () => {
12
- const cfg: DateInputConfig = {
13
- format: 'd.m.yy',
14
- symbolMeta: PRIMENG_DATE_FORMAT_META,
15
- leadingZeroMode: LeadingZeroInputMode.Both,
16
- twoDigitYearInputStrategy: 'past',
17
- yearInputMode: YearInputMode.Both,
18
- insertMode: InsertMode.Overwrite,
19
- };
20
-
21
- const parser = new DateParser(cfg);
22
-
23
- const res1 = parser.parse('01.01.21');
24
-
25
- expect(res1).toBeTruthy();
26
- expect(res1?.date).toBeTruthy();
27
- expect(res1?.date?.getFullYear()).toEqual(2021);
28
- expect(res1?.date?.getMonth()).toEqual(0);
29
- expect(res1?.date?.getDate()).toEqual(1);
30
-
31
- const res2 = parser.parse('01 01 ');
32
-
33
- expect(res2).toBeTruthy();
34
- expect(res2?.date).toBeNull();
35
- expect(res2?.complete).toBeFalsy();
36
- expect(res2?.prettyInput).toEqual('01.01.');
37
-
38
- const res3 = parser.parse('01.01');
39
-
40
- expect(res3).toBeTruthy();
41
- expect(res3?.date).toBeNull();
42
- expect(res3?.complete).toBeFalsy();
43
- expect(res3?.prettyInput).toEqual('01.01.');
44
-
45
- const res4 = parser.parse('01.1ab');
46
- expect(res4).toBeTruthy();
47
- expect(res4?.date).toBeNull();
48
- expect(res4?.complete).toBeFalsy();
49
- expect(res4?.prettyInput).toEqual('01.1.');
50
-
51
- const res5 = parser.parse('01.1');
52
- expect(res5).toBeTruthy();
53
- expect(res5?.date).toBeNull();
54
- expect(res5?.complete).toBeFalsy();
55
- expect(res5?.prettyInput).toEqual('01.1');
56
-
57
- const res6 = parser.parse('41.2.21');
58
- expect(res6).toBeTruthy();
59
- expect(res6?.prettyInput).toEqual('4.2.21');
60
- expect(res6?.date?.getFullYear()).toEqual(2021);
61
- expect(res6?.date?.getMonth()).toEqual(1);
62
- expect(res6?.complete).toBeTruthy();
63
-
64
- const res7 = parser.parse('411.34.21');
65
- expect(res7).toBeTruthy();
66
- expect(res7?.prettyInput).toEqual('4.3.21');
67
- expect(res7?.date?.getFullYear()).toEqual(2021);
68
- expect(res7?.date?.getMonth()).toEqual(2);
69
- expect(res7?.complete).toBeTruthy();
70
- });
71
- });
@@ -1,72 +0,0 @@
1
- import { DateUtils } from '../date';
2
-
3
- describe('DateUtils', () => {
4
- it('Parse time to Date and detect invalid values.', () => {
5
- const hhmmValid = '12:34';
6
- const hhmmssValid = '12:34:56';
7
- const hhmmssmsValid = '12: 34:56 . 789';
8
-
9
- const hhmmParsed = DateUtils.timeToDate(hhmmValid);
10
- const hhmmssParsed = DateUtils.timeToDate(hhmmssValid);
11
- const hhmmssmsParsed = DateUtils.timeToDate(hhmmssmsValid);
12
-
13
- const invalids = [
14
- 'null',
15
- ' ',
16
- ' 3',
17
- '25:43',
18
- '03:60',
19
- '03:59:60',
20
- '03:59:59:f',
21
- '03:59:59:1111',
22
- ];
23
-
24
- expect(hhmmParsed).toBeTruthy();
25
- expect(hhmmParsed?.getHours()).toEqual(12);
26
- expect(hhmmParsed?.getMinutes()).toEqual(34);
27
- expect(hhmmParsed?.getSeconds()).toEqual(0);
28
-
29
- expect(hhmmssParsed).toBeTruthy();
30
- expect(hhmmssParsed?.getHours()).toEqual(12);
31
- expect(hhmmssParsed?.getMinutes()).toEqual(34);
32
- expect(hhmmssParsed?.getSeconds()).toEqual(56);
33
-
34
- expect(hhmmssmsParsed).toBeTruthy();
35
- expect(hhmmssmsParsed?.getHours()).toEqual(12);
36
- expect(hhmmssmsParsed?.getMinutes()).toEqual(34);
37
- expect(hhmmssmsParsed?.getSeconds()).toEqual(56);
38
- expect(hhmmssmsParsed?.getMilliseconds()).toEqual(789);
39
-
40
- invalids.forEach((invalid) => {
41
- expect(DateUtils.timeToDate(invalid)).toBeNull();
42
- });
43
- });
44
-
45
- it('works with medieval dates.', () => {
46
- const dateStrs = [
47
- '2019-11-11T00:00:00',
48
- '1111-11-11T00:00:00',
49
- '1532-11-11T01:40:54',
50
- '1402-12-31T23:59:59',
51
- ];
52
-
53
- const dates = [
54
- new Date(2019, 10, 11, 0, 0, 0),
55
- new Date(1111, 10, 11, 0, 0, 0),
56
- new Date(1532, 10, 11, 1, 40, 54),
57
- new Date(1402, 11, 31, 23, 59, 59),
58
- ];
59
-
60
- dateStrs.forEach((dateStr) => {
61
- const date = new Date(dateStr);
62
- const str2 = DateUtils.toISOLocal(date);
63
- expect(str2).toEqual(dateStr);
64
- });
65
-
66
- dates.forEach((date) => {
67
- const str = DateUtils.toISOLocal(date);
68
- const date2 = new Date(str);
69
- expect(date2).toEqual(date);
70
- });
71
- });
72
- });
@@ -1,14 +0,0 @@
1
- import { FileZipUtils } from '../file-zip';
2
-
3
- const file =
4
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAADG0lEQVR4nAEQA+/8AawKf+AlKzhoy+J/Qhq2ahh3knZXSAQI4HHUosjxAFpxjL+cYy9qNcw3sLqQoX3BcAEktwVMoDW79QwR/56ccqA2mxaknvIb1rltbeQoiBnmuaQ1NOSqnCCoDb6WMAZjWMwBWF5rOfMg/BMaWY9HM08dvQtiWcXdaU0Ocbz4DXlJ2BHcGoiSyOZAjuBNyOIz+DMwBKbpyskInCe/qC/G8qfHtQhJ/VfoqMhEFs+MHPQK5RocgHr2A03wyGigMHI0zjzD6AKQ9BJXWFqNlXHAGMUBNkG2txIsKlbqUxCnK0AlbyYs9SxYdA+tv96WYYZXowTUcswEFa9yJRTAODGrUAX7RXenSgyeCr3Yjt4bSlL7EmAkaWBhjq1/PBj2N0Fiy2nuN+etACZOspzoDeo49GLvnRHx8GJPeZnxhLEQ52nGi64q7C9zurUIXB+68Zx4U+FvAVEA5wQbp+UW8mKA4bWNe3LX/qiW1PS5uS1+JMBIJiP94c+RuPTh09kzAb6/of1lxn/2LNkAjum/UGPKmps1JhxdjEs2U3lq+JGqP9YJVDBIcMvIX6JEEQb9BrN99cSbHxovRB2nAX/yeLYCv16uTAGppjioojJxUDRDmfJN4MTDQ1iXONQcgBD26HBmDuUdJxlbDslg5QKYSTrz23P0tAr39vOpnvGu8RzTAXz+QL1JPojj95ctXRoU87sPUJJ63RnSIKUB/QoBxZwsDcJCp6WSKNgY0PxaLtsc5CSWcp6IrXPtdknKucj6bgGcRFDYXRm1GRWkxf9YAc0DDS1tREmeluTJs25U5d6e4c30H6lghhcZAwpU7wnne/b11iLMfs+IbctkTMjm3QRK1cI04wfYC5vVjZyJ7i49mQz077/1SdyjvSzHVIOnDQnvgMjLdbs9mKcOk9Ty/xEEzPI9rtlQLGJ1oBPBuWb/CdE9jOp5aCkJzhb/71yCv7HFQgYY6jWz8WPa0Zv7qivxAkjygcDU1+4lOtjrZ9DxWFWY7MqcQtn/u/e8VZ98GJXsv0qltwJ/fy4JRv9BWAS/HiDjhywl59k8AAAAAElFTkSuQmCC';
5
-
6
- describe('file-zip utils', () => {
7
- it('compressPepaWay should be equal to decompressPepaWay', async () => {
8
- const arrayBuffer = await fetch(file).then((f) => f.arrayBuffer());
9
- const zippedResult = FileZipUtils.compressPepaWay(arrayBuffer);
10
-
11
- const result = FileZipUtils.decompressPepaWay(zippedResult);
12
- expect(result).toEqual(file.split(',')[1]);
13
- });
14
- });