Have ideas to improve npm?Join in the discussion! »

    isnot

    1.0.3 • Public • Published

    isnot

    Beautifully documented type checking package for JavaScript.

    Light. Efficient. Zero dependencies.

    Usage

    Use any of the functions as named exports:

    const {isString, isArray} = require('isnot')
    //or
    import {isObject} from 'isnot'
    

    Functions

    Strings

    String

    Corresponds to the js string primitive

    isString
    isString(""); //true
    isNotString
    isNotString(() => {}); //true

    Empty String

    An empty string is only ''

    isEmptyString

    Purely checks if the string is empty

    isEmptyString({}); //false
     
    isEmptyString(""); //true
     
    isEmptyString(" "); //false
    isEmptyString
    isNotEmptyString(""); //false

    Name

    A name is a string that is just not empty space.

    isName
    isName(""); //false
     
    isName(" "); //false
     
    isName("\r"); //false
     
    isName(123); //false
     
    isName("hey"); //true
    isNotName
    isNotName(""); //true
     
    isNotName(" "); //true
     
    isNotName("\n"); //true
     
    isNotName([]); //true
     
    isNotName({}.toString()); //false

    Email

    isEmail
    isEmail("a@b.c"); //true
    isNotEmail
    isNotEmail("missing@dot"); //true
     
    isNotEmail("missing.domain"); //true

    Variable Name

    isVariableName
    isVariableName("var"); //true (technically not, but it can be a property of an object accessed without ['...'])
     
    isVariableName("oh dear"); //false
     
    isVariableName("0rel"); //false cannot start with number
     
    isVariableName("var0"); //true
    isNotVariableName
    isNotVariableName("a@a"); //true
     
    isNotVariableName("--var--"); //true

    URL

    isURL
    isURL("https://localhost"); //true
     
    isURL("www.site.com"); //true
    isNotURL
    isNotURL("a@a"); //true
     
    isNotURL("site.com"); //false

    ISO String

    Checks only if string it's in a ISO format, not if the date is actually a valid date. Useful to check date properties stored in a database.

    isISOString
    isISOString(new Date().toISOString()); //true
     
    isISOString("2017-06-01T18:43:26.000-02:00"); //true
     
    isISOString("2017-06-01T18:43:26.000Z"); //true
    isNotISOString
    isNotISOString("2017-06-01"); //true
     
    isNotISOString("2017/06/01"); //true
     
    isNotISOString("2017/06/01T18:43:26.000-02:00"); //true
     
    isNotISOString(new Date().toString()); //true

    UUID

    Tests any version of UUID from 1 to 5.

    isUUID
    isUUID(uuidv1()); //true
     
    isUUID(uuidv2()); //true
     
    isUUID(uuidv3()); //true
     
    isUUID(uuidv4()); //true
     
    isUUID(uuidv5()); //true
     
    isUUID("5a2de30a-a736-5aea-8f7f-ad0f019cdc00"); //true
    isNotUUID
    isNotUUID("2017-06-01"); //true

    Arrays

    isArray/isNotArray

    isArray([]); // true
     
    isArray({}); // false
     
    isNotArray(); // true
     
    isNotArray(["hey"]); // false

    isEmptyArray/isNotEmptyArray

    isEmptyArray([]); // true
     
    isEmptyArray({}); // false
     
    isNotEmptyArray([]); // false
     
    isNotEmptyArray([1]); // true
     
    isNotEmptyArray({}); // false

    isArrayOfNames

    isArrayOfNames([]); // false
     
    isArrayOfNames([" ", ""]); // false
     
    isArrayOfNames(["1", "foo"]); // true

    Objects

    Object

    isObject()
    isObject([]); // FALSE, arrays are not objects for this library
     
    isObject({}); // true
    isNotObject()
    isNotObject(""); //true
    isEmptyObject()
    isEmptyObject({}); //true
    isNotEmptyObject()
    isNotEmptyObject({ a: 1 }); //true

    Numbers

    isNumber(1); //true
     
    isNotNumber(NaN); //true
     
    isInt(0); //true
     
    isNotInt(1.2); //true

    Boolean

    isBoolean
    isBoolean(1); //false
    isBoolean(0); //false
    isNotBoolean
    isNotBoolean(NaN); //true
    isNotBoolean(true); //true
    

    Generic

    isEmpty([]); //true
     
    isEmpty(""); //true
     
    isEmpty(" "); //true
     
    isEmpty({}); //true
     
    isEmpty(null); //true
     
    isEmpty(undefined); //true
     
    isEmpty(0); //false
     
    isNotEmpty("hey"); //true

    Dates

    isDate(""); //false
     
    isNotDate(""); //true
     
    isDate(new Date()); //true
     
    isDate("1970-01-01T00:00:00.000Z"); //true
     
    isDate("1970-01-01T00:00:00"); //true
     
    isDate("1970-01-01T00:00"); //true
     
    isDate("1970-01-01"); //true
     
    isDate("0000-00-00"); //false
     
    isDate("1970-13-01"); //false (bad month)
     
    isDate("1970-01-32"); //false (bad day)
     
    isDate("2017-02-29"); //false (not leap year)

    undefined

    isUndefined(""); //false
     
    isUndefined(false); //false
     
    isUndefined(undefined); //true
     
    isUndefined(typeof undefined); //false
     
    isUndefined({}.inventedProp); //true

    Install

    npm i isnot

    DownloadsWeekly Downloads

    2

    Version

    1.0.3

    License

    UNLICENCED

    Unpacked Size

    61.2 kB

    Total Files

    62

    Last publish

    Collaborators

    • avatar