Timo Hocker 01d90058ab update-scanner: automatic update
@sapphirecode/eslint-config: 2.1.7 ==> 2.1.8 minor
nyc: 15.0.1 ==> 15.1.0 minor
2020-06-02 08:33:21 +02:00
fix
2020-05-15 12:20:10 +02:00
2020-03-14 14:12:44 +01:00
2020-05-15 13:16:46 +02:00
2020-06-02 08:33:21 +02:00

@sapphirecode/utilities

version: 1.3.x

small utility functions to make much needed features easier to work with

Installation

npm:

npm i --save @sapphirecode/utilities

yarn:

yarn add @sapphirecode/utilities

Usage

const util = require('@sapphirecode/utilities');

// cut off decimal places to a specified point
util.truncate_decimal(12.345678, 2);
// returns 12.34

// will return null instead of throwing on invalid json
util.try_parse_json('{{foo');

// copy an object to prevent modification of the original
const obj = {foo:'bar'};
const copy = util.copy_object(obj);
copy.foo = 'baz';
console.log(obj.foo); // bar

// run a regular expression and get a callback for every result
const data = "foobarfoo";
const regex = /foo/g;
util.run_regex(regex, data, res => {
  console.log(res[0]); // will output 'foo' 2 times
});

// check if a variable is null, undefined or NaN
console.log(util.is_nil(parseInt('abc'))); // true
console.log(util.is_nil('foo')); // false
console.log(util.is_nil(42)); // false
console.log(util.is_nil(null)); // true
console.log(util.is_nil(undefined)); // true

License

MIT © Timo Hocker timo@scode.ovh

Description
No description provided
Readme 357 KiB
Languages
JavaScript 100%