Skip to content

Commit d811468

Browse files
docs(README.md): update
1 parent 4185c72 commit d811468

File tree

2 files changed

+138
-102
lines changed

2 files changed

+138
-102
lines changed

README.md

Lines changed: 69 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -243,17 +243,17 @@ const are: Are = {
243243

244244
### areString
245245

246-
Use `areString()` or `are.string()` to check if all of **any** arguments are a `string` type.
246+
Use `areString()` or `are.string()` to check if **any** of all the values are a `string`.
247247

248248
```typescript
249-
const areString = (...args: any): boolean => check('string', ...args);
249+
const areString = (...value: any): boolean => check('string', ...value);
250250
```
251251

252-
| Parameter | Type | Description |
253-
| :-------- | :---: | :------------------------------------------------- |
254-
| ...args | `any` | Any arguments to check they're all a `string` type |
252+
| Parameter | Type | Description |
253+
| :-------- | :---: | :------------------ |
254+
| ...value | `any` | Any values to check |
255255

256-
The **return value** is a `boolean` value.
256+
The **return value** is a `boolean` indicating whether or not all the values are an `Array`.
257257

258258
[Example usage on playground][are-string]
259259

@@ -1189,13 +1189,13 @@ const isPrimitive: IsPrimitive = <T extends Primitive>(
11891189
type: Primitives,
11901190
callback: ResultCallback = resultCallback
11911191
): value is T => {
1192-
if (isString(type)) {
1192+
if (isStringType(type)) {
11931193
switch (type) {
11941194
case 'bigint': return isBigInt(value, callback);
1195-
case 'boolean': return isBoolean(value, callback);
1196-
case 'number': return isNumber(value, callback);
1195+
case 'boolean': return isBooleanType(value, callback);
1196+
case 'number': return isNumberType(value, callback);
11971197
case 'null': return isNull(value, callback);
1198-
case 'string': return isString(value, callback);
1198+
case 'string': return isStringType(value, callback);
11991199
case 'symbol': return isSymbol(value, callback);
12001200
case 'undefined': return isUndefined(value, callback);
12011201
}
@@ -1230,7 +1230,7 @@ const isString: IsString = (value: any, callback: ResultCallback = resultCallbac
12301230
| value | `any` | Any `value` to check |
12311231
| callback | [`ResultCallback`][resultcallback] | [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
12321232

1233-
The **return value** is a `boolean` indicating whether or not the `value` is a `string`.
1233+
The **return value** is a `boolean` indicating whether or not the `value` is a `string` type or [`String`][string] object.
12341234

12351235
----
12361236

@@ -1239,7 +1239,7 @@ The **return value** is a `boolean` indicating whether or not the `value` is a `
12391239
Use `isStringObject()` or `is.stringObject()` to check if **any** `value` is an `object` type and instance of [`String`][string] and [`Object`][object].
12401240

12411241
```typescript
1242-
const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is string =>
1242+
const isStringObject: IsStringObject = (value: any, callback: ResultCallback = resultCallback): value is String =>
12431243
callback(value instanceof Object === true && value instanceof String === true && typeof value === 'object', value);
12441244
```
12451245

@@ -1266,7 +1266,7 @@ const isStringType: IsStringType = (value: any, callback: ResultCallback = resul
12661266
| value | `any` | Any `value` to check |
12671267
| callback | [`ResultCallback`][resultcallback]=[`resultCallback`][callback] | [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
12681268

1269-
The **return value** is a `boolean` indicating whether or not the `value` is a `string`.
1269+
The **return value** is a `boolean` indicating whether or not the `value` is a `string` type.
12701270

12711271
----
12721272

@@ -1296,7 +1296,7 @@ Use `isType()` or `is.type()` to check if **any** `value` is the [`Type`](#type)
12961296

12971297
```typescript
12981298
const isType: IsType = <T extends Type>(value: any, type: Types<T>, callback: ResultCallback = resultCallback): value is T => {
1299-
if (isString(type)) {
1299+
if (isStringType(type)) {
13001300
switch (type) {
13011301
// Primitives.
13021302
case 'bigint':
@@ -1573,9 +1573,9 @@ const guardArray: GuardArray = <Type>(value: Array<Type>, callback?: ResultCallb
15731573
isArray<Type>(value, callback);
15741574
```
15751575

1576-
| Parameter | Type | Description |
1577-
|-----------| :---------------------------------: |-------------|
1578-
| value | `Array<Type>` | A generic `Type` `Array` `value` to guard |
1576+
| Parameter | Type | Description |
1577+
|-----------| :--------------------------------: |-------------|
1578+
| value | `Array<Type>` | A generic `Type` `Array` `value` to guard |
15791579
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
15801580

15811581
The **return value** is a `boolean` indicating whether or not the `value` is an [`Array`][array] of a generic `Type`.
@@ -1596,27 +1596,27 @@ const guardBigInt: GuardBigInt = (value: bigint, callback?: ResultCallback): val
15961596
| Parameter | Type | Description |
15971597
| :-------- | :---------------------------------: | :------------------------------- |
15981598
| value | `bigint` | A `bigint` type `value` to guard |
1599-
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
1599+
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
16001600

16011601
The **return value** is a `boolean` indicating whether or not the `value` is a `bigint`.
16021602

16031603
----
16041604

16051605
### guardBoolean
16061606

1607-
Use `guardBoolean()` or `guard.is.boolean()` to guard the `value` to be a `boolean`.
1607+
Use `guardBoolean()` or `guard.is.boolean()` to guard the `value` to be any type of a boolean.
16081608

16091609
```typescript
1610-
const guardBoolean: GuardBoolean = (value: boolean, callback?: ResultCallback): value is boolean =>
1610+
const guardBoolean: GuardBoolean = <B extends AnyBoolean>(value: B, callback?: ResultCallback): value is B =>
16111611
isBoolean(value, callback);
16121612
```
16131613

1614-
| Parameter | Type | Description |
1615-
| :-------- | :---------------------------------: | :-------------------------------- |
1616-
| value | `boolean` | A `boolean` type `value` to guard |
1617-
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
1614+
| Parameter | Type | Description |
1615+
| :-------- | :-------------------------------------: | :--------------------------------------------------- |
1616+
| value | `B` extends [`AnyBoolean`](#anyboolean) | An [`AnyBoolean`](#anyboolean) type `value` to guard |
1617+
| callback? | [`ResultCallback`][resultcallback] | An Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
16181618

1619-
The **return value** is a `boolean` indicating whether or not the `value` is a `boolean`.
1619+
The **return value** is a `boolean` indicating whether or not the `value` is a `boolean` type or [`Boolean`][boolean] object.
16201620

16211621
----
16221622

@@ -1629,9 +1629,9 @@ const guardFunction: GuardFunction = (value: Func, callback?: ResultCallback): v
16291629
isFunction(value, callback);
16301630
```
16311631

1632-
| Parameter | Type | Description |
1633-
| :-------- | :---------------------------------: | :-------------------------------------- |
1634-
| value | [`Func`](#func) | A [`Func`](#func) type `value` to guard |
1632+
| Parameter | Type | Description |
1633+
| :-------- | :--------------------------------: | :-------------------------------------- |
1634+
| value | [`Func`](#func) | A [`Func`](#func) type `value` to guard |
16351635
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
16361636

16371637
The **return value** is a `boolean` indicating whether or not the `value` is a [`Func`](#func).
@@ -1649,10 +1649,10 @@ const guardInstance: GuardInstance = <Obj>(value: Obj, instance: Constructor<Obj
16491649
isInstance<Obj>(value, instance, callback);
16501650
```
16511651

1652-
| Parameter | Type | Description |
1653-
| :-------- | :---------------------------------: | :--------------------------------------------------- |
1654-
| value | `Obj` | An `Obj` type `value` to compare with the `instance` |
1655-
| instance | [`Constructor<Obj>`](#constructor) | A generic `Obj` [`Constructor`](#constructor) type to create an `instance` to compare with the `value` |
1652+
| Parameter | Type | Description |
1653+
| :-------- | :--------------------------------: | :--------------------------------------------------- |
1654+
| value | `Obj` | An `Obj` type `value` to compare with the `instance` |
1655+
| instance | [`Constructor<Obj>`](#constructor) | A generic `Obj` [`Constructor`](#constructor) type to create an `instance` to compare with the `value` |
16561656
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
16571657

16581658
The **return value** is a `boolean` indicating whether or not the `value` is an `instance` of a generic `Obj`.
@@ -1668,8 +1668,8 @@ const guardKey: GuardKey = (value: Key, callback?: ResultCallback): value is Key
16681668
isKey(value, callback);
16691669
```
16701670

1671-
| Parameter | Type | Description |
1672-
| :-------- | :---------------------------------: | :------------------------------------ |
1671+
| Parameter | Type | Description |
1672+
| :-------- | :--------------------------------: | :------------------------------------ |
16731673
| value | [`Key`][key] | A [`Key`][key] type `value` to guard |
16741674
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
16751675

@@ -1686,9 +1686,9 @@ const guardNull: GuardNull = (value: null, callback?: ResultCallback): value is
16861686
isNull(value, callback);
16871687
```
16881688

1689-
| Parameter | Type | Description |
1690-
| :-------- | :---------------------------------: | :----------------------------- |
1691-
| value | `null` | A `null` type `value` to guard |
1689+
| Parameter | Type | Description |
1690+
| :-------- | :--------------------------------: | :----------------------------- |
1691+
| value | `null` | A `null` type `value` to guard |
16921692
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
16931693

16941694
The **return value** is a `boolean` indicating whether or not the `value` is a `null`.
@@ -1697,19 +1697,19 @@ The **return value** is a `boolean` indicating whether or not the `value` is a `
16971697

16981698
### guardNumber
16991699

1700-
Use `guardNumber()` or `guard.is.number()` to guard the `value` to be a `number`.
1700+
Use `guardNumber()` or `guard.is.number()` to guard the `value` to be any type of a number.
17011701

17021702
```typescript
1703-
const guardNumber: GuardNumber = (value: number, callback?: ResultCallback): value is number =>
1703+
const guardNumber: GuardNumber = <N extends AnyNumber>(value: N, callback?: ResultCallback): value is N =>
17041704
isNumber(value, callback);
17051705
```
17061706

1707-
| Parameter | Type | Description |
1708-
|---------- | :---------------------------------: | :-------------------------------- |
1709-
| value | `number` | A `number` type `value` to guard. |
1710-
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
1707+
| Parameter | Type | Description |
1708+
|---------- | :-----------------------------------: | :----------------------------------- |
1709+
| value | `N` extends [`AnyNumber`](#anynumber) | An `AnyNumber` type `value` to guard |
1710+
| callback? | [`ResultCallback`][resultcallback] | An Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
17111711

1712-
The **return value** is a `boolean` indicating whether or not the `value` is a `number`.
1712+
The **return value** is a `boolean` indicating whether or not the `value` is a `number` type or [`Number`][number] object.
17131713

17141714
[Example usage on playground][guard-number]
17151715

@@ -1777,19 +1777,19 @@ The **return value** is a `boolean` indicating whether or not the `value` is the
17771777

17781778
### guardString
17791779

1780-
Use `guardString()` or `guard.is.string()` to guard the `value` to be a `string`.
1780+
Use `guardString()` or `guard.is.string()` to guard the `value` to be any type of a string.
17811781

17821782
```typescript
1783-
const guardString: GuardString = (value: string, callback?: ResultCallback): value is string =>
1783+
const guardString: GuardString = <S extends AnyString>(value: S, callback?: ResultCallback): value is S =>
17841784
isString(value, callback);
17851785
```
17861786

1787-
| Parameter | Type | Description |
1788-
|-------------| :---------------------------------: | :------------------------------- |
1789-
| value | `string` | A `string` type `value` to guard |
1790-
| callback? | [`ResultCallback`][resultcallback] | Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
1787+
| Parameter | Type | Description |
1788+
|-------------| :-----------------------------------: | :----------------------------------- |
1789+
| value | `S` extends [`AnyString`](#anystring) | An `AnyString` type `value` to guard |
1790+
| callback? | [`ResultCallback`][resultcallback] | An Optional [`ResultCallback`][resultcallback] function to handle result before returns eg. to throw an `Error` |
17911791

1792-
The **return value** is a `boolean` indicating whether or not the `value` is a `string`.
1792+
The **return value** is a `boolean` indicating whether or not the `value` is a `string` type or [`String`][string] object.
17931793

17941794
[Example usage on playground][guard-string]
17951795

@@ -2097,6 +2097,24 @@ resultTRUE === {
20972097

20982098
## Common types
20992099

2100+
### AnyBoolean
2101+
2102+
```typescript
2103+
type AnyBoolean = Exclude<boolean | Boolean, true | false>;
2104+
```
2105+
2106+
### AnyNumber
2107+
2108+
```typescript
2109+
type AnyNumber = number | Number;
2110+
```
2111+
2112+
### AnyString
2113+
2114+
```typescript
2115+
type AnyString = string | String;
2116+
```
2117+
21002118
### Constructor
21012119

21022120
```typescript

0 commit comments

Comments
 (0)