Git Product home page Git Product logo

payload-is's Introduction

Project logo

Payload is ?

Status GitHub Issues GitHub Pull Requests License


Javascript Data Check (Typescript)

📝 Table of Contents

🧐 About

简洁的 JS (Javascript)数据校验方法。支持 Typescript。无其他依赖。

🏁 Getting Started

Installing

npm install payload-is

Usage

import { isObject, isPlainObject } from "payload-is";
// array
isArray([]); // true
isEmptyArray([]); // true
isFullArray([1]); // true

// bigint
isBigInt(1n); // true
isBigIntObject(Object(1n)); // true

// boolean
isBoolean(true); // true
isBooleanObject(new Boolean(true)); // true
isTrue(true); // true
isFalse(false); // true

// collection
isSet(new Set()); // true
isMap(new Map()); // true
isWeakSet(new WeakSet()); // true
isWeakMap(new WeakMap()); // true
isWeakRef(new WeakRef()); // true

// date
isDate(new Date()); //true
isValidDate(new Date(2022, 2, 22)); // true
isInvalidDate(new Date("InvalidDate")); // true

// error
isError(new Error("mesage")); //true
isEvalError(new EvalError("mesage"));
isRangeError(new RangeError("mesage"));
isReferenceError(new ReferenceError("mesage"));
isSyntaxError(new SyntaxError("mesage"));
isTypeError(new TypeError("mesage"));
isURIError(new URIError("mesage"));

// EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,
isNativeError(new SyntaxError("message")); // true

// function
isFunction(function () {}); // true;
isAsyncFunction(async function () {}); // true
isAsyncGeneratorFunction(async function* () {}); // true
isGeneratorFunction(function* () {}); // true

// generator
isGenerator((function* () {})()); // true
isAsyncGenerator((async function* () {})()); // true

// iterable
isIterable(new Set()); // true
isIterable(new Map()); // true
isAsyncIterable((async function* () {})()); // true

// nil
isNil(null); // true
isNil(undefined); // true
isNull(null); // true
isUndefined(undefined); // true

// number
isNumber(10); // true
isValidNumber(10); // true
isInvalidNumber(NAN); // true
isNumberObject(new Number(10)); // true

// object
isObject({}); // true
isPlainObject({}); // true
isEmptyObject({}); // true
isFullObject({ key: "abc" }); // true

// primitive
isPrimitive(1); // true
isPrimitive(null); // true
isPrimitive(undefined); // true

// promise
isPromise(new Promise(() => {})); // true
isPromiseLike({ then() {} }); // true

// regexp
isRegExp(/\d+/); // true
isRegExp(new RegExp("abc")); // true

// string
isString(""); // true
isEmptyString(""); // true
isFullString(" "); // true
isStringObject(new String("")); // true

// symbol
isSymbol(Symbol()); // true
isSymbolObject(Object(Symbol("object"))); // true

// buffer
isArrayBuffer(new ArrayBuffer(32)); // true
isSharedArrayBuffer(new SharedArrayBuffer(32)); // true
isArrayBufferLike(new ArrayBuffer(32)); // true
isArrayBufferLike(new SharedArrayBuffer(32)); // true
isDataView(new DataView(new ArrayBuffer(32))); // true

isInt8Array(new Int8Array(32)); // true
isUint8Array(new Uint8Array(32)); // true
isUint8ClampedArray(new Uint8ClampedArray(32)); // true
isInt16Array(new Int16Array(32)); // true
isUint16Array(new Uint16Array(32)); // true
isInt32Array(new Int32Array(32)); // true
isUint32Array(new Uint32Array(32)); // true
isFloat32Array(new Float32Array(32)); // true
isFloat64Array(new Float64Array(32)); // true
isBigInt64Array(new BigInt64Array(32)); // true
isBigUint64Array(new BigUint64Array(32)); // true

// Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array
isTypedArray(new Int8Array(32)); // true

🔧 Running the tests

npm run test

✍️ Authors

payload-is's People

Contributors

yjja avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.