Skip to content

Commit

Permalink
refactor(guardIs {}): add guardObjectKeysIn(), `guardStringIncludes…
Browse files Browse the repository at this point in the history
…()` and `guardStringIncludesSome()` functions and update missing tests.
  • Loading branch information
sciborrudnicki committed Sep 23, 2021
1 parent 691f07e commit 7387e23
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/guard/interface/guard-is.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import { guardObject } from '../lib/guard-object.func';
import { guardObjectKey } from '../lib/guard-object-key.func';
import { guardObjectKeyIn } from '../lib/guard-object-key-in.func';
import { guardObjectKeys } from '../lib/guard-object-keys.func';
import { guardObjectKeysIn } from '../lib/guard-object-keys-in.func';
import { guardObjectSomeKeys } from '../lib/guard-object-some-keys.func';
import { guardPrimitive } from '../lib/guard-primitive.func';
import { guardRegExp } from '../lib/guard-regexp.func';
import { guardString } from '../lib/guard-string.func';
import { guardStringIncludes } from '../lib/guard-string-includes.func';
import { guardStringIncludesSome } from '../lib/guard-string-includes-some.func';
import { guardStringLength } from '../lib/guard-string-length.func';
import { guardSymbol } from '../lib/guard-symbol.func';
import { guardTrue } from '../lib/guard-true.func';
Expand Down Expand Up @@ -95,6 +98,10 @@ export interface GuardIs {
* Guards the value to be an `object` of a generic type variable `Obj` with its specified `keys`.
*/
objectKeys: typeof guardObjectKeys;
/**
* Guards the value to be an `object` of a generic type variable `Obj` with specified keys in it(or its prototype chain).
*/
objectKeysIn: typeof guardObjectKeysIn;
/**
* Guards the value to be an `object` of a generic type variable `Obj` with its specified `keys`.
*/
Expand All @@ -111,6 +118,14 @@ export interface GuardIs {
* Guards the value to be `string` of any type.
*/
string: typeof guardString;
/**
* Guards the value to be a `string` type or an instance of `String` that includes all of the specified words/sentences.
*/
stringIncludes: typeof guardStringIncludes;
/**
* Guards the value to be a `string` type or an instance of `String` that includes some of the specified words/sentences.
*/
stringIncludesSome: typeof guardStringIncludesSome;
/**
* Guards the value to be a `string` of a length between the specified range.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/guard/lib/guard-is.object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import { guardObject } from './guard-object.func';
import { guardObjectKey } from './guard-object-key.func';
import { guardObjectKeyIn } from './guard-object-key-in.func';
import { guardObjectKeys } from './guard-object-keys.func';
import { guardObjectKeysIn } from './guard-object-keys-in.func';
import { guardObjectSomeKeys } from './guard-object-some-keys.func';
import { guardPrimitive } from './guard-primitive.func';
import { guardRegExp } from './guard-regexp.func';
import { guardString } from './guard-string.func';
import { guardStringIncludes } from './guard-string-includes.func';
import { guardStringIncludesSome } from './guard-string-includes-some.func';
import { guardStringLength } from './guard-string-length.func';
import { guardSymbol } from './guard-symbol.func';
import { guardTrue } from './guard-true.func';
Expand All @@ -46,10 +49,13 @@ export const guardIs: GuardIs = Object.freeze({
objectKey: guardObjectKey,
objectKeyIn: guardObjectKeyIn,
objectKeys: guardObjectKeys,
objectKeysIn: guardObjectKeysIn,
objectSomeKeys: guardObjectSomeKeys,
primitive: guardPrimitive,
regexp: guardRegExp,
string: guardString,
stringIncludes: guardStringIncludes,
stringIncludesSome: guardStringIncludesSome,
stringLength: guardStringLength,
symbol: guardSymbol,
true: guardTrue,
Expand Down
9 changes: 9 additions & 0 deletions src/guard/test/guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,29 @@ testing.describe(`guard`, () => {
testing
.it('guard', () => expect(guard).toBeDefined())
.it('guard.array()', () => expect(guard.array).toBeDefined())
.it('guard.bigint()', () => expect(guard.bigint).toBeDefined())
.it('guard.boolean()', () => expect(guard.boolean).toBeDefined())
.it('guard.class()', () => expect(guard.class).toBeDefined())
.it('guard.defined()', () => expect(guard.defined).toBeDefined())
.it('guard.false()', () => expect(guard.false).toBeDefined())
.it('guard.function()', () => expect(guard.function).toBeDefined())
.it('guard.instance()', () => expect(guard.instance).toBeDefined())
.it('guard.key()', () => expect(guard.key).toBeDefined())
.it('guard.null()', () => expect(guard.null).toBeDefined())
.it('guard.number()', () => expect(guard.number).toBeDefined())
.it('guard.numberBetween()', () => expect(guard.numberBetween).toBeDefined())
.it('guard.object()', () => expect(guard.object).toBeDefined())
.it('guard.objectKey()', () => expect(guard.objectKey).toBeDefined())
.it('guard.objectKeyIn()', () => expect(guard.objectKeyIn).toBeDefined())
.it('guard.objectKeys()', () => expect(guard.objectKeys).toBeDefined())
.it('guard.objectKeysIn()', () => expect(guard.objectKeysIn).toBeDefined())
.it('guard.objectSomeKeys()', () => expect(guard.objectSomeKeys).toBeDefined())
.it('guard.primitive()', () => expect(guard.primitive).toBeDefined())
.it('guard.string()', () => expect(guard.string).toBeDefined())
.it('guard.stringIncludes()', () => expect(guard.stringIncludes).toBeDefined())
.it('guard.stringIncludesSome()', () => expect(guard.stringIncludesSome).toBeDefined())
.it('guard.symbol()', () => expect(guard.symbol).toBeDefined())
.it('guard.true()', () => expect(guard.true).toBeDefined())
.it('guard.type()', () => expect(guard.type).toBeDefined())
.it('guard.undefined()', () => expect(guard.undefined).toBeDefined());
});
Expand Down

0 comments on commit 7387e23

Please sign in to comment.