Skip to content

Commit 4433dfc

Browse files
committed
Update documentation
1 parent de018f8 commit 4433dfc

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,34 @@ See the [test page](https://wizard04wsu.github.io/javascript-type-testing/test/t
1313
This module uses an expanded set of type names and related descriptors to simplify common tests of values.
1414
Basic types do not distinguish between primitives and objects, but descriptors _primitive_ or _object_
1515
can be used to determine that aspect.
16-
For example, `5` and `new Number(5)` are both _number_, but `5` is _primitive_ and `new Number(5)` is _object_.
16+
For example, `5` and `new Number(5)` are both type _number_, but `5` has descriptor _primitive_ and `new Number(5)` has descriptor _object_.
1717

18-
The **is()** function returns an **IsType** object describing its argument.
18+
The **is()** function returns an object that describes its argument.
1919

2020
Syntax:
2121
> **is**(_value_)
2222
2323

24-
## IsType Object
24+
## Return Value
2525

2626
| Member | Description
2727
| - | -
2828
| .type | The type of _value_ (using this module's type names).
29-
| .of(_class_) | Tests if _value_ was an instance of _class_.
29+
| .of(_class_) | Tests if _value_ is an instance of _class_.
3030
| .all(_...descriptors)_ | Takes a list of descriptor names as arguments. Returns `true` if **all** of them applied to _value_.
3131
| .any(_...descriptors_) | Takes a list of descriptor names as arguments. Returns `true` if **any** of them applied to _value_.
32-
| \[[_descriptor_](#type-names-and-related-descriptors)\] | Descriptors are listed in the table below. Each descriptor property is a boolean that is `true` if it applied to _value_.
32+
| \[_descriptor_\] | Each [descriptor](#descriptors-and-type-names) property is a boolean that is `true` if it applied to _value_.
3333

34-
Enumerable properties of the **is** function are string values of the name of each descriptor. These can be used
34+
Enumerable properties of `is` are string constants of all the descriptor names. These can be used
3535
in the `.all()` and `.any()` methods instead of string literals.
36-
For example, <code>is(<i>value</i>).all("number", "object")</code> is equivalent to <code>is(<i>value</i>).all(is.number, is.object)</code>.
36+
For example, these are equivalent:
3737

38+
> <code>is(<i>value</i>).all("number", "object")</code>
3839
39-
## Type Names and Related Descriptors
40+
> <code>is(<i>value</i>).all(is.number, is.object)</code>
41+
42+
43+
## Descriptors and Type Names
4044

4145
| Descriptor | Type Name | Primitive Values | Instances Of Classes
4246
| - | - | - | -
@@ -51,7 +55,7 @@ For example, <code>is(<i>value</i>).all("number", "object")</code> is equivalent
5155
| false | | `false` |
5256
| true | | `true` |
5357
| falsy | | undefined, `null`, `false`, `0n`, `NaN`, `0`, `""` |
54-
| truthy | | not _falsy_ | `Object`
58+
| truthy | | not a _falsy_ value | `Object`
5559
| **symbol** | yes | a `Symbol` |
5660
| **bigint** | yes | `0n`, `5n` |
5761
| numberish | | `0`, `5`, `Infinity`, `NaN` | `Number`
@@ -65,14 +69,14 @@ For example, <code>is(<i>value</i>).all("number", "object")</code> is equivalent
6569
| **set** | yes | | `Set`
6670
| **weakmap** | yes | | `WeakMap`
6771
| **weakset** | yes | | `WeakSet`
68-
| empty | | `""`, `[]` | `String` or `Array` of length == 0, `Map` or `Set` of size == 0
69-
| nonempty | | not _empty_ | `String`, `Array`, `Map`, or `Set` that is not _empty_
72+
| empty | | `""`, `[]` | `String` or `Array` with `.length === 0`,<br>`Map` or `Set` with `.size === 0`
73+
| nonempty | | `"foo"`, `[1,2]` | `String` or `Array` with `.length > 0`,<br>`Map` or `Set` with `.size > 0`
7074
| **date** | yes | | `Date`
7175
| **error** | yes | | `Error`
7276
| **function** | yes | | `Function`
7377
| **promise** | yes | | `Promise`
7478
| **regex** | yes | | `Regex`
7579

76-
## Note
80+
## Math Note
7781

7882
Note that JavaScript doesn't always treat mathematical expressions of undefined or indeterminate form as you might expect. For example, `1/0` is an undefined form, but JavaScript evaluates it as `Infinity`.

isType.mjs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ function is(value){
145145
}
146146

147147
for(const propName in new TypeTest()){
148+
// For each descriptor name:
149+
150+
// Add an enumerable property to the `is` function.
148151
Object.defineProperty(is, propName, {
149152
value: propName,
150153
enumerable: true,

0 commit comments

Comments
 (0)