0.2.26 • Published 21 days ago

@andrewcaires/utils.js v0.2.26

Weekly downloads
-
License
MIT
Repository
github
Last release
21 days ago

npm downloads size license

utils.js

JavaScript utility library for web and nodejs development

Installation

npm i @andrewcaires/utils.js

Api

EventEmitter

Class for custom events

import { EventEmitter } from '@andrewcaires/utils.js';

const emitter = new EventEmitter();

// OR

class CustomEvent extends EventEmitter {}

const custom = new CustomEvent();
  • EventEmitter.on Adds the listener function to the end of the listeners array for the event named
const cb = (data) => {

  console.log(data);
}

emitter.on('event', cb);
  • EventEmitter.once Adds the listener function to the end of the listeners array for the event named. The next time event is triggered, this listener is removed
const cb = (data) => {

  console.log(data);
}

emitter.once('event', cb);
  • EventEmitter.off Removes the specified listener from the listener array for the event named
emitter.off('event', cb);
  • EventEmitter.emit Synchronously calls each of the listeners registered for the event named
emitter.emit('event', 'on emit event');

type

Determine the internal JavaScript [Class] of an object

import { isArray, isBoolean, isFunction, isNumber, isObject, isString, isFloat, isInteger, isNull, isUndefined, isValid, type } from '@andrewcaires/utils.js';
  • isArray Finds whether a variable is an array
isArray([]) // > true
  • isBoolean Finds out whether a variable is a boolean
isBoolean(true) // > true
isBoolean(false) // > true
  • isDef Find out if a variable has been defined
isDef(any) // > true
  • isFunction Find whether the type of a variable is function
isFunction(function() {}) // > true
  • isNumber Finds whether a variable is an number
isNumber(1) // > true
isNumber(1.7) // > true
  • isObject Finds whether a variable is an object
isObject({}) // > true
  • isString Find whether the type of a variable is string
isString('') // > true
  • isFloat Finds whether the type of a variable is float
isFloat(1.7) // > true
  • isInteger Find whether the type of a variable is integer
isInteger(1) // > true
  • isNull Finds whether a variable is null
isNull(null) // > true
  • isUndefined Finds whether a variable is undefined
isUndefined(undefined) // > true
  • type Get the type of a variable
type([]); // => 'array'

type(true); // => 'boolean'
type(false); // => 'boolean'

type(function() {}); // => 'function'

type(1); // => 'number'
type(1.7); // => 'number'

type({}); // => 'object'

type(''); // => 'string'
type('test'); // => 'string'

type(); // => 'null'
type(null); // => 'null'

Links

License

0.2.26

21 days ago

0.2.25

21 days ago

0.2.24

22 days ago

0.2.23

4 months ago

0.2.22

6 months ago

0.2.21

8 months ago

0.2.20

11 months ago

0.2.19

11 months ago

0.2.18

11 months ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.2

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago