diff --git a/package-lock.json b/package-lock.json index 839be8fe9..eb9658331 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "nock": "13.3.8", "semantic-release": "19.0.5", "semantic-release-monorepo": "7.0.5", - "typescript": "^5.3.2" + "typescript": "5.3.2" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -89,7 +89,6 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/@adobe/helix-universal/-/helix-universal-4.4.1.tgz", "integrity": "sha512-YJKiuzeAZvzkardlAVcyW/PYNzKfIf/3v7Dd22wxvimmI3gct4k3V39gUSVrP+sWZPvlBS67WMNCv28n0eKjWg==", - "optional": true, "dependencies": { "@adobe/fetch": "4.1.1", "aws4": "1.12.0" @@ -12099,7 +12098,7 @@ }, "packages/spacecat-shared-dynamo": { "name": "@adobe/spacecat-shared-dynamo", - "version": "1.0.0", + "version": "1.1.2", "license": "Apache-2.0", "dependencies": { "@adobe/spacecat-shared-utils": "1.0.1", @@ -12117,21 +12116,19 @@ }, "packages/spacecat-shared-example": { "name": "@adobe/spacecat-shared-example", - "version": "1.0.0", + "version": "1.1.0", "license": "Apache-2.0", "dependencies": { "@adobe/fetch": "4.1.1", "@adobe/helix-shared-wrap": "2.0.0", + "@adobe/helix-universal": "4.4.1", "aws4": "1.12.0" }, - "devDependencies": {}, - "optionalDependencies": { - "@adobe/helix-universal": "4.4.1" - } + "devDependencies": {} }, "packages/spacecat-shared-utils": { "name": "@adobe/spacecat-shared-utils", - "version": "1.0.1", + "version": "1.1.0", "license": "Apache-2.0", "devDependencies": { "chai": "4.3.10" diff --git a/packages/spacecat-shared-utils/src/functions.js b/packages/spacecat-shared-utils/src/functions.js index 1fc87f96b..87b786b5a 100644 --- a/packages/spacecat-shared-utils/src/functions.js +++ b/packages/spacecat-shared-utils/src/functions.js @@ -14,6 +14,16 @@ const REGEX_ISO_DATE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/; const REGEX_TIME_OFFSET_DATE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}(Z|[+-]\d{2}:\d{2})/; +/** + * Determines if the given parameter is an array. + * + * @param {*} value - The value to check. + * @returns {boolean} True if the parameter is an array, false otherwise. + */ +function isArray(value) { + return Array.isArray(value); +} + /** * Determines case-insensitively if the given value is a boolean or a string * representation of a boolean. @@ -53,7 +63,7 @@ function isNumber(value) { * @returns {boolean} True if the parameter is an object, false otherwise. */ function isObject(value) { - return !Array.isArray(value) && value !== null && typeof value === 'object'; + return !isArray(value) && value !== null && typeof value === 'object'; } /** @@ -150,14 +160,15 @@ function toBoolean(value) { * @param {Array} b - The second array to compare. * @returns {boolean} True if the arrays are equal, false otherwise. */ -const arrayEquals = (a, b) => Array.isArray(a) - && Array.isArray(b) +const arrayEquals = (a, b) => isArray(a) + && isArray(b) && a.length === b.length && a.every((val, index) => val === b[index]); export { arrayEquals, hasText, + isArray, isBoolean, isInteger, isValidDate, diff --git a/packages/spacecat-shared-utils/src/index.js b/packages/spacecat-shared-utils/src/index.js index ac3f00747..517615578 100644 --- a/packages/spacecat-shared-utils/src/index.js +++ b/packages/spacecat-shared-utils/src/index.js @@ -13,6 +13,7 @@ export { arrayEquals, hasText, + isArray, isBoolean, isInteger, isValidDate, diff --git a/packages/spacecat-shared-utils/test/functions.test.js b/packages/spacecat-shared-utils/test/functions.test.js index f346cf72e..ff86f94d3 100644 --- a/packages/spacecat-shared-utils/test/functions.test.js +++ b/packages/spacecat-shared-utils/test/functions.test.js @@ -18,6 +18,7 @@ import { expect } from 'chai'; import { hasText, isBoolean, + isArray, isInteger, isValidDate, isIsoDate, @@ -81,6 +82,24 @@ describe('Shared functions', () => { expect(hasText('a12dsamklda')).to.be.true; }); + it('is array', () => { + const invalidArrays = [ + true, + {}, + { asd: 'dsa' }, + '', + 'dasd', + NaN, + Infinity, + -Infinity, + 123, + ]; + + invalidArrays.forEach((value) => expect(isArray(value)).to.be.false); + expect(isArray([])).to.be.true; + expect(isArray(['abc'])).to.be.true; + }); + it('is boolean', () => { const invalidBooleans = [ null, diff --git a/packages/spacecat-shared-utils/test/index.test.js b/packages/spacecat-shared-utils/test/index.test.js index 3a1a9fbb4..6b2231096 100644 --- a/packages/spacecat-shared-utils/test/index.test.js +++ b/packages/spacecat-shared-utils/test/index.test.js @@ -19,6 +19,7 @@ describe('Index Exports', () => { const expectedExports = [ 'arrayEquals', 'hasText', + 'isArray', 'isBoolean', 'isInteger', 'isValidDate',