Skip to content

Commit

Permalink
Merge pull request #22 from losandes/feat/is-array-of-primitives
Browse files Browse the repository at this point in the history
feat: adds is.arrayOf for evaluting arrays of primitives
  • Loading branch information
losandes authored Apr 1, 2021
2 parents a6d62ae + 00e37f7 commit 26e4a80
Show file tree
Hide file tree
Showing 14 changed files with 4,383 additions and 5,277 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -28,17 +28,20 @@ jobs:
- run: node --version
- run: npm --version

- name: Install pnpm
run: npm i -g pnpm

- name: Install npm dependencies
run: npm ci
run: pnpm install

- name: Lint the code
run: npm run lint
run: pnpm run lint

- name: Build browser distribution
run: npm run build --if-present
run: pnpm run build --if-present

- name: Run tests
run: npm run test:coverage:ci
run: pnpm run test:coverage:ci
env:
CI: true

Expand Down
40 changes: 28 additions & 12 deletions dist/blueprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
bp = blueprint(name, schema);
}

if (bp.err) {
throw bp.err;
}

var cleanMessage = function cleanMessage(key, message) {
return message.replace("Invalid ".concat(bp.name, ": "), '').replace(/expected `/g, "expected `".concat(key, "."));
};
Expand Down Expand Up @@ -527,7 +523,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var context;

if (from) {
context = _objectSpread({}, ctx, {}, {
context = _objectSpread(_objectSpread({}, ctx), {
value: from(ctx)
});
} else {
Expand Down Expand Up @@ -585,7 +581,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var context;

if (from) {
context = _objectSpread({}, ctx, {}, {
context = _objectSpread(_objectSpread({}, ctx), {
value: from(ctx)
});
} else {
Expand Down Expand Up @@ -651,6 +647,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
nullOrWhitespace: undefined,
decimal: undefined,
primitive: undefined,
arrayOf: undefined,
not: {
defined: undefined,
nullOrUndefined: undefined,
Expand All @@ -668,7 +665,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
number: undefined,
nullOrWhitespace: undefined,
decimal: undefined,
primitive: undefined
primitive: undefined,
arrayOf: undefined
}
};
var primitives = ['boolean', 'null', 'undefined', 'number', 'bigint', 'string', 'symbol'];
Expand All @@ -684,11 +682,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
};

is.defined = function (obj) {
try {
return is.getType(obj) !== 'undefined';
} catch (e) {
return false;
}
return is.getType(obj) !== 'undefined';
};

is.not.defined = function (obj) {
Expand Down Expand Up @@ -835,6 +829,28 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return is.primitive(input) === false;
};

is.arrayOf = function (type) {
if (!is[type]) {
throw new Error("is does not support evaluation of {".concat(type, "}"));
}

return function (input) {
return input.find(function (v) {
return is.not[type](v);
}) === undefined;
};
};

is.not.arrayOf = function (type) {
if (!is[type]) {
throw new Error("is does not support evaluation of {".concat(type, "}"));
}

return function (input) {
return is.arrayOf(type)(input) === false;
};
};

return is;
}
};
Expand Down
12 changes: 6 additions & 6 deletions dist/blueprint.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ declare namespace is {
function nullOrWhitespace (input?: any): boolean;
function decimal (input?: any, places?: number): boolean;
function primitive (input?: any): boolean;
function arrayOf (type: string): (input?: any) => boolean;

namespace not {
function defined (input?: any): boolean;
Expand All @@ -305,5 +306,6 @@ declare namespace is {
function nullOrWhitespace (input?: any): boolean;
function decimal (input?: any, places?: number): boolean;
function primitive (input?: any): boolean;
function arrayOf (type: string): (input?: any) => boolean;
}
}
Loading

0 comments on commit 26e4a80

Please sign in to comment.