GithubHelp home page GithubHelp logo

stevenpersia / tinyboo Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 761 KB

Utilities library for type checking and other useful things. Already more than 40 functions (TypeScript supported). πŸ‘»

Home Page: https://www.npmjs.com/package/tinyboo

License: MIT License

JavaScript 73.12% TypeScript 26.88%
utils type check functions library tinyboo utilities typescript

tinyboo's Introduction

tinyboo

Overview

Utilities library for type checking and other useful things. Already more than 40 functions. Each function returns false or true, that's it. Perfect for front and back ends. πŸ‘»

  • 0 dependencies 🌱
  • Super lightweight (~25 kB) ⚑
  • Easy to use 🀘
  • Tested πŸ› 
  • TypeScript supported 🌞

Roadmap : isUrl, isAbsoluteUrl, isRelativeUrl, isGif, isJpg, isPng, isPdf, isSvg, isWebp, isHtml, isZip, isRar, isMatch, ...

Installation

Install package :

yarn add tinyboo
# or
npm install tinyboo

Import what you need :

import { isEmptyArray, isIP, isGreaterThan } from 'tinyboo';

And have fun !

Usage

Type checkers

isArray([]); // β†’ true
isBlob(new Blob()); // β†’ true
isBoolean(false); // β†’ true
isDate(new Date()); // β†’ true
isError(new Error()); // β†’ true
isFile(new File()); // β†’ true
isFunction(() => {}); // β†’ true
isMap(new Map()); // β†’ true
isNull(null); // β†’ true
isNumber(1); // β†’ true
isObject({}); // β†’ true
isRegExp(/^foo(bar)?$/); // β†’ true
isSet(new Set()); // β†’ true
isString('foo'); // β†’ true
isSymbol(Symbol()); // β†’ true
isUndefined(undefined); // β†’ true
isWeakMap(new WeakMap()); // β†’ true
isWeakSet(new WeakSet()); // β†’ true
isPrimitive('foo'); // β†’ true

Arrays

isArrayOfBooleans([true, false]); // β†’ true
isArrayOfDates([new Date(), new Date()]); // β†’ true
isArrayOfNumbers([1, 2, 3]); // β†’ true
isArrayOfObjects([{}, {}]); // β†’ true
isArrayOfPrimitives(['foo', 1]); // β†’ true
isArrayOfStrings(['bar', '1']); // β†’ true

Objects

hasKey({ foo: 'bar' }, 'foo'); // β†’ true
hasValue({ foo: 'bar' }, 'bar'); // β†’ true

Numbers

isFiniteNumber(2); // β†’ true
isGreaterThan(700, 500); // β†’ true
isInteger(21); // β†’ true
isLessThan(300, 500); // β†’ true
isBetween(2, 1, 3); // β†’ true

Others

isEmptyArray([]); // β†’ true
isEmptyObject({}); // β†’ true
isEmptyString(' '); // β†’ true
isEqual('foo', 'foo'); // β†’ true
isHexadecimal('F1F1F1'); // β†’ true
isIP('210.23.51.230'); // β†’ true
isJSON('{ "foo": "bar" }'); // β†’ true

More examples

isEqual - works with array, boolean, null, number and string

// Array
isEqual([1, 'foo', 'bar'], [1, 'foo', 'bar']); // β†’ true
isEqual([1, 'foo', 'bar'], ['foo', 1, 'bar']); // β†’ false

// Boolean
isEqual(false, false); // β†’ true
isEqual(true, false); // β†’ false

// Null
isEqual(null, null); // β†’ true
isEqual(null, 'foo'); // β†’ false

// Number
isEqual(1, 1); // β†’ true
isEqual(1, '1'); // β†’ false

// String
isEqual('foo', 'foo'); // β†’ true
isEqual('foo', 'bar'); // β†’ false

isIP - only works with string

isIP('127.0.0.0'); // β†’ true
isIP('0.0.0.0'); // β†’ true
isIP('255.255.255.255'); // β†’ true

isIP('192.168'); // β†’ false
isIP(19216801); // β†’ false
isIP('127.000.000.000'); // β†’ false

isJSON - only works with string or null

isJSON('{}'); // β†’ true
isJSON('null'); // β†’ true
isJSON('{ "foo": "bar" }'); // β†’ true
isJSON(null); // β†’ true

isJSON({}); // β†’ false
isJSON({ foo: 'bar' }); // β†’ false
isJSON(''); // β†’ false

Star, Fork, Clone & Contribute

Feel free to contribute on this repository. If my work helps you, please give me back with a star. This means a lot to me and keeps me going!

tinyboo's People

Contributors

stevenpersia avatar dependabot[bot] avatar

Stargazers

Tarun Chauhan avatar Lucas Tidas avatar  avatar  avatar Malo avatar ΠΎΠ³Ρ€ΠΎΠΌΠ½Ρ‹ΠΉ avatar William N. avatar  avatar Redobana Tovonandroy avatar

Watchers

James Cloos avatar

Forkers

lambdaeasy

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.