@sindresorhus/is
Advanced tools
Comparing version 0.5.0 to 0.6.0
/// <reference types="node" /> | ||
declare function is(value: any): string; | ||
export declare const enum TypeName { | ||
null = "null", | ||
boolean = "boolean", | ||
undefined = "undefined", | ||
string = "string", | ||
number = "number", | ||
symbol = "symbol", | ||
Function = "Function", | ||
Array = "Array", | ||
Buffer = "Buffer", | ||
Object = "Object", | ||
RegExp = "RegExp", | ||
Date = "Date", | ||
Error = "Error", | ||
Map = "Map", | ||
Set = "Set", | ||
WeakMap = "WeakMap", | ||
WeakSet = "WeakSet", | ||
Int8Array = "Int8Array", | ||
Uint8Array = "Uint8Array", | ||
Uint8ClampedArray = "Uint8ClampedArray", | ||
Int16Array = "Int16Array", | ||
Uint16Array = "Uint16Array", | ||
Int32Array = "Int32Array", | ||
Uint32Array = "Uint32Array", | ||
Float32Array = "Float32Array", | ||
Float64Array = "Float64Array", | ||
ArrayBuffer = "ArrayBuffer", | ||
SharedArrayBuffer = "SharedArrayBuffer", | ||
Promise = "Promise", | ||
} | ||
declare function is(value: any): TypeName; | ||
declare namespace is { | ||
@@ -22,2 +53,3 @@ const undefined: (value: any) => boolean; | ||
const asyncFunction: (value: any) => boolean; | ||
const boundFunction: (value: any) => boolean; | ||
const regExp: (value: any) => boolean; | ||
@@ -52,2 +84,3 @@ const date: (value: any) => boolean; | ||
const domElement: (value: any) => boolean; | ||
const nodeStream: (value: any) => boolean; | ||
const infinite: (value: any) => boolean; | ||
@@ -54,0 +87,0 @@ const even: (rem: number) => boolean; |
@@ -5,33 +5,41 @@ "use strict"; | ||
const toString = Object.prototype.toString; | ||
const getObjectType = (value) => toString.call(value).slice(8, -1); | ||
const isOfType = (type) => (value) => typeof value === type; // tslint:disable-line:strict-type-predicates | ||
const isObjectOfType = (type) => (value) => getObjectType(value) === type; | ||
const getObjectType = (value) => { | ||
const objectName = toString.call(value).slice(8, -1); | ||
if (objectName) { | ||
return objectName; | ||
} | ||
return null; | ||
}; | ||
const isObjectOfType = (typeName) => (value) => { | ||
return getObjectType(value) === typeName; | ||
}; | ||
function is(value) { | ||
if (value === null) { | ||
return 'null'; | ||
return "null" /* null */; | ||
} | ||
if (value === true || value === false) { | ||
return 'boolean'; | ||
return "boolean" /* boolean */; | ||
} | ||
const type = typeof value; | ||
if (type === 'undefined') { | ||
return 'undefined'; | ||
return "undefined" /* undefined */; | ||
} | ||
if (type === 'string') { | ||
return 'string'; | ||
return "string" /* string */; | ||
} | ||
if (type === 'number') { | ||
return 'number'; | ||
return "number" /* number */; | ||
} | ||
if (type === 'symbol') { | ||
return 'symbol'; | ||
return "symbol" /* symbol */; | ||
} | ||
if (is.function_(value)) { | ||
return 'Function'; | ||
return "Function" /* Function */; | ||
} | ||
if (Array.isArray(value)) { | ||
return 'Array'; | ||
return "Array" /* Array */; | ||
} | ||
if (Buffer.isBuffer(value)) { | ||
return 'Buffer'; | ||
return "Buffer" /* Buffer */; | ||
} | ||
@@ -45,3 +53,3 @@ const tagType = getObjectType(value); | ||
} | ||
return 'Object'; | ||
return "Object" /* Object */; | ||
} | ||
@@ -66,3 +74,3 @@ (function (is) { | ||
is.generator = (value) => is.iterable(value) && is.function_(value.next) && is.function_(value.throw); | ||
is.nativePromise = isObjectOfType('Promise'); | ||
is.nativePromise = isObjectOfType("Promise" /* Promise */); | ||
const hasPromiseAPI = (value) => !is.null_(value) && | ||
@@ -77,20 +85,21 @@ isObject(value) && | ||
is.asyncFunction = isFunctionOfType('AsyncFunction'); | ||
is.regExp = isObjectOfType('RegExp'); | ||
is.date = isObjectOfType('Date'); | ||
is.error = isObjectOfType('Error'); | ||
is.map = isObjectOfType('Map'); | ||
is.set = isObjectOfType('Set'); | ||
is.weakMap = isObjectOfType('WeakMap'); | ||
is.weakSet = isObjectOfType('WeakSet'); | ||
is.int8Array = isObjectOfType('Int8Array'); | ||
is.uint8Array = isObjectOfType('Uint8Array'); | ||
is.uint8ClampedArray = isObjectOfType('Uint8ClampedArray'); | ||
is.int16Array = isObjectOfType('Int16Array'); | ||
is.uint16Array = isObjectOfType('Uint16Array'); | ||
is.int32Array = isObjectOfType('Int32Array'); | ||
is.uint32Array = isObjectOfType('Uint32Array'); | ||
is.float32Array = isObjectOfType('Float32Array'); | ||
is.float64Array = isObjectOfType('Float64Array'); | ||
is.arrayBuffer = isObjectOfType('ArrayBuffer'); | ||
is.sharedArrayBuffer = isObjectOfType('SharedArrayBuffer'); | ||
is.boundFunction = (value) => is.function_(value) && !value.hasOwnProperty('prototype'); | ||
is.regExp = isObjectOfType("RegExp" /* RegExp */); | ||
is.date = isObjectOfType("Date" /* Date */); | ||
is.error = isObjectOfType("Error" /* Error */); | ||
is.map = isObjectOfType("Map" /* Map */); | ||
is.set = isObjectOfType("Set" /* Set */); | ||
is.weakMap = isObjectOfType("WeakMap" /* WeakMap */); | ||
is.weakSet = isObjectOfType("WeakSet" /* WeakSet */); | ||
is.int8Array = isObjectOfType("Int8Array" /* Int8Array */); | ||
is.uint8Array = isObjectOfType("Uint8Array" /* Uint8Array */); | ||
is.uint8ClampedArray = isObjectOfType("Uint8ClampedArray" /* Uint8ClampedArray */); | ||
is.int16Array = isObjectOfType("Int16Array" /* Int16Array */); | ||
is.uint16Array = isObjectOfType("Uint16Array" /* Uint16Array */); | ||
is.int32Array = isObjectOfType("Int32Array" /* Int32Array */); | ||
is.uint32Array = isObjectOfType("Uint32Array" /* Uint32Array */); | ||
is.float32Array = isObjectOfType("Float32Array" /* Float32Array */); | ||
is.float64Array = isObjectOfType("Float64Array" /* Float64Array */); | ||
is.arrayBuffer = isObjectOfType("ArrayBuffer" /* ArrayBuffer */); | ||
is.sharedArrayBuffer = isObjectOfType("SharedArrayBuffer" /* SharedArrayBuffer */); | ||
is.truthy = (value) => Boolean(value); | ||
@@ -112,3 +121,3 @@ is.falsy = (value) => !value; | ||
let prototype; | ||
return getObjectType(value) === 'Object' && | ||
return getObjectType(value) === "Object" /* Object */ && | ||
(prototype = Object.getPrototypeOf(value), prototype === null || // tslint:disable-line:ban-comma-operator | ||
@@ -118,13 +127,19 @@ prototype === Object.getPrototypeOf({})); | ||
const typedArrayTypes = new Set([ | ||
'Int8Array', | ||
'Uint8Array', | ||
'Uint8ClampedArray', | ||
'Int16Array', | ||
'Uint16Array', | ||
'Int32Array', | ||
'Uint32Array', | ||
'Float32Array', | ||
'Float64Array' | ||
"Int8Array" /* Int8Array */, | ||
"Uint8Array" /* Uint8Array */, | ||
"Uint8ClampedArray" /* Uint8ClampedArray */, | ||
"Int16Array" /* Int16Array */, | ||
"Uint16Array" /* Uint16Array */, | ||
"Int32Array" /* Int32Array */, | ||
"Uint32Array" /* Uint32Array */, | ||
"Float32Array" /* Float32Array */, | ||
"Float64Array" /* Float64Array */ | ||
]); | ||
is.typedArray = (value) => typedArrayTypes.has(getObjectType(value)); | ||
is.typedArray = (value) => { | ||
const objectType = getObjectType(value); | ||
if (objectType === null) { | ||
return false; | ||
} | ||
return typedArrayTypes.has(objectType); | ||
}; | ||
const isValidLength = (value) => is.safeInteger(value) && value > -1; | ||
@@ -152,2 +167,3 @@ is.arrayLike = (value) => !is.nullOrUndefined(value) && !is.function_(value) && isValidLength(value.length); | ||
!is.plainObject(value) && DOM_PROPERTIES_TO_CHECK.every(property => property in value); | ||
is.nodeStream = (value) => !is.nullOrUndefined(value) && isObject(value) && is.function_(value.pipe); | ||
is.infinite = (value) => value === Infinity || value === -Infinity; | ||
@@ -154,0 +170,0 @@ const isAbsoluteMod2 = (value) => (rem) => is.integer(rem) && Math.abs(rem % 2) === value; |
118
package.json
{ | ||
"name": "@sindresorhus/is", | ||
"version": "0.5.0", | ||
"description": "Type check values: `is.string('🦄') //=> true`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/is", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "dist/index.js", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"lint": "tslint --format stylish --project .", | ||
"build": "tsc", | ||
"test": "npm run lint && npm run build && ava dist/tests", | ||
"prepublish": "npm run build && del dist/tests" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"type", | ||
"types", | ||
"is", | ||
"check", | ||
"checking", | ||
"validate", | ||
"validation", | ||
"utility", | ||
"util", | ||
"typeof", | ||
"instanceof", | ||
"object", | ||
"assert", | ||
"assertion", | ||
"test", | ||
"kind", | ||
"primitive", | ||
"verify", | ||
"compare" | ||
], | ||
"devDependencies": { | ||
"@types/jsdom": "^2.0.31", | ||
"@types/node": "^8.0.47", | ||
"ava": "*", | ||
"del-cli": "^1.1.0", | ||
"jsdom": "^9.12.0", | ||
"tslint": "^5.8.0", | ||
"tslint-xo": "^0.3.0", | ||
"typescript": "^2.6.1" | ||
}, | ||
"types": "dist/index.d.ts" | ||
"name": "@sindresorhus/is", | ||
"version": "0.6.0", | ||
"description": "Type check values: `is.string('🦄') //=> true`", | ||
"license": "MIT", | ||
"repository": "sindresorhus/is", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "dist/index.js", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"lint": "tslint --format stylish --project .", | ||
"build": "tsc", | ||
"test": "npm run lint && npm run build && ava dist/tests", | ||
"prepublish": "npm run build && del dist/tests" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"keywords": [ | ||
"type", | ||
"types", | ||
"is", | ||
"check", | ||
"checking", | ||
"validate", | ||
"validation", | ||
"utility", | ||
"util", | ||
"typeof", | ||
"instanceof", | ||
"object", | ||
"assert", | ||
"assertion", | ||
"test", | ||
"kind", | ||
"primitive", | ||
"verify", | ||
"compare" | ||
], | ||
"devDependencies": { | ||
"@types/jsdom": "^2.0.31", | ||
"@types/node": "^8.0.47", | ||
"@types/tempy": "^0.1.0", | ||
"ava": "*", | ||
"del-cli": "^1.1.0", | ||
"jsdom": "^9.12.0", | ||
"tempy": "^0.2.1", | ||
"tslint": "^5.8.0", | ||
"tslint-xo": "^0.3.0", | ||
"typescript": "^2.6.1" | ||
}, | ||
"types": "dist/index.d.ts" | ||
} |
@@ -99,2 +99,17 @@ # is [![Build Status](https://travis-ci.org/sindresorhus/is.svg?branch=master)](https://travis-ci.org/sindresorhus/is) | ||
##### .boundFunction(value) | ||
Returns `true` for any `bound` function. | ||
```js | ||
is.boundFunction(() => {}); | ||
// => true | ||
is.boundFunction(function () {}.bind(null)); | ||
// => true | ||
is.boundFunction(function () {}); | ||
// => false | ||
``` | ||
##### .map(value) | ||
@@ -200,2 +215,12 @@ ##### .set(value) | ||
##### .nodeStream(value) | ||
Returns `true` if `value` is a Node.js [stream](https://nodejs.org/api/stream.html). | ||
```js | ||
const fs = require('fs'); | ||
is.nodeStream(fs.createReadStream('unicorn.png')); | ||
//=> true | ||
``` | ||
##### .infinite(value) | ||
@@ -274,2 +299,3 @@ | ||
- [is-blob](https://github.com/sindresorhus/is-blob) - Check if a value is a Blob - File-like object of immutable, raw data | ||
- [has-emoji](https://github.com/sindresorhus/has-emoji) - Check whether a string has any emoji | ||
@@ -276,0 +302,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
87952
1166
310
0
10