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.10.6 to 1.11.0

2

errors.js

@@ -87,3 +87,3 @@ var inherits = require('inherits')

function getValueTypeName (value) {
return native.Null(value) ? '' : getTypeName(value.constructor)
return native.Nil(value) ? '' : getTypeName(value.constructor)
}

@@ -90,0 +90,0 @@

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

var errors = require('./errors')
var NATIVE = require('./native')
var ERRORS = require('./errors')

@@ -6,18 +7,3 @@ function _Buffer (value) {

}
_Buffer.toJSON = function () { return 'Buffer' }
function _BufferN (length) {
function BufferN (value) {
if (!Buffer.isBuffer(value)) return false
if (value.length !== length) {
throw errors.tfCustomError('Buffer(Length: ' + length + ')', 'Buffer(Length: ' + value.length + ')')
}
return true
}
BufferN.toJSON = function () { return 'Buffer' }
return BufferN
}
function Hex (value) {

@@ -27,16 +13,20 @@ return typeof value === 'string' && /^([0-9a-f]{2})+$/i.test(value)

function _HexN (length) {
function HexN (value) {
if (!Hex(value)) return false
if (value.length !== length) {
throw errors.tfCustomError('Hex(Length: ' + length + ')', 'Hex(Length: ' + value.length + ')')
}
function _LengthN (type, length) {
let name = type.toJSON()
return true
function Length (value) {
if (!type(value)) return false
if (value.length === length) return true
throw ERRORS.tfCustomError(name + '(Length: ' + length + ')', name + '(Length: ' + value.length + ')')
}
HexN.toJSON = function () { return 'Hex' }
Length.toJSON = function () { return name }
return HexN
return Length
}
let _ArrayN = _LengthN.bind(null, NATIVE.Array)
let _BufferN = _LengthN.bind(null, _Buffer)
let _HexN = _LengthN.bind(null, Hex)
var UINT53_MAX = Math.pow(2, 53) - 1

@@ -60,3 +50,4 @@

module.exports = {
var types = {
ArrayN: _ArrayN,
Buffer: _Buffer,

@@ -75,1 +66,9 @@ BufferN: _BufferN,

}
for (var typeName in types) {
types[typeName].toJSON = function (t) {
return t
}.bind(null, typeName)
}
module.exports = types

@@ -35,3 +35,3 @@ var ERRORS = require('./errors')

function _maybe (value, strict) {
return NATIVE.Null(value) || type(value, strict, maybe)
return NATIVE.Nil(value) || type(value, strict, maybe)
}

@@ -49,3 +49,3 @@ _maybe.toJSON = function () { return '?' + tfJSON(type) }

if (!NATIVE.Object(value, strict)) return false
if (NATIVE.Null(value, strict)) return false
if (NATIVE.Nil(value, strict)) return false

@@ -92,3 +92,3 @@ for (var propertyName in value) {

if (!NATIVE.Object(value)) return false
if (NATIVE.Null(value)) return false
if (NATIVE.Nil(value)) return false

@@ -212,5 +212,5 @@ var propertyName

var extra = require('./extra')
for (typeName in extra) {
typeforce[typeName] = extra[typeName]
var EXTRA = require('./extra')
for (typeName in EXTRA) {
typeforce[typeName] = EXTRA[typeName]
}

@@ -217,0 +217,0 @@

@@ -5,3 +5,3 @@ var types = {

Function: function (value) { return typeof value === 'function' },
Null: function (value) { return value === undefined || value === null },
Nil: function (value) { return value === undefined || value === null },
Number: function (value) { return typeof value === 'number' },

@@ -13,2 +13,5 @@ Object: function (value) { return typeof value === 'object' },

// TODO: deprecate
types.Null = types.Nil
for (var typeName in types) {

@@ -15,0 +18,0 @@ types[typeName].toJSON = function (t) {

{
"name": "typeforce",
"version": "1.10.6",
"version": "1.11.0",
"description": "Another biased type checking solution for Javascript",

@@ -17,3 +17,3 @@ "keywords": [

},
"license": "MIT",
"license": "ISC",
"author": "Daniel Cousens",

@@ -20,0 +20,0 @@ "main": "index.js",

@@ -46,5 +46,5 @@ # typeforce

function LongString (value, strict) {
if (!typeforce.String(value)) return false
if (value.length !== 32) return false
return true
if (!typeforce.String(value)) return false
if (value.length !== 32) return false
return true
}

@@ -67,4 +67,4 @@

var type = {
foo: 'Number',
bar: '?String'
foo: 'Number',
bar: '?String'
}

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

typeforce({
x: 'Number'
x: 'Number'
}, { x: 1 }, true)

@@ -86,3 +86,3 @@ // OK!

typeforce({
x: 'Number'
x: 'Number'
}, { x: 1, y: 2 }, true)

@@ -127,2 +127,2 @@ // TypeError: Unexpected property 'y' of type Number

## LICENSE [MIT](LICENSE)
## LICENSE [ISC](LICENSE)

Sorry, the diff of this file is not supported yet

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