Socket
Socket
Sign inDemoInstall

type-check

Package Overview
Dependencies
1
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.2 to 0.4.0

44

lib/check.js

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

// Generated by LiveScript 1.4.0
// Generated by LiveScript 1.6.0
(function(){
var ref$, any, all, isItNaN, types, defaultType, customTypes, toString$ = {}.toString;
var ref$, any, all, isItNaN, types, defaultType, toString$ = {}.toString;
ref$ = require('prelude-ls'), any = ref$.any, all = ref$.all, isItNaN = ref$.isItNaN;

@@ -39,8 +39,8 @@ types = {

};
function checkArray(input, type){
function checkArray(input, type, options){
return all(function(it){
return checkMultiple(it, type.of);
return checkMultiple(it, type.of, options);
}, input);
}
function checkTuple(input, type){
function checkTuple(input, type, options){
var i, i$, ref$, len$, types;

@@ -50,3 +50,3 @@ i = 0;

types = ref$[i$];
if (!checkMultiple(input[i], types)) {
if (!checkMultiple(input[i], types, options)) {
return false;

@@ -58,3 +58,3 @@ }

}
function checkFields(input, type){
function checkFields(input, type, options){
var inputKeys, numInputKeys, k, numOfKeys, key, ref$, types;

@@ -70,3 +70,3 @@ inputKeys = {};

types = ref$[key];
if (!checkMultiple(input[key], types)) {
if (!checkMultiple(input[key], types, options)) {
return false;

@@ -80,3 +80,3 @@ }

}
function checkStructure(input, type){
function checkStructure(input, type, options){
if (!(input instanceof Object)) {

@@ -87,10 +87,10 @@ return false;

case 'fields':
return checkFields(input, type);
return checkFields(input, type, options);
case 'array':
return checkArray(input, type);
return checkArray(input, type, options);
case 'tuple':
return checkTuple(input, type);
return checkTuple(input, type, options);
}
}
function check(input, typeObj){
function check(input, typeObj, options){
var type, structure, setting, that;

@@ -102,7 +102,7 @@ type = typeObj.type, structure = typeObj.structure;

}
setting = customTypes[type] || types[type];
setting = options.customTypes[type] || types[type];
if (setting) {
return setting.typeOf === toString$.call(input).slice(8, -1) && setting.validate(input);
return (setting.typeOf === void 8 || setting.typeOf === toString$.call(input).slice(8, -1)) && setting.validate(input);
} else {
return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj));
return type === toString$.call(input).slice(8, -1) && (!structure || checkStructure(input, typeObj, options));
}

@@ -115,3 +115,3 @@ } else if (structure) {

}
return checkStructure(input, typeObj);
return checkStructure(input, typeObj, options);
} else {

@@ -121,3 +121,3 @@ throw new Error("No type defined. Input: " + input + ".");

}
function checkMultiple(input, types){
function checkMultiple(input, types, options){
if (toString$.call(types).slice(8, -1) !== 'Array') {

@@ -127,3 +127,3 @@ throw new Error("Types must be in an array. Input: " + input + ".");

return any(function(it){
return check(input, it);
return check(input, it, options);
}, types);

@@ -133,5 +133,7 @@ }

options == null && (options = {});
customTypes = options.customTypes || {};
return checkMultiple(input, parsedType);
if (options.customTypes == null) {
options.customTypes = {};
}
return checkMultiple(input, parsedType, options);
};
}).call(this);

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

// Generated by LiveScript 1.4.0
// Generated by LiveScript 1.6.0
(function(){
var VERSION, parseType, parsedTypeCheck, typeCheck;
VERSION = '0.3.2';
VERSION = '0.4.0';
parseType = require('./parse-type');

@@ -6,0 +6,0 @@ parsedTypeCheck = require('./check');

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

// Generated by LiveScript 1.4.0
// Generated by LiveScript 1.6.0
(function(){

@@ -137,3 +137,3 @@ var identifierRegex, tokenRegex;

function consumeTypes(tokens){
var lookahead, types, typesSoFar, typeObj, type;
var lookahead, types, typesSoFar, typeObj, type, structure;
if ('::' === peek(tokens)) {

@@ -164,7 +164,9 @@ throw new Error("No comment before comment separator '::' found.");

for (;;) {
typeObj = consumeType(tokens), type = typeObj.type;
typeObj = consumeType(tokens), type = typeObj.type, structure = typeObj.structure;
if (!typesSoFar[type]) {
types.push(typeObj);
}
typesSoFar[type] = true;
if (structure == null) {
typesSoFar[type] = true;
}
if (!maybeConsumeOp(tokens, '|')) {

@@ -171,0 +173,0 @@ break;

{
"name": "type-check",
"version": "0.3.2",
"version": "0.4.0",
"author": "George Zahariev <z@georgezahariev.com>",

@@ -32,10 +32,9 @@ "description": "type-check allows you to check the types of JavaScript values at runtime with a Haskell like type syntax.",

"dependencies": {
"prelude-ls": "~1.1.2"
"prelude-ls": "^1.2.1"
},
"devDependencies": {
"livescript": "~1.4.0",
"mocha": "~2.3.4",
"istanbul": "~0.4.1",
"browserify": "~12.0.1"
"livescript": "^1.6.0",
"mocha": "^7.1.1",
"browserify": "^16.5.1"
}
}

@@ -5,3 +5,3 @@ # type-check [![Build Status](https://travis-ci.org/gkz/type-check.png?branch=master)](https://travis-ci.org/gkz/type-check)

`type-check` is a library which allows you to check the types of JavaScript values at runtime with a Haskell like type syntax. It is great for checking external input, for testing, or even for adding a bit of safety to your internal code. It is a major component of [levn](https://github.com/gkz/levn). MIT license. Version 0.3.2. Check out the [demo](http://gkz.github.io/type-check/).
`type-check` is a library which allows you to check the types of JavaScript values at runtime with a Haskell like type syntax. It is great for checking external input, for testing, or even for adding a bit of safety to your internal code. It is a major component of [levn](https://github.com/gkz/levn). MIT license. Version 0.4.0. Check out the [demo](http://gkz.github.io/type-check/).

@@ -138,3 +138,3 @@ For updates on `type-check`, [follow me on twitter](https://twitter.com/gkzahariev).

* __Type__ = an `Identifier`, an `Identifier` followed by a `Structure`, just a `Structure`, or a wildcard `*` - eg. `String`, `Object{x: Number}`, `{x: Number}`, `Array{0: String, 1: Boolean, length: Number}`, `*`
* __Types__ = optionally a comment (an `Indentifier` followed by a `::`), optionally the identifier `Maybe`, one or more `Type`, separated by `|` - eg. `Number`, `String | Date`, `Maybe Number`, `Maybe Boolean | String`
* __Types__ = optionally a comment (an `Identifier` followed by a `::`), optionally the identifier `Maybe`, one or more `Type`, separated by `|` - eg. `Number`, `String | Date`, `Maybe Number`, `Maybe Boolean | String`
* __Structure__ = `Fields`, or a `Tuple`, or an `Array` - eg. `{x: Number}`, `(String, Number)`, `[Date]`

@@ -208,3 +208,3 @@ * __Fields__ = a `{`, followed one or more `Field` separated by a comma `,` (trailing comma `,` is permitted), optionally an `...` (always preceded by a comma `,`), followed by a `}` - eg. `{x: Number, y: String}`, `{k: Function, ...}`

The `typeOf` property is the type the value should be, and `validate` is a function which should return true if the value is of that type. `validate` receives one parameter, which is the value that we are checking.
The `typeOf` property is the type the value should be (optional - if not set only `validate` will be used), and `validate` is a function which should return true if the value is of that type. `validate` receives one parameter, which is the value that we are checking.

@@ -211,0 +211,0 @@ ## Technical About

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc