diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f35b35f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,119 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +Changes not listed here (skipped semver) are typically dependency updates or README fixes. + + +## [0.7.8] - 2023-05-19 + +### Added + +- (string) `isUUID` / `isUuid` alias +- (string) `isJSON` / `isJson` alias + +## [0.7.7] - 2023-03-30 + +### Added + +- (string) `isUuid` + + +## [0.7.5] - 2021-11-03 + +### Added + +- (string) `isMySqlTimestamp` + + +## [0.7.0] - 2017-12-10 + +### Added + +- (primitive) `isBoolean` + + +## [0.5.0] - 2017-11-19 + +### Added + +- babel support and point main package to dist es5 version + + +## [0.4.0] - 2017-08-24 + +### Added + +- (string) `isTimestamp` + + +## [0.3.0] - 2017-08-11 + +### Added + +- (number) `isNumeric` +- (string) `isNumericString` + + +## [0.2.2] - 2017-02-22 + +### Added + +- (string) `isStringOfLengthBetween` + +### Fixed + +- (number) `isCalendarMonth` +- (number) `isCalendarMonthZeroBased` + + +## [0.2.1] - 2017-02-22 + +### Changed + +- (number) optimize `isNumberBetween` + + +## [0.2.0] - 2017-02-22 + +### Added + +- (object) `isObject` +- (object) `isObjectContaining` +- (object) `isObjectAbsent` +- (object) `isObjectMatching` +- (object) `isObjectExtending` +- (object) `isObjectSatisfying` + +### Changed + +- update to ES6 + + +## [0.1.0] - 2015-12-31 + +### Added + +- (string) `isJSON` + + +## [0.0.9] - 2015-07-08 + +### Added + +- (number) `isNumericBoolean` + + +## [0.0.5] - 2015-07-07 + +### Added + +- (number) `numberIsOneOf` +- (string) `stringIsOneOf` + + +## [0.0.1] - 2015-07-07 + +### Added + +- Initial commit diff --git a/README.md b/README.md index 0a95a3a..b79bc60 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,13 @@ const validateUserOrThrow = V.isObjectOf(userType); validateUserOrThrow(userType, user); ``` +# Interface +- [Strings](#strings) +- [Numbers](#numbers) +- [Arrays](#arrays) +- [Objects](#objects) +- [Primitives](#primitives) + ## Strings ### isString @@ -187,19 +194,29 @@ expect(prr.isNumericString('asd123asd')).toBe(false); ``` --- -### isJSON +### isJSON / isJson String → Boolean ``` expect(prr.isJSON('foo')).toBe(false); expect(prr.isJSON('{foo:"bar"}')).toBe(false); expect(prr.isJSON('{}')).toBe(true); expect(prr.isJSON('{"foo":"bar"}')).toBe(true); + +expect(prr.isJson('foo')).toBe(false); +expect(prr.isJson('{foo:"bar"}')).toBe(false); +expect(prr.isJson('{}')).toBe(true); +expect(prr.isJson('{"foo":"bar"}')).toBe(true); ``` --- -### isUuid +### isUUID / isUuid String → Boolean ``` +expect(prr.isUUID('foo')).toBe(false); +expect(prr.isUUID(123)).toBe(false); +expect(prr.isUUID('cd17c371-9468-963b-f3e0bf05e70e')).toBe(false); +expect(prr.isUUID('cd17c371-9468-4baa-963b-f3e0bf05e70e')).toBe(true); + expect(prr.isUuid('foo')).toBe(false); expect(prr.isUuid(123)).toBe(false); expect(prr.isUuid('cd17c371-9468-963b-f3e0bf05e70e')).toBe(false); diff --git a/lib/predicates/arrays.js b/lib/predicates/arrays.js index f9dbf44..dc7bab6 100644 --- a/lib/predicates/arrays.js +++ b/lib/predicates/arrays.js @@ -5,11 +5,11 @@ const R = require('ramda'), module.exports = { isArray : R.is(Array), - isArrayOfLength : __.ofLength(Array, 'identical'), + isArrayOfLength : __.ofLength(Array, 'equals'), isArrayOfLengthAtLeast : __.ofLength(Array, 'gte'), isArrayOfLengthAtMost : __.ofLength(Array, 'lte'), isArrayLongerThan : __.ofLength(Array, 'gt'), isArrayShorterThan : __.ofLength(Array, 'lt'), - isArrayContaining : R.contains(R.__), + isArrayContaining : R.includes(R.__), isEmptyArray : R.allPass([R.is(Array), R.isEmpty]) }; diff --git a/lib/predicates/numbers.js b/lib/predicates/numbers.js index f017b00..82fac31 100644 --- a/lib/predicates/numbers.js +++ b/lib/predicates/numbers.js @@ -12,7 +12,7 @@ const isNumberBetweenInclusive = R.curry((min, max, n) => { }); const numberIsOneOf = R.curry((selectionArr, num) => { - return R.allPass([R.is(Number), R.contains(R.__, selectionArr)])(num); + return R.allPass([R.is(Number), R.includes(R.__, selectionArr)])(num); }); const isNumber = R.is(Number), @@ -25,7 +25,7 @@ const isNumber = R.is(Number), isEvenNumber = __.modTwoEq(0), isOddNumber = __.modTwoEq(1), isNumeric = v => !isNaN(parseInt(v, 10)), - isNumericBoolean = R.contains(R.__, [0, 1]); + isNumericBoolean = R.includes(R.__, [0, 1]); module.exports = { isNumber, diff --git a/lib/predicates/strings.js b/lib/predicates/strings.js index aa28bb0..3a3b5f7 100644 --- a/lib/predicates/strings.js +++ b/lib/predicates/strings.js @@ -4,7 +4,7 @@ const R = require('ramda'), __ = require('./_private.js'); const isString = R.is(String), - isStringOfLength = __.ofLength(String, 'identical'), + isStringOfLength = __.ofLength(String, 'equals'), isStringOfLengthAtLeast = __.ofLength(String, 'gte'), isStringOfLengthAtMost = __.ofLength(String, 'lte'), isStringLongerThan = __.ofLength(String, 'gt'), @@ -19,7 +19,7 @@ const isStringMatching = R.curry((pattern, str) => { }); const stringIsOneOf = R.curry((selectionArr, str) => { - return R.allPass([R.is(String), R.contains(R.__, selectionArr)])(str); + return R.allPass([R.is(String), R.includes(R.__, selectionArr)])(str); }); const isStringOfLengthBetween = R.curry((min, max, str) => { @@ -38,7 +38,7 @@ const isTimestamp = R.test(/(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([ const isMySqlTimestamp = R.test(/^([1-2][0-9]{3})-([0-1][0-9])-([0-3][0-9])(?:( [0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/); -const isUuid = R.test(/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi); +const isUUID = R.test(/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi); const isJSON = (str) => { try { @@ -66,5 +66,7 @@ module.exports = { isMySqlTimestamp, isEmail, isJSON, - isUuid + isUUID, + isJson : isJSON, + isUuid : isUUID }; diff --git a/package.json b/package.json index 22923bd..6d6aa0b 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "prettycats", - "version": "0.7.7", + "version": "0.7.8", "description": "Helpful, common, and curried predicates library built on Ramda.", "main": "dist/prettycats.js", "dependencies": { - "ramda": "^0.27.x" + "ramda": "^0.29.x" }, "devDependencies": { "@babel/cli": "^7.6.4", diff --git a/yarn.lock b/yarn.lock index dd67d34..e680540 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2435,10 +2435,10 @@ qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== -ramda@^0.27.x: - version "0.27.1" - resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.27.1.tgz#66fc2df3ef873874ffc2da6aa8984658abacf5c9" - integrity sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw== +ramda@^0.29.x: + version "0.29.0" + resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.29.0.tgz#fbbb67a740a754c8a4cbb41e2a6e0eb8507f55fb" + integrity sha512-BBea6L67bYLtdbOqfp8f58fPMqEwx0doL+pAi8TZyp2YWz8R9G8z9x75CZI8W+ftqhFHCpEX2cRnUUXK130iKA== read-pkg-up@^4.0.0: version "4.0.0"