Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

core-functions

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

core-functions - npm Package Compare versions

Comparing version 3.0.19 to 3.0.20

2

package.json
{
"name": "core-functions",
"version": "3.0.19",
"version": "3.0.20",
"description": "Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including strings, booleans, Promises, base 64, Arrays, Objects, standard AppErrors, etc.",

@@ -5,0 +5,0 @@ "author": "Byron du Preez",

@@ -1,2 +0,2 @@

# core-functions v3.0.19
# core-functions v3.0.20

@@ -26,3 +26,3 @@ Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including

This module is exported as a [Node.js](https://nodejs.org/) module.
This module is exported as a [Node.js](https://nodejs.org) module.

@@ -42,2 +42,16 @@ ## Installation

const any = require('core-functions/any');
// Arbitrary usage
assert(any.defined(undefined) === false);
assert(any.defined(null) === false);
assert(any.defined(0) === true);
assert(any.defined('') === true);
assert(any.notDefined(undefined) === true);
assert(any.notDefined(null) === true);
assert(any.notDefined(0) === false);
assert(any.notDefined('') === false);
assert(any.valueOf(null) === null);
assert(any.valueOf(Number(123)) === 123);
```

@@ -48,2 +62,19 @@

const Strings = require('core-functions/strings');
// Arbitrary usage
assert(Strings.isBlank(' '));
assert(!Strings.isNotBlank(' '));
assert(Strings.trim(null) === null);
assert(Strings.trim(' abc ') === 'abc');
assert(Strings.isString('Abc'));
assert(Strings.isString(String('Xyz')));
assert(!Strings.isString({}));
assert(Strings.nthIndexOf('123 123 123', '23', 3) === 9);
const obj = {};
obj.self = obj; // recursive object graph
console.log(Strings.stringify(obj)); // Logs: {"self":[Circular: this]}
```

@@ -53,2 +84,15 @@ To use the number utilities

const Numbers = require('core-functions/numbers');
// Arbitrary usage
assert(Numbers.isInteger(Number(123)) === true);
assert(Numbers.isInteger(Number(123.001)) === false);
assert(Numbers.isInteger(undefined) === false);
assert(Numbers.isFiniteNumber(Number.MAX_VALUE) === true);
assert(Numbers.isFiniteNumber(Number.POSITIVE_INFINITY) === false);
assert(Numbers.isIntegerLike('1234567890123456789012345678901234567890') === true);
assert(Numbers.isIntegerLike('1234567890123456789012345678901234567890.00000000001') === false);
// ... plus more functions
```

@@ -59,2 +103,8 @@

const Booleans = require('core-functions/booleans');
// Arbitrary usage
assert(Booleans.isBoolean(0) === false);
assert(Booleans.isBoolean('') === false);
assert(Booleans.isBoolean(true) === true);
assert(Booleans.isBoolean(false) === true);
```

@@ -65,2 +115,6 @@

const base64 = require('core-functions/base64');
// Arbitrary usage
console.log(base64.toBase64('ABC')); // Displays: IkFCQyI=
console.log(base64.fromBase64('IkFCQyI=')); // Displays: ABC
```

@@ -71,2 +125,8 @@

const Dates = require('core-functions/dates');
// Arbitrary usage
assert(Dates.isSimpleISODate(new Date('2017-07-21Z')) === true);
assert(Dates.isSimpleISODate(new Date('2017-07-2123:59Z')) === false);
// ... plus more functions
```

@@ -77,2 +137,9 @@

const sorting = require('core-functions/sorting');
// Arbitrary usage
assert(sorting.compareIntegerLikes('1234567890123456789012345678901234567890', '1234567890123456789012345678901234567889') === 1);
assert(sorting.compareIntegerLikes('1234567890123456789012345678901234567890', '1234567890123456789012345678901234567890') === 0);
assert(sorting.compareIntegerLikes('1234567890123456789012345678901234567890', '1234567890123456789012345678901234567891') === -1);
// ... plus more functions
```

@@ -83,2 +150,7 @@

const Promises = require('core-functions/promises');
// Arbitrary usage
Promises.delay(1000).then(() => console.log('Tock'));
// ... plus MANY more functions
```

@@ -89,2 +161,5 @@

const Objects = require('core-functions/objects');
console.log(Objects.getPropertyKeys({a:1, b:2})); // ['a', 'b']
console.log(Objects.toKeyValuePairs({a:1, b:2})); // [['a', 1], ['b', 2]]
```

@@ -95,2 +170,10 @@

const Arrays = require('core-functions/arrays');
// Arbitrary usage
assert(Arrays.isDistinct([1,2,3]) === true);
assert(Arrays.isDistinct([1,1,2,2,3]) === false);
assert(Arrays.distinct([1,1,2,2,3]).length === 3); // [1,2,3]
assert(Arrays.flatten([[1], [2,3], [4,5]]).length === 5); // [1,2,3,4,5]
```

@@ -101,2 +184,6 @@

const timers = require('core-functions/timers');
// Arbitrary usage
const timer = setTimeout(1000, () => { console.log('Tick'); });
timers.cancelTimeout(timer);
```

@@ -108,4 +195,4 @@

const Try = tries.Try;
const Success = tries.Success;
const Failure = tries.Failure;
// const Success = tries.Success;
// const Failure = tries.Failure;

@@ -131,3 +218,3 @@ // Simulate getting a Success outcome from successful execution of a function, which returns a value

// using recover function to convert a Failed outcome's error into a Success(123)
const outcome3 = outcome2.recover(err => 123);
const outcome3 = outcome2.recover(err => { console.error(err); return 123; });
assert(outcome3.isSuccess());

@@ -139,3 +226,3 @@ assert(outcome3.value === 123);

value => {
return value * 42;
return value + 42;
},

@@ -147,2 +234,4 @@ err => {

);
assert(outcome4.value === 'Abc42');
```

@@ -175,6 +264,44 @@

const toAppErrorForApiGateway = appErrors.toAppErrorForApiGateway;
// Arbitrary usage
const code = Math.floor(Math.random() * 10) + 1;
let err = null;
let cause = new Error('Boom');
switch(code) {
case 1:
err = new BadRequest('Invalid request', '001', new Error('Xyz is not valid')); break;
case 2:
err = new Unauthorized('Not authorized', '002', cause); break;
case 3:
err = new Forbidden('Access forbidden', '003', cause); break;
case 4:
err = new NotFound('File not found', '004', cause); break;
case 5:
err = new RequestTimeout('Request timed out', '005', cause); break;
case 6:
err = new TooManyRequests('Too many requests', '006', cause); break;
case 7:
err = new InternalServerError('Internal server failure', '007', cause); break;
case 8:
err = new BadGateway('Bad, bad Gateway', '008', cause); break;
case 9:
err = new ServiceUnavailable('Service is currently unavailable', '009'); break;
case 10:
err = new GatewayTimeout('Gateway timed out', '010'); break;
default:
err = new AppError('Unexpected error', code, null, 418); break;
}
console.log(`Currently supported HTTP status codes: ${supportedHttpStatusCodes}`);
console.log('Corresponding AppError:', toAppError(cause));
console.log('Corresponding AppError for API Gateway:', toAppErrorForApiGateway(err));
if (err) {
throw err;
}
```
## Unit tests
This module's unit tests were developed with and must be run with [tape](https://www.npmjs.com/package/tape). The unit tests have been tested on [Node.js v4.3.2](https://nodejs.org/en/blog/release/v4.3.2/).
This module's unit tests were developed with and must be run with [tape](https://www.npmjs.com/package/tape). The unit tests have been tested on [Node.js v6.10.3](https://nodejs.org/en/blog/release/v6.10.3).

@@ -181,0 +308,0 @@ See the [package source](https://github.com/byron-dupreez/core-functions) for more details.

## Changes
### 3.0.20
- Updated usage notes and tested with Node version number in `README.md`
### 3.0.19

@@ -4,0 +7,0 @@ - Renamed dummy first exports (`exports._ = '_'; //IDE workaround`) of most modules to (`exports._$_ = '_$_';`) to avoid

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc