@hrimsoft/utils

1.0.0 • Public • Published

@hrimsoft/utils

GitHub npm npm

This is a centralized object store that works in the browser and nodejs.

installing

npm install @hrimsoft/utils --save or yarn add @hrimsoft/utils

usage

Checking arguments on null, white space or empty arrays

import _ from '@hrimsoft/utils';
// or
// const _ = require('@hrimsoft/utils').default

_.isNull('  '); // true
_.isNotNull('  '); // false; it's more readable than if(!_.isNull('   '))...

_.isNull([]); // true

Checking callback functions before calling them

import _ from '@hrimsoft/utils';
// or
// const _ = require('@hrimsoft/utils').default

function my_func(callback){
    if(_.isFunction(callback))
      callback.call();
}

// if you have an object and you need to check it member on being a function dynamically
const obj = {
    prop: {
        method: (x) => x + 1;
    }
}
_.isFunction('prop.method', obj)); // true

Casting to numbers

import _ from '@hrimsoft/utils';
// or
// const _ = require('@hrimsoft/utils').default

_.toNumber('.5'); // 0.5
_.toNumber('12'); // 12
_.toNumber(true); // 1
_.toNumber(['1',false, '-12.3']); // [1,0,-12.3]

Casting to boolean

import _ from '@hrimsoft/utils';
// or
// const _ = require('@hrimsoft/utils').default

_.toBool(5);     // true
_.toBool(0);     // false
_.toBool('');    // false
_.toBool('  ');  // false

// argument could be in any case
_.toBool('TrUe');  // true
_.toBool('FalSe);  // false

_.toBool(null);    // false
_.toBool({});      // true
_.toBool([]);      // false
_.toBool([1,'false', ' ', { prop: 10 }]); // [true, false, false, true]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.01latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.01

Package Sidebar

Install

npm i @hrimsoft/utils

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

29.9 kB

Total Files

15

Last publish

Collaborators

  • basim-hrimsoft