Skip to content

Commit a8e992a

Browse files
Merge pull request #10 from angular-package/3.3.x
3.3.2
2 parents 8eee16a + cb1ce2d commit a8e992a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+836
-264
lines changed

packages/type/package.json

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,30 @@
1313
"registry": "https://registry.npmjs.org"
1414
},
1515
"keywords": [
16-
"angular-package",
17-
"@angular-package",
18-
"@angular-package/type",
19-
"guards",
16+
"array",
17+
"bigint",
18+
"boolean",
19+
"check",
20+
"defined",
21+
"determine",
22+
"function",
23+
"guard",
24+
"instance",
25+
"key",
26+
"propertyKey",
27+
"number",
28+
"object",
29+
"primitive",
30+
"string",
31+
"symbol",
32+
"undefined",
2033
"type",
2134
"types",
22-
"type guards"
35+
"type guards",
36+
"typescript",
37+
"angular-package",
38+
"@angular-package",
39+
"@angular-package/type"
2340
],
2441
"repository": {
2542
"type": "git",
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { check } from './check-args.func';
2-
32
/**
4-
* Checks if all of any arguments are a `'string'` type.
5-
* @param args Any arguments to check if they're all a `'string'` type.
6-
* @returns boolean.
7-
* @example https://www.typescriptlang.org/play?jsx=0#code/C4TwDgpgBAkgzgZWAJwJYDsDmUC8UAUAbgIYA2ArhAFxTHogCUuAfFCRdKnFHChpgG4AUKEhQACmgC2qYKkIRueAOQAjVJgzBlUAD5Q1Ae0OkIdHfuXpyU1RGQWDcELZOPlvNFnfl0AEwgAMwwIP2VhAGNDdF4oLiQvTBp4BP5cAnZKGjpGGkzObk80nFZ8uJjgOgiIQ0CoVKw9fVEaurKcDqc+b0jo2IiACwgIgGt0-BaaSVQZOQU4ABooADpV4mRMOGz6BhpVY1M6FigAbyEoKFNgKGRFclJrvBRKYQurqCkIYAHDP2TEbqCc48ADuskGBBaTDOFwuEWIcGgHkByhon2+v3S8UBAigqluxBGr1hAUCxHuwDRXx+fixAMSuPxZiJwIAvsDAoZkAQohVaBsoLV+ZtocCLrc4BT0uiafh1pgGMSLqg6vgJVKOngyaREaLYbCmYSlVB2RdTTcvuRkOgLZKHsJWb0+esIA1sHh8KtlvKtrQdnsDmYbSUoINhiN8MjEsoll6fYqhEIAPRJqAANXWqGIqlMcCEvNiCAAKgAlGAAOQA4gB9NMAQQAMgBVACi6WUDa5ECkcTAkqkAH5wvm+tdy02ALIAIRbJdrjdb6QATAB2J2xKcAeU3DZbdfL8+bba1ZER6+uTfLABEWwAxCstq+H1vVosAdU36V8pJCfmE70vG973LR9nxbYQRxiEwIGWUhDEwOVbjdfBALvB8n3rI8lmLMsqzApZx2nWd8KgLcdz3A9MNbBhFSgFMoG1RFILgaDYPgxDXUBfAcIrGsqJbbDS14sCaNxejnggZjWLghCXWQni8P4wTcL4hcBNI7dd33ETaPoxjJILaT2LkriFNUrCNPI7SlPqITFLU0S6NTfSgA
3+
* Checks if any of all the values are a `string`.
4+
* @param value Any arguments to check if they're all a `'string`.
5+
* @returns A `boolean` indicating whether or not all the `values` are an `Array`.
86
*/
9-
export const areString = (...args: any): boolean => check('string', ...args);
7+
export const areString = (...value: any): boolean => check('string', ...value);
Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11

22
import { areString } from '../lib/are-string.func';
33

4-
describe('areString()', () => {
4+
describe(areString.name, () => {
55

66
beforeEach(async () => {});
77

88
beforeEach(() => {});
99

10-
it('is DEFINED', () => {
11-
expect(areString).toBeDefined();
12-
});
10+
it('is DEFINED', () => expect(areString).toBeDefined());
1311

14-
it(`string to be TRUE`, () => {
15-
expect(areString('one', 'two', 'three')).toBeTruthy();
16-
});
12+
it(`string to be TRUE`, () => expect(areString('one', 'two', 'three')).toBeTruthy());
1713

18-
it(`number to be FALSE`, () => {
19-
expect(areString(1, 2, 3)).toBeFalsy();
20-
});
14+
it(`number to be FALSE`, () => expect(areString(1, 2, 3)).toBeFalsy());
2115

22-
it(`boolean to be FALSE`, () => {
23-
expect(areString(true, false, false)).toBeFalsy();
24-
});
16+
it(`boolean to be FALSE`, () => expect(areString(true, false, false)).toBeFalsy());
2517

26-
it(`string with number to be FALSE`, () => {
27-
expect(areString('one', 'two', 'three', 3)).toBeFalse();
28-
});
18+
it(`string with number to be FALSE`, () => expect(areString('one', 'two', 'three', 3)).toBeFalse());
2919

30-
it(`string with array to be FALSE`, () => {
31-
expect(areString('one', 'two', 'three', ['3'])).toBeFalse();
32-
});
20+
it(`string with array to be FALSE`, () => expect(areString('one', 'two', 'three', ['3'])).toBeFalse());
3321
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type AreString = (...params: any) => boolean;
1+
export type AreString = (...value: any) => boolean;
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { GuardIs } from './guard-is.interface';
2-
import { GuardAre } from './guard-are.interface';
3-
42
export interface Guard {
53
is: GuardIs;
6-
// are: GuardAre;
74
}

packages/type/src/guard/lib/guard-is.object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const guardIs: GuardIs = {
2424
function: guardFunction,
2525
instance: guardInstance,
2626
key: guardKey,
27-
number: guardNumber,
2827
null: guardNull,
28+
number: guardNumber,
2929
object: guardObject,
3030
objectKey: guardObjectKey,
3131
primitive: guardPrimitive,

packages/type/src/guard/lib/guard-primitive.func.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ import { ResultCallback } from '../../type/result-callback.type';
1313
* @returns A `boolean` indicating whether or not the `value` is the `Primitive` from the `type`.
1414
*/
1515
export const guardPrimitive: GuardPrimitive =
16-
<Type extends Primitive>(value: Type, type: Primitives, callback?: ResultCallback): value is Type =>
16+
<Type extends Primitive>(value: Type, type: Primitives, callback?: ResultCallback): value is Type =>
1717
isPrimitive<Type>(value, type, callback);
Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// Function.
22
import { guardArray } from '../lib/guard-array.func';
33
// Variables.
4-
import { BIGINT, BIGINT_INSTANCE } from '../../is/test/variables/big-int.const';
5-
import { Class } from '../../is/test/variables/class.const';
6-
import { Func } from '../../type/func.type';
7-
import { ObjectOne, ObjectTwo, OBJECT_ONE, OBJECT_TWO } from '../../is/test/variables/object.const';
84
import {
95
ARRAY_BIGINT,
106
ARRAY_BOOLEAN,
@@ -18,60 +14,31 @@ import {
1814
ARRAY_SYMBOL_NUMBER,
1915
ARRAY_SYMBOL_STRING,
2016
ARRAY_UNDEFINED
21-
} from '../../is/test/variables/array.const';
22-
import { FALSE, TRUE, FALSE_INSTANCE, TRUE_INSTANCE } from '../../is/test/variables/boolean.const';
23-
import { FUNCTION } from '../../is/test/variables/function.const';
24-
import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../is/test/variables/number.const';
25-
import { STRING, STRING_INSTANCE } from '../../is/test/variables/string.const';
26-
import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../is/test/variables/symbol.const';
27-
import { UNDEFINED } from '../../is/test/variables/undefined.const';
28-
import { notDefined } from '../../is/test/variables/not-defined.const';
17+
} from './variables/array.const';
18+
import { Class } from './variables/class.const';
19+
import { Func } from '../../type/func.type';
20+
import { ObjectOne, ObjectTwo } from './variables/object.const';
2921

30-
describe('guardArray', () => {
22+
describe(guardArray.name, () => {
3123
// TRUE
3224
it('is DEFINED', () => {
3325
expect(guardArray).toBeDefined();
3426
});
3527

3628
it('Array<bigint>', () => expect(guardArray<bigint>(ARRAY_BIGINT)).toBeTruthy());
37-
it('Array<boolean>', () => expect(guardArray<boolean>(ARRAY_BOOLEAN)).toBeTruthy());
29+
it('Array<boolean>', () => expect(guardArray<boolean | Boolean>(ARRAY_BOOLEAN)).toBeTruthy());
3830
it('Array<Class>', () => expect(guardArray<Class>(ARRAY_CLASS)).toBeTruthy());
3931
it('Array<Func>', () => expect(guardArray<Func>(ARRAY_FUNCTION)).toBeTruthy());
4032
it('Array<null>', () => expect(guardArray<null>(ARRAY_NULL)).toBeTruthy());
41-
it('Array<number>', () => expect(guardArray<number>(ARRAY_NUMBER)).toBeTruthy());
33+
it('Array<number>', () => expect(guardArray<number | Number>(ARRAY_NUMBER)).toBeTruthy());
4234
it('Array<ObjectOne> Array<ObjectTwo>', () => {
4335
expect(guardArray<ObjectOne>(ARRAY_OBJECT_ONE)).toBeTruthy();
4436
expect(guardArray<ObjectTwo>(ARRAY_OBJECT_TWO)).toBeTruthy();
4537
});
46-
it('Array<string>', () => expect(guardArray<string>(ARRAY_STRING)).toBeTruthy());
38+
it('Array<string>', () => expect(guardArray<string | String>(ARRAY_STRING)).toBeTruthy());
4739
it('Array<symbol>', () => {
4840
expect(guardArray<symbol>(ARRAY_SYMBOL_STRING)).toBeTruthy();
4941
expect(guardArray<symbol>(ARRAY_SYMBOL_NUMBER)).toBeTruthy();
5042
});
5143
it('Array<undefined>', () => expect(guardArray<undefined>(ARRAY_UNDEFINED)).toBeTruthy());
52-
53-
// FALSE
54-
it(`'bigint'`, () => {
55-
expect(guardArray(BIGINT)).toBeFalsy();
56-
expect(guardArray(BIGINT_INSTANCE)).toBeFalsy();
57-
});
58-
it(`'boolean' | Boolean`, () => {
59-
expect(guardArray(FALSE)).toBeFalsy();
60-
expect(guardArray(TRUE)).toBeFalsy();
61-
expect(guardArray(FALSE_INSTANCE)).toBeFalsy();
62-
expect(guardArray(TRUE_INSTANCE)).toBeFalsy();
63-
});
64-
it(`'number' | Number`, () => {
65-
expect(guardArray(NUMBER)).toBeFalsy();
66-
expect(guardArray(NUMBER_INSTANCE)).toBeFalsy();
67-
expect(guardArray(NUMBER_NEW_INSTANCE)).toBeFalsy();
68-
});
69-
it(`'string' | String`, () => {
70-
expect(guardArray<string>(STRING)).toBeFalsy();
71-
expect(guardArray<string>(STRING_INSTANCE)).toBeFalsy();
72-
});
73-
it(`'undefined'`, () => {
74-
expect(guardArray<undefined>(notDefined)).toBeFalse();
75-
expect(guardArray<undefined>(UNDEFINED)).toBeFalse();
76-
});
7744
});
Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,30 @@
11
// Function.
22
import { guardBigInt } from '../lib/guard-big-int.func';
33
// Variables.
4-
import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from '../../is/test/variables/big-int.const';
5-
// import { Class, CLASS } from '../../is/test/variables/class.const';
6-
// import { FUNCTION } from '../../is/test/variables/function.const';
7-
import { NULL } from '../../is/test/variables/null.const';
8-
import { NUMBER, NUMBER_INSTANCE, NUMBER_NEW_INSTANCE } from '../../is/test/variables/number.const';
9-
// import { OBJECT_ONE, OBJECT_TWO, OBJECT_ONE_NEW, OBJECT_TWO_NEW } from '../../is/test/variables/object.const';
10-
import { STRING, STRING_INSTANCE, STRING_NEW_INSTANCE } from '../../is/test/variables/string.const';
11-
// import { SYMBOL_NUMBER, SYMBOL_STRING } from '../../is/test/variables/symbol.const';
12-
import { TRUE, FALSE, FALSE_EXPECTATION, TRUE_EXPECTATION, TRUE_INSTANCE, FALSE_INSTANCE } from '../../is/test/variables/boolean.const';
13-
import { UNDEFINED } from '../../is/test/variables/undefined.const';
4+
import { BIGINT, BIGINT_EXPECTATION, BIGINT_INSTANCE } from './variables/big-int.const';
5+
import { TRUE } from './variables/boolean.const';
146

15-
describe(`guardBigInt`, () => {
7+
describe(guardBigInt.name, () => {
168
// Defined.
179
it('is DEFINED', () => expect(guardBigInt).toBeDefined());
1810

1911
// Checks ...
2012
describe(`checks`, () => {
2113
it('callback', () => {
22-
guardBigInt(STRING, (result: boolean) => {
23-
expect(result).toBe(FALSE);
14+
guardBigInt(BIGINT, (result: boolean, value: bigint) => {
15+
expect(result).toBe(TRUE);
16+
expect(value).toEqual(BIGINT);
2417
return result;
2518
});
2619
});
2720

28-
// ... arrays.
29-
describe(`array`, () => {
30-
// it(`${FUNCTION}`, () => expect(guardBigInt(FUNCTION, 'function')).toBe(FALSE));
31-
// it(`${Class}`, () => expect(guardBigInt(Class, 'function')).toBe(FALSE));
32-
});
33-
// ... function.
34-
describe(`function`, () => {
35-
// it(`FUNCTION`, () => expect(guardBigInt(FUNCTION)).toBe(FALSE));
36-
// it(`Class`, () => expect(guardBigInt(Class)).toBe(FALSE));
37-
});
38-
// ... objects.
39-
describe('object', () => {
40-
// it(`CLASS`, () => expect(guardBigInt(CLASS)).toBe(FALSE));
41-
// it(`OBJECT_ONE`, () => expect(guardBigInt(OBJECT_ONE)).toBe(FALSE));
42-
// it(`OBJECT_TWO`, () => expect(guardBigInt(OBJECT_TWO)).toBe(FALSE));
43-
// it(`new Object(OBJECT_ONE_NEW})`, () => expect(guardBigInt(OBJECT_ONE_NEW)).toBe(FALSE));
44-
// it(`new Object(OBJECT_TWO_NEW})`, () => expect(guardBigInt(OBJECT_TWO_NEW)).toBe(FALSE));
45-
});
4621
// ... primitives.
4722
describe(`primitive`, () => {
4823
// bigint
4924
describe(`bigint`, () => {
5025
it(`${BIGINT}`, () => expect(guardBigInt(BIGINT)).toBe(TRUE));
5126
it(`${BIGINT_EXPECTATION}`, () => expect(guardBigInt(BIGINT_INSTANCE)).toBe(TRUE));
5227
});
53-
54-
// boolean
55-
describe(`boolean`, () => {
56-
it(`${TRUE}`, () => expect(guardBigInt(TRUE)).toBe(FALSE));
57-
it(`${FALSE}`, () => expect(guardBigInt(FALSE)).toBe(FALSE));
58-
it(`${FALSE_EXPECTATION}`, () => expect(guardBigInt(TRUE_INSTANCE)).toBe(FALSE));
59-
it(`${TRUE_EXPECTATION}`, () => expect(guardBigInt(FALSE_INSTANCE)).toBe(FALSE));
60-
});
61-
62-
// null
63-
it(`${NULL}`, () => expect(guardBigInt(NULL)).toBe(FALSE));
64-
65-
// number
66-
describe(`number`, () => {
67-
it(`${NUMBER}`, () => expect(guardBigInt(NUMBER)).toBe(FALSE));
68-
it(`Number(${NUMBER})`, () => expect(guardBigInt(NUMBER_INSTANCE)).toBe(FALSE));
69-
it(`new Number(${NUMBER})`, () => expect(guardBigInt(NUMBER_NEW_INSTANCE)).toBe(FALSE));
70-
});
71-
// string
72-
describe(`string`, () => {
73-
it(`${STRING}`, () => expect(guardBigInt(STRING)).toBe(FALSE));
74-
it(`String(${STRING})`, () => expect(guardBigInt(STRING_INSTANCE)).toBe(FALSE));
75-
it(`new String(${STRING})`, () => expect(guardBigInt(STRING_NEW_INSTANCE)).toBe(FALSE));
76-
});
77-
// symbol
78-
describe(`symbol`, () => {
79-
// it(`Symbol(${NUMBER})`, () => expect(guardBigInt(SYMBOL_NUMBER)).toBe(FALSE));
80-
// it(`Symbol(${STRING})`, () => expect(guardBigInt(SYMBOL_STRING)).toBe(FALSE));
81-
});
82-
// undefined
83-
it(`${UNDEFINED}`, () => expect(guardBigInt(UNDEFINED)).toBe(FALSE));
8428
});
8529
});
8630
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Function.
2+
import { guardBoolean } from '../lib/guard-boolean.func';
3+
// Variables.
4+
import { FALSE_EXPECTATION, TRUE, TRUE_EXPECTATION, FALSE } from './variables/boolean.const';
5+
6+
describe(guardBoolean.name, () => {
7+
// Defined.
8+
it('is DEFINED', () => expect(guardBoolean).toBeDefined());
9+
10+
// Checks ...
11+
describe(`checks`, () => {
12+
it('callback', () => {
13+
guardBoolean(TRUE, (result: boolean, value: boolean) => {
14+
expect(result).toBe(TRUE);
15+
expect(value).toEqual(TRUE);
16+
return result;
17+
});
18+
});
19+
20+
// ... primitives.
21+
describe(`primitive`, () => {
22+
// boolean
23+
describe(`boolean`, () => {
24+
it(`${FALSE_EXPECTATION}`, () => expect(guardBoolean(FALSE)).toBe(TRUE));
25+
it(`${TRUE_EXPECTATION}`, () => expect(guardBoolean(TRUE)).toBe(TRUE));
26+
});
27+
});
28+
});
29+
});

0 commit comments

Comments
 (0)