Add is.nodeStream() (#34)
This commit is contained in:
parent
ae3adc9818
commit
a04a04c131
4 changed files with 38 additions and 1 deletions
|
|
@ -238,6 +238,8 @@ namespace is { // tslint:disable-line:no-namespace
|
|||
export const domElement = (value: any) => object(value) && value.nodeType === NODE_TYPE_ELEMENT && string(value.nodeName) &&
|
||||
!plainObject(value) && DOM_PROPERTIES_TO_CHECK.every(property => property in value);
|
||||
|
||||
export const nodeStream = (value: any) => !nullOrUndefined(value) && isObject(value) && function_(value.pipe);
|
||||
|
||||
export const infinite = (value: any) => value === Infinity || value === -Infinity;
|
||||
|
||||
const isAbsoluteMod2 = (value: number) => (rem: number) => integer(rem) && Math.abs(rem % 2) === value;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
import * as fs from 'fs';
|
||||
import * as net from 'net';
|
||||
import * as Stream from 'stream';
|
||||
import * as util from 'util';
|
||||
import * as tempy from 'tempy';
|
||||
import test, {TestContext, Context} from 'ava';
|
||||
import {jsdom} from 'jsdom';
|
||||
import m from '..';
|
||||
|
|
@ -286,7 +290,8 @@ const types = new Map<string, Test>([
|
|||
'canvas',
|
||||
'script'
|
||||
].map(createDomElement) }
|
||||
], ['non-domElements', {
|
||||
],
|
||||
['non-domElements', {
|
||||
is: value => !m.domElement(value),
|
||||
fixtures: [
|
||||
document.createTextNode('data'),
|
||||
|
|
@ -297,6 +302,20 @@ const types = new Map<string, Test>([
|
|||
document.createDocumentFragment()
|
||||
]
|
||||
}],
|
||||
['nodeStream', {
|
||||
is: m.nodeStream,
|
||||
fixtures: [
|
||||
fs.createReadStream('readme.md'),
|
||||
fs.createWriteStream(tempy.file()),
|
||||
new net.Socket(),
|
||||
new Stream.Duplex(),
|
||||
new Stream.PassThrough(),
|
||||
new Stream.Readable(),
|
||||
new Stream.Transform(),
|
||||
new Stream.Stream(),
|
||||
new Stream.Writable()
|
||||
]
|
||||
}],
|
||||
['infinite', {
|
||||
is: m.infinite,
|
||||
fixtures: [
|
||||
|
|
@ -641,6 +660,10 @@ test('is.domElement', t => {
|
|||
t.false(m.domElement({nodeType: 1, nodeName: 'div'}));
|
||||
});
|
||||
|
||||
test('is.nodeStream', t => {
|
||||
testType(t, 'nodeStream');
|
||||
});
|
||||
|
||||
test('is.infinite', t => {
|
||||
testType(t, 'infinite', ['number']);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue