Merge branch 'master' into master

This commit is contained in:
Lukas Tetzlaff 2018-05-03 20:52:35 +02:00 committed by GitHub
commit 44948c222b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 3 deletions

View file

@ -43,17 +43,23 @@
"verify", "verify",
"compare" "compare"
], ],
"dependencies": {
"symbol-observable": "^1.2.0"
},
"devDependencies": { "devDependencies": {
"@types/jsdom": "^11.0.4", "@types/jsdom": "^11.0.4",
"@types/node": "^9.6.0", "@types/node": "^9.6.0",
"@types/tempy": "^0.1.0", "@types/tempy": "^0.1.0",
"@types/zen-observable": "^0.5.3",
"ava": "*", "ava": "*",
"del-cli": "^1.1.0", "del-cli": "^1.1.0",
"jsdom": "^11.6.2", "jsdom": "^11.6.2",
"rxjs": "^6.0.0",
"tempy": "^0.2.1", "tempy": "^0.2.1",
"tslint": "^5.9.1", "tslint": "^5.9.1",
"tslint-xo": "^0.7.0", "tslint-xo": "^0.7.0",
"typescript": "^2.8.1" "typescript": "^2.8.1",
"zen-observable": "^0.8.8"
}, },
"types": "dist/index.d.ts" "types": "dist/index.d.ts"
} }

View file

@ -261,6 +261,16 @@ is.nodeStream(fs.createReadStream('unicorn.png'));
//=> true //=> true
``` ```
##### .observable(value)
Returns `true` if `value` is an `Observable`.
```js
const {Observable} = require('rxjs');
is.observable(new Observable());
//=> true
```
##### .infinite(value) ##### .infinite(value)
Check if `value` is `Infinity` or `-Infinity`. Check if `value` is `Infinity` or `-Infinity`.
@ -281,7 +291,6 @@ Returns `true` if `value` is falsy or an empty string, array, object, map, or se
Returns `true` if `is.empty(value)` or a string that is all whitespace. Returns `true` if `is.empty(value)` or a string that is all whitespace.
##### .any(predicate, ...values) ##### .any(predicate, ...values)
Returns `true` if **any** of the input `values` returns true in the `predicate`: Returns `true` if **any** of the input `values` returns true in the `predicate`:
@ -306,6 +315,7 @@ is.all(is.string, '🦄', [], 'unicorns');
//=> false //=> false
``` ```
## FAQ ## FAQ
### Why yet another type checking module? ### Why yet another type checking module?

View file

@ -1,4 +1,5 @@
import * as util from 'util'; import * as util from 'util';
import symbolObservable from 'symbol-observable';
type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array; type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
type Primitive = null | undefined | string | number | boolean | Symbol; type Primitive = null | undefined | string | number | boolean | Symbol;
@ -24,6 +25,7 @@ export const enum TypeName {
Function = 'Function', Function = 'Function',
GeneratorFunction = 'GeneratorFunction', GeneratorFunction = 'GeneratorFunction',
AsyncFunction = 'AsyncFunction', AsyncFunction = 'AsyncFunction',
Observable = 'Observable',
Array = 'Array', Array = 'Array',
Buffer = 'Buffer', Buffer = 'Buffer',
Object = 'Object', Object = 'Object',
@ -90,6 +92,10 @@ function is(value: any): TypeName { // tslint:disable-line:only-arrow-functions
return TypeName.Function; return TypeName.Function;
} }
if (is.observable(value)) {
return TypeName.Observable;
}
if (Array.isArray(value)) { if (Array.isArray(value)) {
return TypeName.Array; return TypeName.Array;
} }
@ -246,7 +252,8 @@ namespace is { // tslint:disable-line:no-namespace
export const domElement = (value: any): value is DomElement => object(value) as any && value.nodeType === NODE_TYPE_ELEMENT && string(value.nodeName) && export const domElement = (value: any): value is DomElement => object(value) as any && value.nodeType === NODE_TYPE_ELEMENT && string(value.nodeName) &&
!plainObject(value) && DOM_PROPERTIES_TO_CHECK.every(property => property in value); !plainObject(value) && DOM_PROPERTIES_TO_CHECK.every(property => property in value);
export const nodeStream = (value: any): value is NodeStream => !nullOrUndefined(value) && isObject(value) as any && function_(value.pipe); export const observable = (value: any) => Boolean(value && value[symbolObservable] && value === value[symbolObservable]());
export const nodeStream = (value: any): value is NodeStream => !nullOrUndefined(value) && isObject(value) as any && function_(value.pipe) && !observable(value);
export const infinite = (value: any) => value === Infinity || value === -Infinity; export const infinite = (value: any) => value === Infinity || value === -Infinity;

View file

@ -5,6 +5,8 @@ import * as util from 'util';
import * as tempy from 'tempy'; import * as tempy from 'tempy';
import test, {TestContext, Context} from 'ava'; import test, {TestContext, Context} from 'ava';
import {JSDOM} from 'jsdom'; import {JSDOM} from 'jsdom';
import {Subject, Observable} from 'rxjs';
import ZenObservable from 'zen-observable';
import m from '..'; import m from '..';
const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8; const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8;
@ -321,6 +323,14 @@ const types = new Map<string, Test>([
new Stream.Writable() new Stream.Writable()
] ]
}], }],
['observable', {
is: m.observable,
fixtures: [
new Observable(),
new Subject(),
new ZenObservable(() => {}) // tslint:disable-line:no-empty
]
}],
['infinite', { ['infinite', {
is: m.infinite, is: m.infinite,
fixtures: [ fixtures: [

View file

@ -5,6 +5,7 @@
"module": "commonjs", "module": "commonjs",
"moduleResolution": "node", "moduleResolution": "node",
"declaration": true, "declaration": true,
"skipLibCheck": true,
"pretty": true, "pretty": true,
"newLine": "lf", "newLine": "lf",
"lib": [ "lib": [