core-functions
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -7,2 +7,4 @@ 'use strict'; | ||
const any = require('./any'); | ||
const propertyIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
@@ -16,4 +18,4 @@ | ||
module.exports = { | ||
/** Returns the standard valueOf of the given value if defined; otherwise returns the value as is */ | ||
valueOf: valueOf, | ||
/** @deprecated - use {@linkcode core-functions/any#valueOf} instead */ | ||
valueOf: any.valueOf, | ||
isTypedArray: isTypedArray, | ||
@@ -38,12 +40,2 @@ getPropertyNames: getPropertyNames, | ||
/** | ||
* Returns the standard valueOf of the given value (if defined and if it has a valueOf function, which should be true of | ||
* all values); otherwise returns the given value as is. | ||
* @param {*} value - the value to which to apply its valueOf function (if any) | ||
* @returns {*} the valueOf the value or the original value | ||
*/ | ||
function valueOf(value) { | ||
return value && typeof value.valueOf === 'function' ? value.valueOf() : value; | ||
} | ||
/** | ||
* Returns true if object is a subclass instance of TypedArray; false otherwise. | ||
@@ -50,0 +42,0 @@ * @param {TypedArray|*} object - the object to test |
{ | ||
"name": "core-functions", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"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.4 | ||
# core-functions v3.0.5 | ||
@@ -7,2 +7,3 @@ Core functions, utilities and classes for working with Node/JavaScript primitives and built-in objects, including | ||
Currently includes: | ||
- any.js - generic utilities for working with any type of value | ||
- app-errors.js - a collection of standard application AppError subclasses for the more commonly used HTTP status codes | ||
@@ -37,2 +38,7 @@ - arrays.js - Array utilities | ||
To use the `any` utilities | ||
```js | ||
const any = require('core-functions/any'); | ||
``` | ||
To use the string utilities | ||
@@ -163,2 +169,13 @@ ```js | ||
### 3.0.5 | ||
- Added new `any` module: | ||
- Added new `defined` & `notDefined` functions | ||
- Added `valueOf` function removed from `objects` module | ||
- Changes to `objects`: | ||
- Moved `valueOf` function to `any` module | ||
- Deprecated exported `valueOf` function & delegated it to `valueOf` in `any` module | ||
- Changes to `sorting`: | ||
- Removed `isUndefinedOrNull` function & replaced its usage with calls to `notDefined` function from `any` module | ||
- Deprecated exported `isUndefinedOrNull` function & delegated it to `notDefined` function from `any` module | ||
### 3.0.4 | ||
@@ -165,0 +182,0 @@ - Changes to `promises` module: |
'use strict'; | ||
const any = require('./any'); | ||
const notDefined = any.notDefined; | ||
const Strings = require('./strings'); | ||
@@ -31,3 +34,6 @@ const Numbers = require('./numbers'); | ||
SortType: SortType, | ||
isUndefinedOrNull: isUndefinedOrNull, | ||
/** @deprecated - use {@linkcode core-functions/any#notDefined} instead */ | ||
isUndefinedOrNull: any.notDefined, | ||
compareUndefinedOrNull: compareUndefinedOrNull, | ||
@@ -45,7 +51,2 @@ compareNumbers: compareNumbers, | ||
/** Simply returns true if the given value is either undefined or null; false otherwise. */ | ||
function isUndefinedOrNull(a) { | ||
return a === undefined || a === null; | ||
} | ||
/** | ||
@@ -72,3 +73,3 @@ * Compares two undefined or null values for sorting of a useless array consisting entirely of undefined or null values. | ||
if (a === b) return 0; | ||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return compareUndefinedOrNull(a, b); | ||
if (notDefined(a) || notDefined(b)) return compareUndefinedOrNull(a, b); | ||
@@ -92,3 +93,3 @@ // For sorting stability, compare NaNs as "equal" to each other and "less" than any other number | ||
if (a === b) return 0; | ||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return compareUndefinedOrNull(a, b); | ||
if (notDefined(a) || notDefined(b)) return compareUndefinedOrNull(a, b); | ||
@@ -112,3 +113,3 @@ const ignoreCase = !!opts && opts.ignoreCase === true; | ||
if (a === b) return 0; | ||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return compareUndefinedOrNull(a, b); | ||
if (notDefined(a) || notDefined(b)) return compareUndefinedOrNull(a, b); | ||
return a < b ? -1 : a > b ? +1 : 0; | ||
@@ -125,3 +126,3 @@ } | ||
if (a === b) return 0; | ||
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) return compareUndefinedOrNull(a, b); | ||
if (notDefined(a) || notDefined(b)) return compareUndefinedOrNull(a, b); | ||
return compareNumbers(a.getTime(), b.getTime()); | ||
@@ -138,3 +139,3 @@ } | ||
if (i1 === i2) return 0; | ||
if (isUndefinedOrNull(i1) || isUndefinedOrNull(i2)) return compareUndefinedOrNull(i1, i2); | ||
if (notDefined(i1) || notDefined(i2)) return compareUndefinedOrNull(i1, i2); | ||
@@ -284,3 +285,3 @@ if (!i1 || i1.length <= 0) return -1; | ||
// Last resort, convert all of the values (other than strings, undefined or null) to strings | ||
sortableValues = sortableValues.map(v => typeof v === 'string' || isUndefinedOrNull(v) ? v : Strings.stringify(v)); | ||
sortableValues = sortableValues.map(v => typeof v === 'string' || notDefined(v) ? v : Strings.stringify(v)); | ||
compare = compareStrings; | ||
@@ -287,0 +288,0 @@ break; |
@@ -11,3 +11,2 @@ 'use strict'; | ||
const Objects = require('../objects'); | ||
const valueOf = Objects.valueOf; | ||
const toKeyValuePairs = Objects.toKeyValuePairs; | ||
@@ -20,45 +19,2 @@ const getOwnPropertyNamesRecursively = Objects.getOwnPropertyNamesRecursively; | ||
// ===================================================================================================================== | ||
// valueOf | ||
// ===================================================================================================================== | ||
test('valueOf', t => { | ||
function check(value, expected) { | ||
return t.deepEqual(Objects.valueOf(value), expected, `Objects.valueOf(${stringify(value)}) must be ${stringify(expected)}`); | ||
} | ||
// undefined | ||
check(undefined, undefined); | ||
check(null, null); | ||
// strings | ||
check('', ''); | ||
check('a', 'a'); | ||
check('Abc', 'Abc'); | ||
check(new Object(''), ''); // wrapped must unwrap | ||
check(new Object('a'), 'a'); // wrapped must unwrap | ||
check(new Object('Abc'), 'Abc'); // wrapped must unwrap | ||
check(0, 0); | ||
check(1, 1); | ||
check(3.14, 3.14); | ||
check(new Object(0), 0); // wrapped must unwrap | ||
check(new Object(1), 1); // wrapped must unwrap | ||
check(new Object(3.14), 3.14); // wrapped must unwrap | ||
check(true, true); | ||
check(false, false); | ||
check(new Object(true), true); // wrapped must unwrap | ||
check(new Object(false), false); // wrapped must unwrap | ||
check({}, {}); | ||
check({a: 1}, {a: 1}); | ||
check([], []); | ||
check(['a'], ['a']); | ||
check(['a', 1], ['a', 1]); | ||
t.end(); | ||
}); | ||
// ===================================================================================================================== | ||
// toKeyValuePairs | ||
@@ -65,0 +21,0 @@ // ===================================================================================================================== |
{ | ||
"name": "core-functions-tests", | ||
"version": "3.0.4", | ||
"version": "3.0.5", | ||
"author": "Byron du Preez", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
916366
44
14577
439