New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

check-more-types

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-more-types - npm Package Compare versions

Comparing version 0.8.1 to 0.9.0

2

bower.json
{
"name": "check-more-types",
"main": "check-more-types.js",
"version": "0.8.1",
"version": "0.9.0",
"homepage": "https://github.com/kensho/check-more-types",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -149,2 +149,57 @@ (function checkMoreTypes(check) {

/**
Returns true if given value is [], {} or ''
@method empty
*/
function empty(a) {
var hasLength = typeof a === 'string' ||
Array.isArray(a);
if (hasLength) {
return !a.length;
}
if (a instanceof Object) {
return !Object.keys(a).length;
}
return false;
}
/**
Returns true if given value has .length and it is not zero, or has properties
@method unempty
*/
function unempty(a) {
var hasLength = typeof a === 'string' ||
Array.isArray(a);
if (hasLength) {
return a.length;
}
if (a instanceof Object) {
return Object.keys(a).length;
}
return true;
}
/**
Returns true if 0 <= value <= 1
@method unit
*/
function unit(value) {
return check.number(value) &&
value >= 0.0 && value <= 1.0;
}
var rgb = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
/**
Returns true if value is hex RGB between '#000000' and '#FFFFFF'
@method hexRgb
*/
function hexRgb(value) {
return check.string(value) &&
rgb.test(value);
}
//
// helper methods
//
if (!check.defend) {

@@ -251,3 +306,7 @@ check.defend = function defend(fn) {

schema: schema,
raises: raises
raises: raises,
empty: empty,
unempty: unempty,
unit: unit,
hexRgb: hexRgb
};

@@ -254,0 +313,0 @@

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

!function(a){"use strict";function b(a){return"undefined"!=typeof a}function c(a){return 0===a||1===a}function d(a){return"boolean"==typeof a}function e(a,b){return Boolean(a&&b&&"string"==typeof b&&"undefined"!=typeof a[b])}function f(b){return a.string(b)&&b.toLowerCase()===b}function g(b){return a.array(b)&&b.length>0}function h(b,c){var d=a.array(b)&&b.every(a.string);return d&&a.bool(c)&&c?b.every(a.lowerCase):d}function i(b,c){return a.array(b)&&b.every(function(b){return a.arrayOfStrings(b,c)})}function j(b,c){return a.verify.object(b,"missing object to check"),a.verify.object(c,"missing predicates object"),Object.keys(c).forEach(function(b){a.verify.fn(c[b],"not a predicate function for "+b)}),a.every(a.map(b,c))}function k(a,b){return j(b,a)}function l(b,c){a.verify.fn(b,"expected function that raises");try{b()}catch(d){return"undefined"==typeof c?!0:"function"==typeof c?c(d):!1}return!1}if(!a)throw new Error("Cannot find check-types library, has it been loaded?");a.defend||(a.defend=function(b){var c=Array.prototype.slice.call(arguments,1);return function(){for(var d=arguments.length;d--;){var e=c[d];if(a.fn(e)&&!e.call(null,arguments[d]))throw new Error("Argument "+(d+1)+" "+arguments[d]+" does not pass predicate")}return b.apply(null,arguments)}}),a.mixin||(a.mixin=function(b,c){function d(b,c,d){a.verify.object(b,"missing object"),a.verify.unemptyString(c,"missing name"),a.verify.fn(d,"missing function"),b[c]||(b[c]=d)}function e(b){return function(){return!a.defined(arguments[0])||a.nulled(arguments[0])?!0:b.apply(null,arguments)}}function f(a){return function(){return!a.apply(null,arguments)}}function g(b,c){return function(){var d;if(b.apply(null,arguments)===!1)throw d=arguments[arguments.length-1],new Error(a.unemptyString(d)?d:c)}}a.verify.fn(b,"expected predicate function"),a.unemptyString(c)||(c=b.name),a.verify.unemptyString(c,"predicate function missing name\n"+b.toString()),d(a,c,b),d(a.maybe,c,e(b)),d(a.not,c,f(b)),d(a.verify,c,g(b,c+" failed"))});var m={defined:b,bit:c,bool:d,has:e,lowerCase:f,unemptyArray:g,arrayOfStrings:h,arrayOfArraysOfStrings:i,all:j,schema:k,raises:l};Object.keys(m).forEach(function(b){a.mixin(m[b],b)})}("object"==typeof window?window.check:global.check);
!function(a){"use strict";function b(a){return"undefined"!=typeof a}function c(a){return 0===a||1===a}function d(a){return"boolean"==typeof a}function e(a,b){return Boolean(a&&b&&"string"==typeof b&&"undefined"!=typeof a[b])}function f(b){return a.string(b)&&b.toLowerCase()===b}function g(b){return a.array(b)&&b.length>0}function h(b,c){var d=a.array(b)&&b.every(a.string);return d&&a.bool(c)&&c?b.every(a.lowerCase):d}function i(b,c){return a.array(b)&&b.every(function(b){return a.arrayOfStrings(b,c)})}function j(b,c){return a.verify.object(b,"missing object to check"),a.verify.object(c,"missing predicates object"),Object.keys(c).forEach(function(b){a.verify.fn(c[b],"not a predicate function for "+b)}),a.every(a.map(b,c))}function k(a,b){return j(b,a)}function l(b,c){a.verify.fn(b,"expected function that raises");try{b()}catch(d){return"undefined"==typeof c?!0:"function"==typeof c?c(d):!1}return!1}function m(a){var b="string"==typeof a||Array.isArray(a);return b?!a.length:a instanceof Object?!Object.keys(a).length:!1}function n(a){var b="string"==typeof a||Array.isArray(a);return b?a.length:a instanceof Object?Object.keys(a).length:!0}function o(b){return a.number(b)&&b>=0&&1>=b}function p(b){return a.string(b)&&q.test(b)}if(!a)throw new Error("Cannot find check-types library, has it been loaded?");var q=/^#(?:[0-9a-fA-F]{3}){1,2}$/;a.defend||(a.defend=function(b){var c=Array.prototype.slice.call(arguments,1);return function(){for(var d=arguments.length;d--;){var e=c[d];if(a.fn(e)&&!e.call(null,arguments[d]))throw new Error("Argument "+(d+1)+" "+arguments[d]+" does not pass predicate")}return b.apply(null,arguments)}}),a.mixin||(a.mixin=function(b,c){function d(b,c,d){a.verify.object(b,"missing object"),a.verify.unemptyString(c,"missing name"),a.verify.fn(d,"missing function"),b[c]||(b[c]=d)}function e(b){return function(){return!a.defined(arguments[0])||a.nulled(arguments[0])?!0:b.apply(null,arguments)}}function f(a){return function(){return!a.apply(null,arguments)}}function g(b,c){return function(){var d;if(b.apply(null,arguments)===!1)throw d=arguments[arguments.length-1],new Error(a.unemptyString(d)?d:c)}}a.verify.fn(b,"expected predicate function"),a.unemptyString(c)||(c=b.name),a.verify.unemptyString(c,"predicate function missing name\n"+b.toString()),d(a,c,b),d(a.maybe,c,e(b)),d(a.not,c,f(b)),d(a.verify,c,g(b,c+" failed"))});var r={defined:b,bit:c,bool:d,has:e,lowerCase:f,unemptyArray:g,arrayOfStrings:h,arrayOfArraysOfStrings:i,all:j,schema:k,raises:l,empty:m,unempty:n,unit:o,hexRgb:p};Object.keys(r).forEach(function(b){a.mixin(r[b],b)})}("object"==typeof window?window.check:global.check);

@@ -15,2 +15,5 @@ # {%= name %} v{%= version %}

This documentation was generated using [grunt-xplain](https://github.com/bahmutov/grunt-xplain)
and [grunt-readme](https://github.com/jonschlinkert/grunt-readme).
## MIT License

@@ -17,0 +20,0 @@

@@ -25,2 +25,22 @@ ### check.defined

### check.unit
check.unit(0); // true
check.unit(1); // true
check.unit(0.1); // true
check.unit(1.2); // false
check.unit(-0.1); // false
---
### check.hexRgb
check.hexRgb('#FF00FF'); // true
check.hexRgb('#000'); // true
check.hexRgb('#aaffed'); // true
check.hexRgb('#00aaffed'); // false
check.hexRgb('aaffed'); // false
---
### check.bool

@@ -37,2 +57,23 @@

### check.empty
check.empty([]); // true
check.empty(''); // true
check.empty({}); // true
check.empty(0); // false
check.empty(['foo']); // false
---
### check.unempty
check.unempty([]); // false
check.unempty(''); // false
check.unempty({}); // false
check.unempty(0); // true
check.unempty(['foo']); // true
check.unempty('foo'); // true
---
### check.unemptyArray

@@ -39,0 +80,0 @@

@@ -39,3 +39,3 @@ module.exports = function(grunt) {

options: {
heading: '** API **\n'
heading: '* **API**\n'
},

@@ -42,0 +42,0 @@ files: {

{
"name": "check-more-types",
"description": "Additional type checks for https://github.com/philbooth/check-types.js",
"version": "0.8.1",
"version": "0.9.0",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",

@@ -6,0 +6,0 @@ "bugs": {

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

# check-more-types v0.8.1
# check-more-types v0.9.0

@@ -39,5 +39,9 @@ > Additional type checks for [check-types.js](https://github.com/philbooth/check-types.js)

** API **
* **API**
* [check.bit](#checkbit)
* [check.unit](#checkunit)
* [check.hexRgb](#checkhexrgb)
* [check.bool](#checkbool)
* [check.empty](#checkempty)
* [check.unempty](#checkunempty)
* [check.unemptyArray](#checkunemptyarray)

@@ -89,2 +93,22 @@ * [check.arrayOfStrings](#checkarrayofstrings)

#### check.unit
check.unit(0); // true
check.unit(1); // true
check.unit(0.1); // true
check.unit(1.2); // false
check.unit(-0.1); // false
---
#### check.hexRgb
check.hexRgb('#FF00FF'); // true
check.hexRgb('#000'); // true
check.hexRgb('#aaffed'); // true
check.hexRgb('#00aaffed'); // false
check.hexRgb('aaffed'); // false
---
#### check.bool

@@ -101,2 +125,23 @@

#### check.empty
check.empty([]); // true
check.empty(''); // true
check.empty({}); // true
check.empty(0); // false
check.empty(['foo']); // false
---
#### check.unempty
check.unempty([]); // false
check.unempty(''); // false
check.unempty({}); // false
check.unempty(0); // true
check.unempty(['foo']); // true
check.unempty('foo'); // true
---
#### check.unemptyArray

@@ -387,2 +432,5 @@

This documentation was generated using [grunt-xplain](https://github.com/bahmutov/grunt-xplain)
and [grunt-readme](https://github.com/jonschlinkert/grunt-readme).
## MIT License

@@ -389,0 +437,0 @@

@@ -716,2 +716,75 @@ describe('check-more-types', function () {

});
describe('check.unit', function () {
/** @sample check/unit */
it('check.unit', function () {
la(check.unit(0));
la(check.unit(1));
la(check.unit(0.1));
la(!check.unit(1.2));
la(!check.unit(-0.1));
});
it('check.unit edge cases', function () {
la(check.unit(0));
la(check.unit(1));
la(check.unit(0.1));
la(check.unit(0.00001));
la(!check.unit(-0.1));
la(!check.unit(-1));
la(!check.unit(10));
la(!check.unit(-10));
la(!check.unit('0.1'));
});
});
describe('check.hexRgb', function () {
/** @sample check/hexRgb */
it('check.hexRgb', function () {
la(check.hexRgb('#FF00FF'));
la(check.hexRgb('#000'));
la(check.hexRgb('#aaffed'));
la(!check.hexRgb('#00aaffed'));
la(!check.hexRgb('aaffed'));
});
it('check.hexRgb works', function () {
la(check.hexRgb('#ffffff'));
la(check.hexRgb('#FF00FF'));
la(check.hexRgb('#000'));
la(check.hexRgb('#000000'));
});
it('fails for other cases', function () {
la(!check.hexRgb('ffffff'));
la(!check.hexRgb('#FF00FFF'));
la(!check.hexRgb('#ggjjaa'));
la(!check.hexRgb('#000000#'));
la(!check.hexRgb('red'));
});
});
describe('check.empty', function () {
/** @sample check/empty */
it('check.empty', function () {
la(check.empty([]));
la(check.empty(''));
la(check.empty({}));
la(!check.empty(0));
la(!check.empty(['foo']));
});
});
describe('check.unempty', function () {
/** @sample check/unempty */
it('check.unempty', function () {
la(!check.unempty([]));
la(!check.unempty(''));
la(!check.unempty({}));
la(check.unempty(0));
la(check.unempty(['foo']));
la(check.unempty('foo'));
});
});
});
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