@ngrdt/utils 0.0.5 → 0.0.6
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/.swcrc +29 -0
- package/eslint.config.js +22 -0
- package/jest.config.ts +30 -0
- package/package.json +7 -5
- package/project.json +29 -0
- package/rollup.config.js +20 -0
- package/src/index.ts +17 -0
- package/src/lib/__test__/array.utils.spec.ts +13 -0
- package/src/lib/__test__/css.utils.spec.ts +27 -0
- package/src/lib/__test__/date-format.spec.ts +71 -0
- package/src/lib/__test__/date.utils.spec.ts +72 -0
- package/src/lib/__test__/file-zip.utils.spec.ts +14 -0
- package/src/lib/__test__/object.utils.spec.ts +23 -0
- package/src/lib/__test__/random.utils.spec.ts +7 -0
- package/src/lib/__test__/string.utils.spec.ts +17 -0
- package/src/lib/types/aria.ts +334 -0
- package/src/lib/types/encodings.ts +273 -0
- package/src/lib/types/keyboard.ts +29 -0
- package/src/lib/types/mime-types.ts +119 -0
- package/src/lib/{router.utils.d.ts → types/router.ts} +1 -1
- package/src/lib/types/type.ts +43 -0
- package/src/lib/utils/array.ts +30 -0
- package/src/lib/utils/css.ts +69 -0
- package/src/lib/utils/date-format.ts +580 -0
- package/src/lib/utils/date.ts +363 -0
- package/src/lib/utils/file.ts +258 -0
- package/src/lib/utils/html.ts +26 -0
- package/src/lib/utils/model.ts +73 -0
- package/src/lib/utils/names.ts +73 -0
- package/src/lib/utils/object.ts +58 -0
- package/src/lib/utils/random.ts +9 -0
- package/src/lib/utils/rxjs.ts +30 -0
- package/src/lib/utils/string.ts +123 -0
- package/tsconfig.json +22 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +14 -0
- package/index.cjs.d.ts +0 -1
- package/index.cjs.js +0 -1
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -1
- package/src/index.d.ts +0 -17
- package/src/lib/array.utils.d.ts +0 -6
- package/src/lib/color.utils.d.ts +0 -5
- package/src/lib/css.utils.d.ts +0 -14
- package/src/lib/date-format.d.ts +0 -77
- package/src/lib/date.utils.d.ts +0 -60
- package/src/lib/encodings.d.ts +0 -44
- package/src/lib/file.utils.d.ts +0 -69
- package/src/lib/html.utils.d.ts +0 -4
- package/src/lib/keyboard.utils.d.ts +0 -36
- package/src/lib/mime-types.d.ts +0 -109
- package/src/lib/model.utils.d.ts +0 -22
- package/src/lib/names.d.ts +0 -19
- package/src/lib/object.utils.d.ts +0 -5
- package/src/lib/random.utils.d.ts +0 -4
- package/src/lib/rxjs.utils.d.ts +0 -6
- package/src/lib/string.utils.d.ts +0 -22
- package/src/lib/type.utils.d.ts +0 -13
package/.swcrc
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ngrdt/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"peerDependencies": {
|
|
5
|
-
"rxjs": ">=7.0.0"
|
|
5
|
+
"rxjs": ">=7.0.0",
|
|
6
|
+
"@angular/common": "~18.2.0",
|
|
7
|
+
"@angular/router": "~18.2.0"
|
|
6
8
|
},
|
|
7
|
-
"main": "./index.cjs
|
|
8
|
-
"module": "./index.
|
|
9
|
+
"main": "./index.cjs",
|
|
10
|
+
"module": "./index.js",
|
|
9
11
|
"types": "src/index.d.ts"
|
|
10
|
-
}
|
|
12
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './lib/utils/model';
|
|
2
|
+
export * from './lib/utils/array';
|
|
3
|
+
export * from './lib/utils/object';
|
|
4
|
+
export * from './lib/utils/random';
|
|
5
|
+
export * from './lib/utils/rxjs';
|
|
6
|
+
export * from './lib/types/type';
|
|
7
|
+
export * from './lib/utils/string';
|
|
8
|
+
export * from './lib/types/keyboard';
|
|
9
|
+
export * from './lib/utils/html';
|
|
10
|
+
export * from './lib/utils/date';
|
|
11
|
+
export * from './lib/utils/file';
|
|
12
|
+
export * from './lib/types/mime-types';
|
|
13
|
+
export * from './lib/utils/css';
|
|
14
|
+
export * from './lib/utils/date-format';
|
|
15
|
+
export * from './lib/types/encodings';
|
|
16
|
+
export * from './lib/types/router';
|
|
17
|
+
export * from './lib/types/aria';
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ObjectUtils } from '../object';
|
|
2
|
+
|
|
3
|
+
const testObj = {
|
|
4
|
+
a1: {
|
|
5
|
+
a2: {
|
|
6
|
+
a3: 'aaa',
|
|
7
|
+
},
|
|
8
|
+
a21: 'aaaaa',
|
|
9
|
+
},
|
|
10
|
+
b: null,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('object utils', () => {
|
|
14
|
+
it('should pluck dot notation path', () => {
|
|
15
|
+
expect(ObjectUtils.pluck(testObj, 'a1.a2')).toBe(testObj.a1.a2);
|
|
16
|
+
expect(ObjectUtils.pluck(testObj, 'a1.a21')).toBe('aaaaa');
|
|
17
|
+
expect(ObjectUtils.pluck(testObj, 'b')).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should not crash when path does not exist on object', () => {
|
|
21
|
+
expect(ObjectUtils.pluck(testObj, 'c1.c2' as any)).toBe(undefined);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StringUtils } from '../string';
|
|
2
|
+
|
|
3
|
+
describe('String utils', () => {
|
|
4
|
+
it('Sentence "Matfyz students are the best" should have 5 tokens.', () => {
|
|
5
|
+
const sentence = 'Matfyz students are the best.';
|
|
6
|
+
const tokens = StringUtils.tokenize(sentence);
|
|
7
|
+
|
|
8
|
+
expect(tokens.length).toEqual(5);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('The method must be resistant to undefined value.', () => {
|
|
12
|
+
const result = StringUtils.tokenize(undefined);
|
|
13
|
+
|
|
14
|
+
expect(Array.isArray(result)).toBeTruthy();
|
|
15
|
+
expect(result.length).toEqual(0);
|
|
16
|
+
});
|
|
17
|
+
});
|