Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typeforce

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typeforce - npm Package Compare versions

Comparing version 1.3.5 to 1.3.6

52

lib/index.js

@@ -7,38 +7,39 @@ 'use strict';

function tfJSON(type) {
if (nativeTypes.Function(type)) return type.toJSON ? type.toJSON() : getFunctionName(type);
if (nativeTypes.Object(type)) {
var json = {};
function getValueTypeName(value) {
if (nativeTypes.Null(value)) return '';
for (var propertyName in type) {
json[propertyName] = tfJSON(type[propertyName]);
}
return getFunctionName(value.constructor);
}
return JSON.stringify(json);
}
function getValue(value) {
if (nativeTypes.Function(value)) return '';
if (nativeTypes.String(value)) return JSON.stringify(value);
if (value && nativeTypes.Object(value)) return '';
return type;
return value;
}
function getTypeTypeName(type) {
var typeJson = tfJSON(type);
function tfJSON(type) {
if (nativeTypes.Function(type)) return type.toJSON ? type.toJSON() : getFunctionName(type);
if (nativeTypes.Array(type)) return 'Array';
if (type && nativeTypes.Object(type)) return 'Object';
return nativeTypes.Object(typeJson) ? JSON.stringify(typeJson) : typeJson;
return type || '';
}
function getValueTypeName(value) {
if (nativeTypes.Null(value)) return '';
function stfJSON(type) {
type = tfJSON(type);
return getFunctionName(value.constructor);
return nativeTypes.Object(type) ? JSON.stringify(type) : type;
}
function tfErrorString(type, value) {
var typeTypeName = getTypeTypeName(type);
var valueTypeName = getValueTypeName(value);
var valueValue = getValue(value);
return 'Expected ' + typeTypeName + ', got ' + (valueTypeName && valueTypeName + ' ') + JSON.stringify(value);
return 'Expected ' + stfJSON(type) + ', got' + (valueTypeName !== '' ? ' ' + valueTypeName : '') + (valueValue !== '' ? ' ' + valueValue : '');
}
function tfPropertyErrorString(type, name, value) {
return tfErrorString('property \"' + name + '\" of type ' + getTypeTypeName(type), value);
return tfErrorString('property \"' + name + '\" of type ' + stfJSON(type), value);
}

@@ -119,3 +120,3 @@

maybe.toJSON = function () {
return '?' + tfJSON(type);
return '?' + stfJSON(type);
};

@@ -140,2 +141,7 @@

} catch (e) {
if (/Expected property "/.test(e.message)) {
e.message = e.message.replace(/Expected property "(.+)" of/, 'Expected property "' + propertyName + '.$1" of');
throw e;
}
throw new TypeError(tfPropertyErrorString(propertyType, propertyName, propertyValue));

@@ -155,3 +161,3 @@ }

object.toJSON = function () {
return type;
return tfJSON(type);
};

@@ -177,3 +183,3 @@

oneOf.toJSON = function () {
return types.map(tfJSON).join('|');
return types.map(stfJSON).join('|');
};

@@ -206,3 +212,3 @@

tuple.toJSON = function () {
return '(' + types.map(tfJSON).join(', ') + ')';
return '(' + types.map(stfJSON).join(', ') + ')';
};

@@ -209,0 +215,0 @@

{
"name": "typeforce",
"version": "1.3.5",
"version": "1.3.6",
"description": "Another biased type checking solution for Javascript",

@@ -34,2 +34,3 @@ "author": "Daniel Cousens",

"standard": "standard",
"start": "npm run watch",
"test": "npm run standard && npm run unit",

@@ -36,0 +37,0 @@ "unit": "mocha --compilers js:babel/register test/index.js",

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