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.11.3 to 1.11.4

89

errors.js
var inherits = require('inherits')
var native = require('./native')
function getTypeName (fn) {
return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1]
}
function getValueTypeName (value) {
return native.Nil(value) ? '' : getTypeName(value.constructor)
}
function getValue (value) {
if (native.Function(value)) return ''
if (native.String(value)) return JSON.stringify(value)
if (value && native.Object(value)) return ''
return value
}
function tfJSON (type) {
if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type)
if (native.Array(type)) return 'Array'
if (type && native.Object(type)) return 'Object'
return type !== undefined ? type : ''
}
function tfErrorString (type, value, valueTypeName) {
var valueJson = getValue(value)
return 'Expected ' + tfJSON(type) + ', got' +
(valueTypeName !== '' ? ' ' + valueTypeName : '') +
(valueJson !== '' ? ' ' + valueJson : '')
}
function tfPropertyErrorString (type, label, name, value, valueTypeName) {
var description = '" of type '
if (label === 'key') description = '" with key type '
return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName)
}
function TfTypeError (type, value, valueTypeName) {

@@ -22,4 +60,12 @@ this.__error = Error.call(this)

})
Object.defineProperty(this, 'stack', {
get: function () {
return this.__error.stack
}
})
}
inherits(TfTypeError, Error)
function TfPropertyTypeError (type, property, label, value, error, valueTypeName) {

@@ -56,6 +102,3 @@ this.__error = error || Error.call(this)

// inherit from Error
[TfTypeError, TfPropertyTypeError].forEach(function (tfErrorType) {
inherits(tfErrorType, Error)
})
inherits(TfPropertyTypeError, Error)

@@ -87,40 +130,2 @@ function tfCustomError (expected, actual) {

function getTypeName (fn) {
return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1]
}
function getValueTypeName (value) {
return native.Nil(value) ? '' : getTypeName(value.constructor)
}
function getValue (value) {
if (native.Function(value)) return ''
if (native.String(value)) return JSON.stringify(value)
if (value && native.Object(value)) return ''
return value
}
function tfJSON (type) {
if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type)
if (native.Array(type)) return 'Array'
if (type && native.Object(type)) return 'Object'
return type !== undefined ? type : ''
}
function tfErrorString (type, value, valueTypeName) {
var valueJson = getValue(value)
return 'Expected ' + tfJSON(type) + ', got' +
(valueTypeName !== '' ? ' ' + valueTypeName : '') +
(valueJson !== '' ? ' ' + valueJson : '')
}
function tfPropertyErrorString (type, label, name, value, valueTypeName) {
var description = '" of type '
if (label === 'key') description = '" with key type '
return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName)
}
module.exports = {

@@ -127,0 +132,0 @@ TfTypeError: TfTypeError,

@@ -175,7 +175,7 @@ var ERRORS = require('./errors')

if (NATIVE.String(type)) {
if (type[0] === '?') return TYPES.maybe(compile(type.slice(1)))
if (type[0] === '?') return TYPES.maybe(type.slice(1))
return NATIVE[type] || TYPES.quacksLike(type)
} else if (type && NATIVE.Object(type)) {
if (NATIVE.Array(type)) return TYPES.arrayOf(compile(type[0]))
if (NATIVE.Array(type)) return TYPES.arrayOf(type[0])

@@ -182,0 +182,0 @@ return TYPES.object(type)

{
"name": "typeforce",
"version": "1.11.3",
"version": "1.11.4",
"description": "Another biased type checking solution for Javascript",

@@ -5,0 +5,0 @@ "keywords": [

# typeforce
[![build status](https://secure.travis-ci.org/dcousens/typeforce.png)](http://travis-ci.org/dcousens/typeforce)

@@ -59,3 +58,2 @@ [![Version](https://img.shields.io/npm/v/typeforce.svg)](https://www.npmjs.org/package/typeforce)

**Pro**tips:
``` javascript

@@ -90,3 +88,2 @@ // use precompiled primitives for high performance

**Pro**tips (extended types):
``` javascript

@@ -122,5 +119,5 @@ typeforce(typeforce.tuple('String', 'Number'), ['foo', 1])

WARNING: Be very wary of using the `quacksLike` type, as it relies on the `Foo.name` property.
**WARNING**: Be very wary of using the `quacksLike` type, as it relies on the `Foo.name` property.
If that property is mangled by a transpiler, such as `uglifyjs`, you will have a bad time.
## LICENSE [ISC](LICENSE)
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