Updated the files.

This commit is contained in:
Batuhan Berk Başoğlu 2024-02-08 19:38:41 -05:00
parent 1553e6b971
commit 753967d4f5
23418 changed files with 3784666 additions and 0 deletions

3
my-app/node_modules/is-what/.babelrc generated vendored Executable file
View file

@ -0,0 +1,3 @@
{
"presets": ["env"]
}

9
my-app/node_modules/is-what/.eslintignore generated vendored Executable file
View file

@ -0,0 +1,9 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
test
.eslintrc.js

18
my-app/node_modules/is-what/.eslintrc.js generated vendored Executable file
View file

@ -0,0 +1,18 @@
// npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-tree-shaking
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'tree-shaking'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'tree-shaking/no-side-effects-in-initialization': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off'
},
}

12
my-app/node_modules/is-what/.github/FUNDING.yml generated vendored Executable file
View file

@ -0,0 +1,12 @@
# These are supported funding model platforms
github: mesqueeb
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

9
my-app/node_modules/is-what/.prettierrc generated vendored Executable file
View file

@ -0,0 +1,9 @@
{
"printWidth": 100,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "es5",
"semi": false,
"bracketSpacing": true,
"quoteProps": "consistent"
}

9
my-app/node_modules/is-what/.vscode/settings.json generated vendored Executable file
View file

@ -0,0 +1,9 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2, // make sure this is the same as .prettierrc
"editor.insertSpaces": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}

21
my-app/node_modules/is-what/LICENSE generated vendored Executable file
View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Luca Ban - Mesqueeb
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

191
my-app/node_modules/is-what/README.md generated vendored Executable file
View file

@ -0,0 +1,191 @@
# is What? 🙉
Very simple & small JS type check functions. It's fully TypeScript supported!
```
npm i is-what
```
Or for deno available at: `"deno.land/x/is_what"`
## Motivation
I built is-what because the existing solutions were all too complex or too poorly built.
I was looking for:
- A simple way to check any kind of type (including non-primitives)
- Be able to check if an object is a plain object `{}` or a special object (like a class instance) ‼️
- Let TypeScript automatically know what type a value is when checking
And that's exactly what `is-what` is! (what a great wordplay 😃)
## Usage
is-what is really easy to use, and most functions work just like you'd expect.
```js
// import functions you want to use like so:
import { isString, isDate, isPlainObject } from 'is-what'
```
1. First I'll go over the simple functions available. Only `isNumber` and `isDate` have special treatment.
2. After that I'll talk about working with Objects (plain objects vs class instances etc.).
3. Lastly I'll talk about TypeScript implementation
### Simple type check functions
```js
// strings
isString('') // true
isEmptyString('') // true
isFullString('') // false
// numbers
isNumber(0) // true
isNumber(NaN) // false
// dates
isDate(new Date()) // true
isDate(new Date('invalid date')) // false
// others
isBoolean(false) // true
isFunction(function () {}) // true
isArray([]) // true
isUndefined(undefined) // true
isNull(null) // true
isRegExp(/\s/gi) // true
isSymbol(Symbol()) // true
isBlob(new Blob()) // true
isFile(new File([''], '', { type: 'text/html' })) // true
// primitives
isPrimitive('') // true
// true for any of: boolean, null, undefined, number, string, symbol
```
### Getting and checking for specific types
You can check for specific types with `getType` and `isType`:
```js
import { getType, isType } from 'is-what'
getType('') // returns 'String'
// pass a Type as second param:
isType('', String) // returns true
```
### isPlainObject vs isAnyObject
Checking for a JavaScript object can be really difficult. In JavaScript you can create classes that will behave just like JavaScript objects but might have completely different prototypes. With is-what I went for this classification:
- `isPlainObject` will only return `true` on plain JavaScript objects and not on classes or others
- `isAnyObject` will be more loose and return `true` on regular objects, classes, etc.
```js
// define a plain object
const plainObject = {hello: 'I am a good old object.'}
// define a special object
class SpecialObject {
constructor (somethingSpecial) {
this.speciality = somethingSpecial
}
}
const specialObject = new SpecialObject('I am a special object! I am a class instance!!!')
// check the plain object
isPlainObject(plainObject) // returns true
isAnyObject(plainObject) // returns true
getType(plainObject) // returns 'Object'
// check the special object
isPlainObject(specialObject) // returns false !!!!!!!!!
isAnyObject(specialObject) // returns true
getType(specialObject) // returns 'Object'
```
> Please note that `isPlainObject` will only return `true` for normal plain JavaScript objects.
## TypeScript
is-what makes TypeScript know the type during if statements. This means that a check returns the type of the payload for TypeScript users.
```ts
function isNumber (payload: any): payload is number {
// return boolean
}
// As you can see above, all functions return a boolean for JavaScript, but pass the payload type to TypeScript.
// usage example:
function fn (payload: string | number): number {
if (isNumber(payload)) {
// ↑ TypeScript already knows payload is a number here!
return payload
}
return 0
}
```
`isPlainObject` and `isAnyObject` with TypeScript will declare the payload to be an object type with any props:
```ts
function isPlainObject (payload: any): payload is {[key: string]: any}
function isAnyObject (payload: any): payload is {[key: string]: any}
// The reason to return `{[key: string]: any}` is to be able to do
if (isPlainObject(payload) && payload.id) return payload.id
// if isPlainObject() would return `payload is object` then it would give an error at `payload.id`
```
### isObjectLike
If you want more control over which kind of objects are allowed you can use `isObjectLike<T>`:
```ts
import { isObjectLike } from 'is-what'
// usage examples:
isObjectLike<{specificKey: string}>(payload)
isObjectLike<object>(payload)
// you can pass a specific type for TS to check on.
```
`isObjectLike<T>` works like this under the hood:
```ts
function isObjectLike<T extends object> (payload: any): payload is T {
return isAnyObject(payload)
}
```
## Meet the family
- [is-what 🙉](https://github.com/mesqueeb/is-what)
- [merge-anything 🥡](https://github.com/mesqueeb/merge-anything)
- [filter-anything ⚔️](https://github.com/mesqueeb/filter-anything)
- [find-and-replace-anything 🎣](https://github.com/mesqueeb/find-and-replace-anything)
- [compare-anything 🛰](https://github.com/mesqueeb/compare-anything)
- [copy-anything 🎭](https://github.com/mesqueeb/copy-anything)
- [flatten-anything 🏏](https://github.com/mesqueeb/flatten-anything)
## Source code
It's litterally just these functions:
```js
function getType (payload) {
return Object.prototype.toString.call(payload).slice(8, -1)
}
function isUndefined (payload) {
return getType(payload) === 'Undefined'
}
function isString (payload) {
return getType(payload) === 'String'
}
function isAnyObject (payload) {
return getType(payload) === 'Object'
}
// etc...
```
See the full source code [here](https://github.com/mesqueeb/is-what/blob/master/src/index.ts).

60
my-app/node_modules/is-what/build.js generated vendored Executable file
View file

@ -0,0 +1,60 @@
/* eslint-disable */
// npm install rollup-plugin-typescript2 typescript --save-dev
import typescript from 'rollup-plugin-typescript2'
// import { terser } from 'rollup-plugin-terser'
// import resolve from 'rollup-plugin-node-resolve'
// ------------------------------------------------------------------------------------------
// formats
// ------------------------------------------------------------------------------------------
// amd Asynchronous Module Definition, used with module loaders like RequireJS
// cjs CommonJS, suitable for Node and Browserify/Webpack
// esm Keep the bundle as an ES module file
// iife A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
// umd Universal Module Definition, works as amd, cjs and iife all in one
// system Native format of the SystemJS loader
// ------------------------------------------------------------------------------------------
// setup
// ------------------------------------------------------------------------------------------
const pkg = require('./package.json')
const name = pkg.name
const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
const external = Object.keys(pkg.dependencies || [])
const plugins = [
typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
]
// ------------------------------------------------------------------------------------------
// Builds
// ------------------------------------------------------------------------------------------
function defaults (config) {
// defaults
const defaults = {
plugins,
external,
}
// defaults.output
config.output = config.output.map(output => {
return Object.assign(
{
sourcemap: false,
name: className,
exports: 'named',
},
output
)
})
return Object.assign(defaults, config)
}
export default [
defaults({
input: 'src/index.ts',
output: [
{ file: 'dist/index.cjs.js', format: 'cjs' },
{ file: 'dist/index.esm.js', format: 'esm' },
],
}),
]

364
my-app/node_modules/is-what/dist/index.cjs.js generated vendored Executable file
View file

@ -0,0 +1,364 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* Returns the object type of the given payload
*
* @param {*} payload
* @returns {string}
*/
function getType(payload) {
return Object.prototype.toString.call(payload).slice(8, -1);
}
/**
* Returns whether the payload is undefined
*
* @param {*} payload
* @returns {payload is undefined}
*/
function isUndefined(payload) {
return getType(payload) === 'Undefined';
}
/**
* Returns whether the payload is null
*
* @param {*} payload
* @returns {payload is null}
*/
function isNull(payload) {
return getType(payload) === 'Null';
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isPlainObject(payload) {
if (getType(payload) !== 'Object')
return false;
return payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype;
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isObject(payload) {
return isPlainObject(payload);
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is { [K in any]: never }}
*/
function isEmptyObject(payload) {
return isPlainObject(payload) && Object.keys(payload).length === 0;
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isFullObject(payload) {
return isPlainObject(payload) && Object.keys(payload).length > 0;
}
/**
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isAnyObject(payload) {
return getType(payload) === 'Object';
}
/**
* Returns whether the payload is an object like a type passed in < >
*
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
*
* @template T this must be passed in < >
* @param {*} payload
* @returns {payload is T}
*/
function isObjectLike(payload) {
return isAnyObject(payload);
}
/**
* Returns whether the payload is a function (regular or async)
*
* @param {*} payload
* @returns {payload is AnyFunction}
*/
function isFunction(payload) {
return typeof payload === 'function';
}
/**
* Returns whether the payload is an array
*
* @param {any} payload
* @returns {payload is any[]}
*/
function isArray(payload) {
return getType(payload) === 'Array';
}
/**
* Returns whether the payload is a an array with at least 1 item
*
* @param {*} payload
* @returns {payload is any[]}
*/
function isFullArray(payload) {
return isArray(payload) && payload.length > 0;
}
/**
* Returns whether the payload is a an empty array
*
* @param {*} payload
* @returns {payload is []}
*/
function isEmptyArray(payload) {
return isArray(payload) && payload.length === 0;
}
/**
* Returns whether the payload is a string
*
* @param {*} payload
* @returns {payload is string}
*/
function isString(payload) {
return getType(payload) === 'String';
}
/**
* Returns whether the payload is a string, BUT returns false for ''
*
* @param {*} payload
* @returns {payload is string}
*/
function isFullString(payload) {
return isString(payload) && payload !== '';
}
/**
* Returns whether the payload is ''
*
* @param {*} payload
* @returns {payload is string}
*/
function isEmptyString(payload) {
return payload === '';
}
/**
* Returns whether the payload is a number (but not NaN)
*
* This will return `false` for `NaN`!!
*
* @param {*} payload
* @returns {payload is number}
*/
function isNumber(payload) {
return getType(payload) === 'Number' && !isNaN(payload);
}
/**
* Returns whether the payload is a boolean
*
* @param {*} payload
* @returns {payload is boolean}
*/
function isBoolean(payload) {
return getType(payload) === 'Boolean';
}
/**
* Returns whether the payload is a regular expression (RegExp)
*
* @param {*} payload
* @returns {payload is RegExp}
*/
function isRegExp(payload) {
return getType(payload) === 'RegExp';
}
/**
* Returns whether the payload is a Map
*
* @param {*} payload
* @returns {payload is Map<any, any>}
*/
function isMap(payload) {
return getType(payload) === 'Map';
}
/**
* Returns whether the payload is a WeakMap
*
* @param {*} payload
* @returns {payload is WeakMap<any, any>}
*/
function isWeakMap(payload) {
return getType(payload) === 'WeakMap';
}
/**
* Returns whether the payload is a Set
*
* @param {*} payload
* @returns {payload is Set<any>}
*/
function isSet(payload) {
return getType(payload) === 'Set';
}
/**
* Returns whether the payload is a WeakSet
*
* @param {*} payload
* @returns {payload is WeakSet<any>}
*/
function isWeakSet(payload) {
return getType(payload) === 'WeakSet';
}
/**
* Returns whether the payload is a Symbol
*
* @param {*} payload
* @returns {payload is symbol}
*/
function isSymbol(payload) {
return getType(payload) === 'Symbol';
}
/**
* Returns whether the payload is a Date, and that the date is valid
*
* @param {*} payload
* @returns {payload is Date}
*/
function isDate(payload) {
return getType(payload) === 'Date' && !isNaN(payload);
}
/**
* Returns whether the payload is a Blob
*
* @param {*} payload
* @returns {payload is Blob}
*/
function isBlob(payload) {
return getType(payload) === 'Blob';
}
/**
* Returns whether the payload is a File
*
* @param {*} payload
* @returns {payload is File}
*/
function isFile(payload) {
return getType(payload) === 'File';
}
/**
* Returns whether the payload is a Promise
*
* @param {*} payload
* @returns {payload is Promise<any>}
*/
function isPromise(payload) {
return getType(payload) === 'Promise';
}
/**
* Returns whether the payload is an Error
*
* @param {*} payload
* @returns {payload is Error}
*/
function isError(payload) {
return getType(payload) === 'Error';
}
/**
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
*
* @param {*} payload
* @returns {payload is typeof NaN}
*/
function isNaNValue(payload) {
return getType(payload) === 'Number' && isNaN(payload);
}
/**
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
*
* @param {*} payload
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
*/
function isPrimitive(payload) {
return (isBoolean(payload) ||
isNull(payload) ||
isUndefined(payload) ||
isNumber(payload) ||
isString(payload) ||
isSymbol(payload));
}
/**
* Returns true whether the payload is null or undefined
*
* @param {*} payload
* @returns {(payload is null | undefined)}
*/
var isNullOrUndefined = isOneOf(isNull, isUndefined);
function isOneOf(a, b, c, d, e) {
return function (value) {
return a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
};
}
/**
* Does a generic check to check that the given payload is of a given type.
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
* It will, however, differentiate between object and null
*
* @template T
* @param {*} payload
* @param {T} type
* @throws {TypeError} Will throw type error if type is an invalid type
* @returns {payload is T}
*/
function isType(payload, type) {
if (!(type instanceof Function)) {
throw new TypeError('Type must be a function');
}
if (!Object.prototype.hasOwnProperty.call(type, 'prototype')) {
throw new TypeError('Type is not a class');
}
// Classes usually have names (as functions usually have names)
var name = type.name;
return getType(payload) === name || Boolean(payload && payload.constructor === type);
}
exports.getType = getType;
exports.isAnyObject = isAnyObject;
exports.isArray = isArray;
exports.isBlob = isBlob;
exports.isBoolean = isBoolean;
exports.isDate = isDate;
exports.isEmptyArray = isEmptyArray;
exports.isEmptyObject = isEmptyObject;
exports.isEmptyString = isEmptyString;
exports.isError = isError;
exports.isFile = isFile;
exports.isFullArray = isFullArray;
exports.isFullObject = isFullObject;
exports.isFullString = isFullString;
exports.isFunction = isFunction;
exports.isMap = isMap;
exports.isNaNValue = isNaNValue;
exports.isNull = isNull;
exports.isNullOrUndefined = isNullOrUndefined;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.isObjectLike = isObjectLike;
exports.isOneOf = isOneOf;
exports.isPlainObject = isPlainObject;
exports.isPrimitive = isPrimitive;
exports.isPromise = isPromise;
exports.isRegExp = isRegExp;
exports.isSet = isSet;
exports.isString = isString;
exports.isSymbol = isSymbol;
exports.isType = isType;
exports.isUndefined = isUndefined;
exports.isWeakMap = isWeakMap;
exports.isWeakSet = isWeakSet;

327
my-app/node_modules/is-what/dist/index.esm.js generated vendored Executable file
View file

@ -0,0 +1,327 @@
/**
* Returns the object type of the given payload
*
* @param {*} payload
* @returns {string}
*/
function getType(payload) {
return Object.prototype.toString.call(payload).slice(8, -1);
}
/**
* Returns whether the payload is undefined
*
* @param {*} payload
* @returns {payload is undefined}
*/
function isUndefined(payload) {
return getType(payload) === 'Undefined';
}
/**
* Returns whether the payload is null
*
* @param {*} payload
* @returns {payload is null}
*/
function isNull(payload) {
return getType(payload) === 'Null';
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isPlainObject(payload) {
if (getType(payload) !== 'Object')
return false;
return payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype;
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isObject(payload) {
return isPlainObject(payload);
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is { [K in any]: never }}
*/
function isEmptyObject(payload) {
return isPlainObject(payload) && Object.keys(payload).length === 0;
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isFullObject(payload) {
return isPlainObject(payload) && Object.keys(payload).length > 0;
}
/**
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
function isAnyObject(payload) {
return getType(payload) === 'Object';
}
/**
* Returns whether the payload is an object like a type passed in < >
*
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
*
* @template T this must be passed in < >
* @param {*} payload
* @returns {payload is T}
*/
function isObjectLike(payload) {
return isAnyObject(payload);
}
/**
* Returns whether the payload is a function (regular or async)
*
* @param {*} payload
* @returns {payload is AnyFunction}
*/
function isFunction(payload) {
return typeof payload === 'function';
}
/**
* Returns whether the payload is an array
*
* @param {any} payload
* @returns {payload is any[]}
*/
function isArray(payload) {
return getType(payload) === 'Array';
}
/**
* Returns whether the payload is a an array with at least 1 item
*
* @param {*} payload
* @returns {payload is any[]}
*/
function isFullArray(payload) {
return isArray(payload) && payload.length > 0;
}
/**
* Returns whether the payload is a an empty array
*
* @param {*} payload
* @returns {payload is []}
*/
function isEmptyArray(payload) {
return isArray(payload) && payload.length === 0;
}
/**
* Returns whether the payload is a string
*
* @param {*} payload
* @returns {payload is string}
*/
function isString(payload) {
return getType(payload) === 'String';
}
/**
* Returns whether the payload is a string, BUT returns false for ''
*
* @param {*} payload
* @returns {payload is string}
*/
function isFullString(payload) {
return isString(payload) && payload !== '';
}
/**
* Returns whether the payload is ''
*
* @param {*} payload
* @returns {payload is string}
*/
function isEmptyString(payload) {
return payload === '';
}
/**
* Returns whether the payload is a number (but not NaN)
*
* This will return `false` for `NaN`!!
*
* @param {*} payload
* @returns {payload is number}
*/
function isNumber(payload) {
return getType(payload) === 'Number' && !isNaN(payload);
}
/**
* Returns whether the payload is a boolean
*
* @param {*} payload
* @returns {payload is boolean}
*/
function isBoolean(payload) {
return getType(payload) === 'Boolean';
}
/**
* Returns whether the payload is a regular expression (RegExp)
*
* @param {*} payload
* @returns {payload is RegExp}
*/
function isRegExp(payload) {
return getType(payload) === 'RegExp';
}
/**
* Returns whether the payload is a Map
*
* @param {*} payload
* @returns {payload is Map<any, any>}
*/
function isMap(payload) {
return getType(payload) === 'Map';
}
/**
* Returns whether the payload is a WeakMap
*
* @param {*} payload
* @returns {payload is WeakMap<any, any>}
*/
function isWeakMap(payload) {
return getType(payload) === 'WeakMap';
}
/**
* Returns whether the payload is a Set
*
* @param {*} payload
* @returns {payload is Set<any>}
*/
function isSet(payload) {
return getType(payload) === 'Set';
}
/**
* Returns whether the payload is a WeakSet
*
* @param {*} payload
* @returns {payload is WeakSet<any>}
*/
function isWeakSet(payload) {
return getType(payload) === 'WeakSet';
}
/**
* Returns whether the payload is a Symbol
*
* @param {*} payload
* @returns {payload is symbol}
*/
function isSymbol(payload) {
return getType(payload) === 'Symbol';
}
/**
* Returns whether the payload is a Date, and that the date is valid
*
* @param {*} payload
* @returns {payload is Date}
*/
function isDate(payload) {
return getType(payload) === 'Date' && !isNaN(payload);
}
/**
* Returns whether the payload is a Blob
*
* @param {*} payload
* @returns {payload is Blob}
*/
function isBlob(payload) {
return getType(payload) === 'Blob';
}
/**
* Returns whether the payload is a File
*
* @param {*} payload
* @returns {payload is File}
*/
function isFile(payload) {
return getType(payload) === 'File';
}
/**
* Returns whether the payload is a Promise
*
* @param {*} payload
* @returns {payload is Promise<any>}
*/
function isPromise(payload) {
return getType(payload) === 'Promise';
}
/**
* Returns whether the payload is an Error
*
* @param {*} payload
* @returns {payload is Error}
*/
function isError(payload) {
return getType(payload) === 'Error';
}
/**
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
*
* @param {*} payload
* @returns {payload is typeof NaN}
*/
function isNaNValue(payload) {
return getType(payload) === 'Number' && isNaN(payload);
}
/**
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
*
* @param {*} payload
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
*/
function isPrimitive(payload) {
return (isBoolean(payload) ||
isNull(payload) ||
isUndefined(payload) ||
isNumber(payload) ||
isString(payload) ||
isSymbol(payload));
}
/**
* Returns true whether the payload is null or undefined
*
* @param {*} payload
* @returns {(payload is null | undefined)}
*/
var isNullOrUndefined = isOneOf(isNull, isUndefined);
function isOneOf(a, b, c, d, e) {
return function (value) {
return a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
};
}
/**
* Does a generic check to check that the given payload is of a given type.
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
* It will, however, differentiate between object and null
*
* @template T
* @param {*} payload
* @param {T} type
* @throws {TypeError} Will throw type error if type is an invalid type
* @returns {payload is T}
*/
function isType(payload, type) {
if (!(type instanceof Function)) {
throw new TypeError('Type must be a function');
}
if (!Object.prototype.hasOwnProperty.call(type, 'prototype')) {
throw new TypeError('Type is not a class');
}
// Classes usually have names (as functions usually have names)
var name = type.name;
return getType(payload) === name || Boolean(payload && payload.constructor === type);
}
export { getType, isAnyObject, isArray, isBlob, isBoolean, isDate, isEmptyArray, isEmptyObject, isEmptyString, isError, isFile, isFullArray, isFullObject, isFullString, isFunction, isMap, isNaNValue, isNull, isNullOrUndefined, isNumber, isObject, isObjectLike, isOneOf, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isType, isUndefined, isWeakMap, isWeakSet };

86
my-app/node_modules/is-what/package.json generated vendored Executable file
View file

@ -0,0 +1,86 @@
{
"name": "is-what",
"sideEffects": false,
"version": "3.14.1",
"description": "JS type check (TypeScript supported) functions like `isPlainObject() isArray()` etc. A simple & small integration.",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"typings": "types/index.d.ts",
"scripts": {
"test": "ava",
"jest": "jest",
"jest-w": "jest --watchAll",
"lint": "tsc --noEmit src/index.ts && eslint . --ext .js,.jsx,.ts,.tsx",
"rollup": "rollup -c ./build.js",
"build": "rimraf types && rimraf dist && npm run lint && npm run rollup && npm run test && npm run jest",
"release": "npm run build && np"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mesqueeb/is-what.git"
},
"keywords": [
"javascript",
"typescript",
"typechecker",
"check-type",
"javascript-type",
"primitive-types",
"plain-object",
"plain-objects",
"class-instance",
"class-identifier",
"type-checking",
"type-checker",
"type-check",
"define-type",
"get-type",
"what-type",
"is-object",
"is-plain-obj",
"is-plain-object"
],
"author": "Luca Ban - Mesqueeb",
"license": "MIT",
"bugs": {
"url": "https://github.com/mesqueeb/is-what/issues"
},
"homepage": "https://github.com/mesqueeb/is-what#readme",
"devDependencies": {
"@babel/core": "^7.12.17",
"@types/babel-core": "^6.25.6",
"@types/jest": "^26.0.20",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"ava": "^3.15.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.6.3",
"babel-preset-env": "^1.7.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-tree-shaking": "^1.8.0",
"jest": "^26.6.3",
"np": "^7.4.0",
"prettier": "^2.2.1",
"regenerator-runtime": "^0.13.7",
"rimraf": "^3.0.2",
"rollup": "^2.39.0",
"rollup-plugin-typescript2": "^0.30.0",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.1.5"
},
"ava": {
"extensions": [
"ts"
],
"require": [
"tsconfig-paths/register",
"ts-node/register"
]
},
"np": {
"yarn": false,
"branch": "production"
}
}

395
my-app/node_modules/is-what/src/index.ts generated vendored Executable file
View file

@ -0,0 +1,395 @@
export type AnyFunction = (...args: any[]) => any
export type AnyAsyncFunction = (...args: any[]) => Promise<any>
export type AnyClass = new (...args: any[]) => any
export type PlainObject = Record<string | number | symbol, any>
type TypeGuard<A, B extends A> = (payload: A) => payload is B
/**
* Returns the object type of the given payload
*
* @param {*} payload
* @returns {string}
*/
export function getType(payload: any): string {
return Object.prototype.toString.call(payload).slice(8, -1)
}
/**
* Returns whether the payload is undefined
*
* @param {*} payload
* @returns {payload is undefined}
*/
export function isUndefined(payload: any): payload is undefined {
return getType(payload) === 'Undefined'
}
/**
* Returns whether the payload is null
*
* @param {*} payload
* @returns {payload is null}
*/
export function isNull(payload: any): payload is null {
return getType(payload) === 'Null'
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export function isPlainObject(payload: any): payload is PlainObject {
if (getType(payload) !== 'Object') return false
return payload.constructor === Object && Object.getPrototypeOf(payload) === Object.prototype
}
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export function isObject(payload: any): payload is PlainObject {
return isPlainObject(payload)
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is { [K in any]: never }}
*/
export function isEmptyObject(payload: any): payload is { [K in any]: never } {
return isPlainObject(payload) && Object.keys(payload).length === 0
}
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export function isFullObject(payload: any): payload is PlainObject {
return isPlainObject(payload) && Object.keys(payload).length > 0
}
/**
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export function isAnyObject(payload: any): payload is PlainObject {
return getType(payload) === 'Object'
}
/**
* Returns whether the payload is an object like a type passed in < >
*
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
*
* @template T this must be passed in < >
* @param {*} payload
* @returns {payload is T}
*/
export function isObjectLike<T extends PlainObject>(payload: any): payload is T {
return isAnyObject(payload)
}
/**
* Returns whether the payload is a function (regular or async)
*
* @param {*} payload
* @returns {payload is AnyFunction}
*/
export function isFunction(payload: any): payload is AnyFunction {
return typeof payload === 'function'
}
/**
* Returns whether the payload is an array
*
* @param {any} payload
* @returns {payload is any[]}
*/
export function isArray(payload: any): payload is any[] {
return getType(payload) === 'Array'
}
/**
* Returns whether the payload is a an array with at least 1 item
*
* @param {*} payload
* @returns {payload is any[]}
*/
export function isFullArray(payload: any): payload is any[] {
return isArray(payload) && payload.length > 0
}
/**
* Returns whether the payload is a an empty array
*
* @param {*} payload
* @returns {payload is []}
*/
export function isEmptyArray(payload: any): payload is [] {
return isArray(payload) && payload.length === 0
}
/**
* Returns whether the payload is a string
*
* @param {*} payload
* @returns {payload is string}
*/
export function isString(payload: any): payload is string {
return getType(payload) === 'String'
}
/**
* Returns whether the payload is a string, BUT returns false for ''
*
* @param {*} payload
* @returns {payload is string}
*/
export function isFullString(payload: any): payload is string {
return isString(payload) && payload !== ''
}
/**
* Returns whether the payload is ''
*
* @param {*} payload
* @returns {payload is string}
*/
export function isEmptyString(payload: any): payload is string {
return payload === ''
}
/**
* Returns whether the payload is a number (but not NaN)
*
* This will return `false` for `NaN`!!
*
* @param {*} payload
* @returns {payload is number}
*/
export function isNumber(payload: any): payload is number {
return getType(payload) === 'Number' && !isNaN(payload)
}
/**
* Returns whether the payload is a boolean
*
* @param {*} payload
* @returns {payload is boolean}
*/
export function isBoolean(payload: any): payload is boolean {
return getType(payload) === 'Boolean'
}
/**
* Returns whether the payload is a regular expression (RegExp)
*
* @param {*} payload
* @returns {payload is RegExp}
*/
export function isRegExp(payload: any): payload is RegExp {
return getType(payload) === 'RegExp'
}
/**
* Returns whether the payload is a Map
*
* @param {*} payload
* @returns {payload is Map<any, any>}
*/
export function isMap(payload: any): payload is Map<any, any> {
return getType(payload) === 'Map'
}
/**
* Returns whether the payload is a WeakMap
*
* @param {*} payload
* @returns {payload is WeakMap<any, any>}
*/
export function isWeakMap(payload: any): payload is WeakMap<any, any> {
return getType(payload) === 'WeakMap'
}
/**
* Returns whether the payload is a Set
*
* @param {*} payload
* @returns {payload is Set<any>}
*/
export function isSet(payload: any): payload is Set<any> {
return getType(payload) === 'Set'
}
/**
* Returns whether the payload is a WeakSet
*
* @param {*} payload
* @returns {payload is WeakSet<any>}
*/
export function isWeakSet(payload: any): payload is WeakSet<any> {
return getType(payload) === 'WeakSet'
}
/**
* Returns whether the payload is a Symbol
*
* @param {*} payload
* @returns {payload is symbol}
*/
export function isSymbol(payload: any): payload is symbol {
return getType(payload) === 'Symbol'
}
/**
* Returns whether the payload is a Date, and that the date is valid
*
* @param {*} payload
* @returns {payload is Date}
*/
export function isDate(payload: any): payload is Date {
return getType(payload) === 'Date' && !isNaN(payload)
}
/**
* Returns whether the payload is a Blob
*
* @param {*} payload
* @returns {payload is Blob}
*/
export function isBlob(payload: any): payload is Blob {
return getType(payload) === 'Blob'
}
/**
* Returns whether the payload is a File
*
* @param {*} payload
* @returns {payload is File}
*/
export function isFile(payload: any): payload is File {
return getType(payload) === 'File'
}
/**
* Returns whether the payload is a Promise
*
* @param {*} payload
* @returns {payload is Promise<any>}
*/
export function isPromise(payload: any): payload is Promise<any> {
return getType(payload) === 'Promise'
}
/**
* Returns whether the payload is an Error
*
* @param {*} payload
* @returns {payload is Error}
*/
export function isError(payload: any): payload is Error {
return getType(payload) === 'Error'
}
/**
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
*
* @param {*} payload
* @returns {payload is typeof NaN}
*/
export function isNaNValue(payload: any): payload is typeof NaN {
return getType(payload) === 'Number' && isNaN(payload)
}
/**
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
*
* @param {*} payload
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
*/
export function isPrimitive(
payload: any
): payload is boolean | null | undefined | number | string | symbol {
return (
isBoolean(payload) ||
isNull(payload) ||
isUndefined(payload) ||
isNumber(payload) ||
isString(payload) ||
isSymbol(payload)
)
}
/**
* Returns true whether the payload is null or undefined
*
* @param {*} payload
* @returns {(payload is null | undefined)}
*/
export const isNullOrUndefined = isOneOf(isNull, isUndefined)
export function isOneOf<A, B extends A, C extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>
): TypeGuard<A, B | C>
export function isOneOf<A, B extends A, C extends A, D extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>,
c: TypeGuard<A, D>
): TypeGuard<A, B | C | D>
export function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>,
c: TypeGuard<A, D>,
d: TypeGuard<A, E>
): TypeGuard<A, B | C | D | E>
export function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>,
c: TypeGuard<A, D>,
d: TypeGuard<A, E>,
e: TypeGuard<A, F>
): TypeGuard<A, B | C | D | E | F>
export function isOneOf(
a: AnyFunction,
b: AnyFunction,
c?: AnyFunction,
d?: AnyFunction,
e?: AnyFunction
): (value: unknown) => boolean {
return (value) =>
a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value))
}
/**
* Does a generic check to check that the given payload is of a given type.
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
* It will, however, differentiate between object and null
*
* @template T
* @param {*} payload
* @param {T} type
* @throws {TypeError} Will throw type error if type is an invalid type
* @returns {payload is T}
*/
export function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T {
if (!(type instanceof Function)) {
throw new TypeError('Type must be a function')
}
if (!Object.prototype.hasOwnProperty.call(type, 'prototype')) {
throw new TypeError('Type is not a class')
}
// Classes usually have names (as functions usually have names)
const name: string | undefined | null = (type as any).name
return getType(payload) === name || Boolean(payload && payload.constructor === type)
}

376
my-app/node_modules/is-what/test/ava.ts generated vendored Executable file
View file

@ -0,0 +1,376 @@
import test from 'ava'
import {
isError,
isEmptyArray,
isObject,
isPlainObject,
isAnyObject,
isUndefined,
isNull,
isNullOrUndefined,
isFunction,
isArray,
isString,
isEmptyString,
isFullString,
isBoolean,
isRegExp,
isNumber,
isDate,
isSymbol,
isPrimitive,
isType,
isMap,
isWeakMap,
isSet,
isWeakSet,
isFullArray,
// isBlob,
// isFile,
isPromise,
isNaNValue,
isEmptyObject,
isOneOf,
isFullObject,
} from '../src/index'
// const blob = Buffer.from([])
test('Basic true tests', t => {
t.is(isError(new Error('')), true)
t.is(isUndefined(undefined), true)
t.is(isNull(null), true)
t.is(isNullOrUndefined(null), true)
t.is(isNullOrUndefined(undefined), true)
t.is(isObject({}), true)
t.is(isEmptyObject({}), true)
t.is(isFullObject({0: ''}), true)
t.is(isFullObject({'': ''}), true)
t.is(isObject(new Object()), true)
t.is(isArray([]), true)
t.is(isEmptyArray([]), true)
t.is(isFullArray(['']), true)
t.is(isArray(new Array()), true)
t.is(isString(''), true)
t.is(isString('_'), true)
t.is(isEmptyString(''), true)
t.is(isFullString(' '), true)
t.is(isBoolean(true), true)
t.is(isBoolean(false), true)
t.is(isRegExp(/./), true)
t.is(isRegExp(/./gi), true)
t.is(isNumber(0), true)
t.is(isNumber(1), true)
t.is(isDate(new Date()), true)
t.is(isSymbol(Symbol()), true)
t.is(isMap(new Map()), true)
t.is(isWeakMap(new WeakMap()), true)
t.is(isSet(new Set()), true)
t.is(isWeakSet(new WeakSet()), true)
// t.is(isBlob(blob), true)
// t.is(isFile(new File([''], '', { type: 'text/html' })), true)
t.is(isPromise(new Promise((resolve, reject) => {})), true)
})
test('Basic false tests', t => {
t.is(isError({}), false)
t.is(isNumber(NaN), false)
t.is(isDate(new Date('_')), false)
t.is(isDate(NaN), false)
t.is(isUndefined(NaN), false)
t.is(isNull(NaN), false)
t.is(isObject(NaN), false)
t.is(isArray(NaN), false)
t.is(isString(NaN), false)
t.is(isEmptyString(' '), false)
t.is(isFullString(''), false)
t.is(isBoolean(NaN), false)
t.is(isRegExp(NaN), false)
t.is(isSymbol(NaN), false)
t.is(isMap(new WeakMap()), false)
t.is(isWeakMap(new Map()), false)
t.is(isSet(new WeakSet()), false)
t.is(isWeakSet(new Set()), false)
t.is(isNullOrUndefined(NaN), false)
})
test('isFunction', t => {
t.is(isFunction(NaN), false)
t.is(isFunction(() => {}), true)
t.is(isFunction(function () {}), true)
t.is(isFunction(async () => {}), true)
t.is(isFunction(async function () {}), true)
t.is(isFunction(function * () {}), true)
t.is(isFunction(async function * () {}), true)
const _ = { fn: () => {}, method () {} }
t.is(isFunction(_.fn), true)
t.is(isFunction(_.method), true)
})
test('isEmptyObject', t => {
t.is(isEmptyObject({}), true)
t.is(isEmptyObject(new Object()), true)
t.is(isEmptyObject('{}'), false)
t.is(isEmptyObject('{}'), false)
t.is(isEmptyObject(null), false)
t.is(isEmptyObject(new Date()), false)
t.is(isEmptyObject(new Error('')), false)
t.is(isEmptyObject(new Date()), false)
t.is(isEmptyObject(Symbol()), false)
t.is(isEmptyObject(new Map()), false)
t.is(isEmptyObject(new WeakMap()), false)
t.is(isEmptyObject(new Set()), false)
t.is(isEmptyObject(new WeakSet()), false)
})
test('isEmptyArray', t => {
t.is(isEmptyArray([]), true)
t.is(isEmptyArray(new Array()), true)
t.is(isEmptyArray(new Array(0)), true)
t.is(isEmptyArray(new Array(1)), false)
t.is(isEmptyArray([undefined]), false)
t.is(isEmptyArray(null), false)
t.is(isEmptyArray(new Date()), false)
t.is(isEmptyArray(new Error('')), false)
t.is(isEmptyArray(new Date()), false)
t.is(isEmptyArray(Symbol()), false)
t.is(isEmptyArray(new Map()), false)
t.is(isEmptyArray(new WeakMap()), false)
t.is(isEmptyArray(new Set()), false)
t.is(isEmptyArray(new WeakSet()), false)
})
test('isFullArray', t => {
t.is(isFullArray(new Array(1)), true)
t.is(isFullArray([undefined]), true)
t.is(isFullArray([null]), true)
t.is(isFullArray(['']), true)
t.is(isFullArray([]), false)
t.is(isFullArray(new Array()), false)
t.is(isFullArray(new Array(0)), false)
t.is(isFullArray(null), false)
t.is(isFullArray(new Date()), false)
t.is(isFullArray(new Error('')), false)
t.is(isFullArray(new Date()), false)
t.is(isFullArray(Symbol()), false)
t.is(isFullArray(new Map()), false)
t.is(isFullArray(new WeakMap()), false)
t.is(isFullArray(new Set()), false)
t.is(isFullArray(new WeakSet()), false)
})
test('NaN tests', t => {
t.is(isNaNValue(NaN), true)
t.is(isNaNValue(new Error('')), false)
t.is(isNaNValue(undefined), false)
t.is(isNaNValue(null), false)
t.is(isNaNValue(undefined), false)
t.is(isNaNValue({}), false)
t.is(isNaNValue(new Object()), false)
t.is(
isNaNValue(() => {}),
false
)
t.is(isNaNValue([]), false)
t.is(isNaNValue(new Array()), false)
t.is(isNaNValue(''), false)
t.is(isNaNValue('_'), false)
t.is(isNaNValue(''), false)
t.is(isNaNValue(' '), false)
t.is(isNaNValue(true), false)
t.is(isNaNValue(false), false)
t.is(isNaNValue(/./), false)
t.is(isNaNValue(/./gi), false)
t.is(isNaNValue(0), false)
t.is(isNaNValue(1), false)
t.is(isNaNValue(new Date()), false)
t.is(isNaNValue(Symbol()), false)
t.is(isNaNValue(new Map()), false)
t.is(isNaNValue(new WeakMap()), false)
t.is(isNaNValue(new Set()), false)
t.is(isNaNValue(new WeakSet()), false)
t.is(isNaNValue(new Promise((resolve, reject) => {})), false)
})
test('Primitive tests', t => {
// true
t.is(isPrimitive(0), true)
t.is(isPrimitive(''), true)
t.is(isPrimitive('str'), true)
t.is(isPrimitive(Symbol()), true)
t.is(isPrimitive(true), true)
t.is(isPrimitive(false), true)
t.is(isPrimitive(null), true)
t.is(isPrimitive(undefined), true)
// false
t.is(isPrimitive(NaN), false)
t.is(isPrimitive([]), false)
t.is(isPrimitive(new Array()), false)
t.is(isPrimitive({}), false)
t.is(isPrimitive(new Object()), false)
t.is(isPrimitive(new Date()), false)
t.is(
isPrimitive(() => {}),
false
)
})
test('Date exception', t => {
t.is(isDate(new Date('_')), false)
})
test('Generic isType', t => {
// -----------------------------
// This is correct old fashion syntax for classes, if this is missing
function MyClass () {}
MyClass.prototype.constructor = MyClass
// @ts-ignore
const myClass = new MyClass()
// -----------------------------
class MyOtherClass { constructor() {} }
// this is expected behaviour
t.is(isType('', String), true)
t.is(isType('_', String), true)
t.is(isType('Hello World', String), true)
t.is(isType(NaN, Number), true)
t.is(isType(0, Number), true)
t.is(isType(1, Number), true)
t.is(isType({}, Object), true)
t.is(isType(new Object(), Object), true)
t.is(isType([], Array), true)
t.is(isType(new Array(), Array), true)
t.is(
isType(() => {}, Function),
true
)
t.is(isType(true, Boolean), true)
t.is(isType(false, Boolean), true)
t.is(isType(new Date('_'), Date), true)
t.is(isType(new Date(), Date), true)
t.is(isType(/./, RegExp), true)
t.is(isType(/./gi, RegExp), true)
t.is(isType(myClass, MyClass), true)
t.is(isType(new MyOtherClass(), MyOtherClass), true)
t.is(isType(myClass, MyOtherClass), false)
t.is(isType(Symbol(), Symbol), true)
// t.is(isType(null, Null), true)
// t.is(isType(undefined, Undefined), true)
// It SHOULD fail
t.is(isType(5, String), false)
t.is(isType(null, Object), false)
// Not sure if this would be the expected behaviour but everything is an object
// so I would say so
t.is(isType(myClass, Object), true)
})
test('isObject vs isAnyObject', t => {
// -----------------------------
// This is correct old fashion syntax for classes, if this is missing
function MyClass () {}
MyClass.prototype.constructor = MyClass
// @ts-ignore
const myClass = new MyClass()
// -----------------------------
class MyClass2 { constructor() {} }
const myClass2 = new MyClass2()
const mySpecialObject = {}
Object.setPrototypeOf(mySpecialObject, {
toDate: function () {
return new Date()
},
})
// IS OBJECT
// plain object
t.is(isObject({}), true)
t.is(isObject(new Object()), true)
t.is(isPlainObject({}), true)
t.is(isPlainObject(new Object()), true)
// classes & prototypes
t.is(isObject(myClass), false)
t.is(isObject(myClass2), false)
t.is(isObject(mySpecialObject), false)
t.is(isPlainObject(myClass), false)
t.is(isPlainObject(myClass2), false)
t.is(isPlainObject(mySpecialObject), false)
// arrays and dates
t.is(isObject([]), false)
t.is(isObject(new Array()), false)
t.is(isObject(new Date('_')), false)
t.is(isObject(new Date()), false)
t.is(isPlainObject([]), false)
t.is(isPlainObject(new Array()), false)
t.is(isPlainObject(new Date('_')), false)
t.is(isPlainObject(new Date()), false)
// IS ANY OBJECT
// plain object
t.is(isAnyObject({}), true)
t.is(isAnyObject(new Object()), true)
// classes & prototypes
t.is(isAnyObject(myClass), true)
t.is(isAnyObject(myClass2), true)
t.is(isAnyObject(mySpecialObject), true)
// arrays and dates
t.is(isAnyObject([]), false)
t.is(isAnyObject(new Array()), false)
t.is(isAnyObject(new Date('_')), false)
t.is(isAnyObject(new Date()), false)
})
test('isOneOf', t => {
t.is(isOneOf(isString, isNumber)('_'), true)
t.is(isOneOf(isString, isNumber)(1), true)
t.is(isOneOf(isString, isNumber)(undefined), false)
t.is(isOneOf(isString, isNumber, isBoolean)('_'), true)
t.is(isOneOf(isString, isNumber, isBoolean)(1), true)
t.is(isOneOf(isString, isNumber, isBoolean)(true), true)
t.is(isOneOf(isString, isNumber, isBoolean)(undefined), false)
t.is(isOneOf(isString, isNumber, isBoolean, isArray)('_'), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray)(1), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray)(true), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray)([]), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray)(undefined), false)
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)('_'), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)(1), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)(true), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)([]), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)({}), true)
t.is(isOneOf(isString, isNumber, isBoolean, isArray, isPlainObject)(undefined), false)
})
test('type related tests', t => {
t.pass()
// const fn: string | ((k: number) => string) = (p) => 'a'
// if (!isFunction(fn)) {
// fn
// }
// const a: Record<string, number> = {}
// a[fn(1)] = fn(2)
// const myArray: string | string[] = ['a', 'b']
// if (!isArray(myArray)) {
// myArray
// }
// const a: Record<string, number> = {}
// a[myArray[1]] = myArray[0]
// const myArray: string | any[] = [1, 2, 'a', 'b']
// if (!isArray(myArray)) {
// myArray
// }
// const a: Record<string, number> = {}
// a[myArray[1]] = myArray[0]
})

15
my-app/node_modules/is-what/test/index.test.js generated vendored Executable file
View file

@ -0,0 +1,15 @@
// @ts-check
import {
isBlob,
isFile,
} from '../dist/index.cjs'
test('isBlob', () => {
expect(isBlob(Blob)).toBe(false)
expect(isBlob(new Blob())).toBe(true)
})
test('isFile', () => {
expect(isFile(File)).toBe(false)
expect(isFile(new File([''], '', { type: 'text/html' }))).toBe(true)
})

11
my-app/node_modules/is-what/tsconfig.json generated vendored Executable file
View file

@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"strict": true,
"isolatedModules": true,
"esModuleInterop": true,
"declaration": true,
"declarationDir": "./types/"
},
"include": ["src/**/*", "test/**/*"]
}

253
my-app/node_modules/is-what/types/index.d.ts generated vendored Executable file
View file

@ -0,0 +1,253 @@
export declare type AnyFunction = (...args: any[]) => any;
export declare type AnyAsyncFunction = (...args: any[]) => Promise<any>;
export declare type AnyClass = new (...args: any[]) => any;
export declare type PlainObject = Record<string | number | symbol, any>;
declare type TypeGuard<A, B extends A> = (payload: A) => payload is B;
/**
* Returns the object type of the given payload
*
* @param {*} payload
* @returns {string}
*/
export declare function getType(payload: any): string;
/**
* Returns whether the payload is undefined
*
* @param {*} payload
* @returns {payload is undefined}
*/
export declare function isUndefined(payload: any): payload is undefined;
/**
* Returns whether the payload is null
*
* @param {*} payload
* @returns {payload is null}
*/
export declare function isNull(payload: any): payload is null;
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export declare function isPlainObject(payload: any): payload is PlainObject;
/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export declare function isObject(payload: any): payload is PlainObject;
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is { [K in any]: never }}
*/
export declare function isEmptyObject(payload: any): payload is {
[K in any]: never;
};
/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export declare function isFullObject(payload: any): payload is PlainObject;
/**
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
*
* @param {*} payload
* @returns {payload is PlainObject}
*/
export declare function isAnyObject(payload: any): payload is PlainObject;
/**
* Returns whether the payload is an object like a type passed in < >
*
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
*
* @template T this must be passed in < >
* @param {*} payload
* @returns {payload is T}
*/
export declare function isObjectLike<T extends PlainObject>(payload: any): payload is T;
/**
* Returns whether the payload is a function (regular or async)
*
* @param {*} payload
* @returns {payload is AnyFunction}
*/
export declare function isFunction(payload: any): payload is AnyFunction;
/**
* Returns whether the payload is an array
*
* @param {any} payload
* @returns {payload is any[]}
*/
export declare function isArray(payload: any): payload is any[];
/**
* Returns whether the payload is a an array with at least 1 item
*
* @param {*} payload
* @returns {payload is any[]}
*/
export declare function isFullArray(payload: any): payload is any[];
/**
* Returns whether the payload is a an empty array
*
* @param {*} payload
* @returns {payload is []}
*/
export declare function isEmptyArray(payload: any): payload is [];
/**
* Returns whether the payload is a string
*
* @param {*} payload
* @returns {payload is string}
*/
export declare function isString(payload: any): payload is string;
/**
* Returns whether the payload is a string, BUT returns false for ''
*
* @param {*} payload
* @returns {payload is string}
*/
export declare function isFullString(payload: any): payload is string;
/**
* Returns whether the payload is ''
*
* @param {*} payload
* @returns {payload is string}
*/
export declare function isEmptyString(payload: any): payload is string;
/**
* Returns whether the payload is a number (but not NaN)
*
* This will return `false` for `NaN`!!
*
* @param {*} payload
* @returns {payload is number}
*/
export declare function isNumber(payload: any): payload is number;
/**
* Returns whether the payload is a boolean
*
* @param {*} payload
* @returns {payload is boolean}
*/
export declare function isBoolean(payload: any): payload is boolean;
/**
* Returns whether the payload is a regular expression (RegExp)
*
* @param {*} payload
* @returns {payload is RegExp}
*/
export declare function isRegExp(payload: any): payload is RegExp;
/**
* Returns whether the payload is a Map
*
* @param {*} payload
* @returns {payload is Map<any, any>}
*/
export declare function isMap(payload: any): payload is Map<any, any>;
/**
* Returns whether the payload is a WeakMap
*
* @param {*} payload
* @returns {payload is WeakMap<any, any>}
*/
export declare function isWeakMap(payload: any): payload is WeakMap<any, any>;
/**
* Returns whether the payload is a Set
*
* @param {*} payload
* @returns {payload is Set<any>}
*/
export declare function isSet(payload: any): payload is Set<any>;
/**
* Returns whether the payload is a WeakSet
*
* @param {*} payload
* @returns {payload is WeakSet<any>}
*/
export declare function isWeakSet(payload: any): payload is WeakSet<any>;
/**
* Returns whether the payload is a Symbol
*
* @param {*} payload
* @returns {payload is symbol}
*/
export declare function isSymbol(payload: any): payload is symbol;
/**
* Returns whether the payload is a Date, and that the date is valid
*
* @param {*} payload
* @returns {payload is Date}
*/
export declare function isDate(payload: any): payload is Date;
/**
* Returns whether the payload is a Blob
*
* @param {*} payload
* @returns {payload is Blob}
*/
export declare function isBlob(payload: any): payload is Blob;
/**
* Returns whether the payload is a File
*
* @param {*} payload
* @returns {payload is File}
*/
export declare function isFile(payload: any): payload is File;
/**
* Returns whether the payload is a Promise
*
* @param {*} payload
* @returns {payload is Promise<any>}
*/
export declare function isPromise(payload: any): payload is Promise<any>;
/**
* Returns whether the payload is an Error
*
* @param {*} payload
* @returns {payload is Error}
*/
export declare function isError(payload: any): payload is Error;
/**
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
*
* @param {*} payload
* @returns {payload is typeof NaN}
*/
export declare function isNaNValue(payload: any): payload is typeof NaN;
/**
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
*
* @param {*} payload
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
*/
export declare function isPrimitive(payload: any): payload is boolean | null | undefined | number | string | symbol;
/**
* Returns true whether the payload is null or undefined
*
* @param {*} payload
* @returns {(payload is null | undefined)}
*/
export declare const isNullOrUndefined: TypeGuard<any, null | undefined>;
export declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
export declare function isOneOf<A, B extends A, C extends A, D extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>): TypeGuard<A, B | C | D>;
export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>): TypeGuard<A, B | C | D | E>;
export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>, e: TypeGuard<A, F>): TypeGuard<A, B | C | D | E | F>;
/**
* Does a generic check to check that the given payload is of a given type.
* In cases like Number, it will return true for NaN as NaN is a Number (thanks javascript!);
* It will, however, differentiate between object and null
*
* @template T
* @param {*} payload
* @param {T} type
* @throws {TypeError} Will throw type error if type is an invalid type
* @returns {payload is T}
*/
export declare function isType<T extends AnyFunction | AnyClass>(payload: any, type: T): payload is T;
export {};