All Projects → gilbarbara → is-lite

gilbarbara / is-lite

Licence: MIT license
Type check tool

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to is-lite

variable-type
👏 ~ 1 kb. Schema validation. 一个只有 1 kb 的用于变量结构校验的库。
Stars: ✭ 24 (+50%)
Mutual labels:  type-check
python-pyfields
Define fields in python classes. Easily.
Stars: ✭ 39 (+143.75%)
Mutual labels:  type-check
youtube-lite
No more wasting time on watching random, irrelevant videos on Youtube. https://youtube-lite.js.org
Stars: ✭ 22 (+37.5%)
Mutual labels:  lite
LiteNetwork
A simple and fast .NET networking library compatible with .NET Standard 2, .NET 5, 6 and 7.
Stars: ✭ 66 (+312.5%)
Mutual labels:  lite
WindowsSimplify
Windows 系統優化精簡 / Windows Simplify Project
Stars: ✭ 234 (+1362.5%)
Mutual labels:  lite
temps-lite
A smart, good-looking little app which tries to speak your language the way you are used to.
Stars: ✭ 40 (+150%)
Mutual labels:  lite
jupyterlite
Wasm powered Jupyter running in the browser 💡
Stars: ✭ 3,039 (+18893.75%)
Mutual labels:  lite
ytmous
Anonymous Youtube Proxy
Stars: ✭ 60 (+275%)
Mutual labels:  lite
Riot
Simple and elegant component-based UI library
Stars: ✭ 14,596 (+91125%)
Mutual labels:  lite
Human Activity Recognition
A new and computationally cheap method to perform human activity recognition using PoseNet and LSTM. Where we use PoseNet for Preprocessing and LSTM for understand the sequence.
Stars: ✭ 25 (+56.25%)
Mutual labels:  lite
TensorFlow Lite SSD RPi 64-bits
TensorFlow Lite SSD on bare Raspberry Pi 4 with 64-bit OS at 24 FPS
Stars: ✭ 25 (+56.25%)
Mutual labels:  lite
QuickNotes
一款简单、轻量、高效的Android记事、记账应用
Stars: ✭ 19 (+18.75%)
Mutual labels:  lite
Pyre Check
Performant type-checking for python.
Stars: ✭ 5,716 (+35625%)
Mutual labels:  type-check

is-lite

NPM version CI is-lite Maintainability Test Coverage

Lightweight type check tool.

Typescript ready with type guards to infer the correct type inside conditionals.

Setup

npm install is-lite

Usage

import is from 'is-lite';

is('value'); // string
is.string('value'); // true

API

is(value)
Returns the type of the value.

Primitives are lowercase: bigint, boolean, null, number, string, symbol, undefined. The rest are camelcase: Array, Function, GeneratorFunction, Object, ...

is.array(value)

is.arrayOf(target: any[], predicate: (value: unknown) => boolean)
Check if all items in an array are of the same type.

is.arrayOf(['a', 'b'], is.string); // true
is.arrayOf([123, 456], is.nnumber); // true

is.arrayOf(['a', 1], is.string); // false

is.asyncFunction(value)
Check if the value is an async function that can be called with await.

is.asyncFunction(async () => {}); // true
is.asyncFunction(() => {}); // false

is.asyncGeneratorFunction(value)

is.bigint(value)

is.boolean(value)

is.date(value)

is.defined(value)
Check if the value is anything but undefined.

is.domElement(value)
Check if the value is a DOM Element.

is.empty(value)
Returns true if:

  • the value is a string, and the length is 0
  • the value is an Object and Object.keys(value).length is 0
  • the value is an Array, and the length is 0
  • the value is a Map, and the size is 0
  • the value is a Set, and the size is 0

is.error(value)

is.function(value)

is.generator(value)
Check for an object that has its own .next() and .throw() methods and has a function definition for Symbol.iterator

is.generatorFunction(value)

is.instanceOf(value, class)
Check if the value is a direct instance of the class.

class APIError extends Error {}

const error = new APIError('Fail');

is.instanceOf(error, APIError); // true
is.instanceOf(error, Error); // false

is.iterable(value)

is.map(value)

is.nan(value)

is.null(value)

is.nullOrUndefined(value)

is.number(value)
Note: is.number(NaN) returns false

is.numericString(value)
Check for a string that represents a number.

is.numericString('42'); // true
is.numericString('-5'); // true
is.numericString('Inifinity'); // true
is.numericString('NaN'); // true

is.plainFunction(value)
Check if the value is a function (it doesn't include async and generator functions)

is.primitive(value)

is.object(value)
Remember that functions and arrays are objects too.

is.oneOf(target: any[], value: any)
Check if the value exists in the target

const colors = ['red', 'green', 'blue'];

is.oneOf(colors, 'green'); // true
is.oneOf(colors, 'brown'); // false

is.plainObject(value)
Check if the object is created by either {}, new Object() or Object.create(null).

is.promise(value)

is.propertyOf(target: object, key: string, predicate?: (value: unknown) => boolean)
Check if the key exists in the target. If you pass a predicate function, it will check the value's type.

const map = { items: [1], isLogged: false, retries: 0 };

is.propertyOf(map, 'retries'); // true
is.propertyOf(map, 'auth'); // false

is.propertyOf(map, 'retries', is.number); // true
is.propertyOf(map, 'items', is.array); // true
is.propertyOf(map, 'isLogged', is.string); // false

is.regexp(value)

is.set(value)

is.string(value)

is.symbol(value)

is.undefined(value)

is.weakMap(value)

is.weakSet(value)

Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.

Show your support

Give a ⭐️ if this project helped you!

License

Copyright © 2019 Gil Barbara [email protected].
This project is MIT licensed.

FAQ

@sindresorhus/is is fantastic, but I needed something even smaller (and simpler). This package covers the basics and is just 1k minified+gzipped.

If you need to support legacy browsers, the Number.isNaN polyfill is required.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].