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

type-utils

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

type-utils - npm Package Compare versions

Comparing version 0.10.2 to 0.10.3

dist/index.js

15

package.json
{
"name": "type-utils",
"version": "0.10.2",
"version": "0.10.3",
"description": "",
"main": "./src/index.js",
"scripts": {
"build": "webpack",
"build": "babel ./src --presets babel-preset-es2015 --out-dir ./dist",
"test": "mocha",
"prepublish": "npm run build"
"prepublish": "npm run build"
},

@@ -21,2 +21,10 @@ "repository": "git+https://github.com/MyNameReallySux/type-utils.git",

"homepage": "https://github.com/MyNameReallySux/type-utils#readme",
"babel": {
"presets": ["env"],
"plugins": [
"transform-regenerator",
"remove-comments"
],
"retainLines": true
},
"devDependencies": {

@@ -26,2 +34,3 @@ "babel-core": "^6.24.1",

"babel-plugin-proxy": "^1.1.0",
"babel-plugin-remove-comments": "^2.0.0",
"babel-plugin-transform-regenerator": "^6.24.1",

@@ -28,0 +37,0 @@ "babel-preset-env": "^1.5.1",

4

src/index.js

@@ -5,4 +5,4 @@ /* ##########################

import TypeUtils from './TypeUtils.js'
import Validator from './Validator.js'
import TypeUtils from './TypeUtils'
import Validator from './Validatorba'

@@ -9,0 +9,0 @@ export {

@@ -28,3 +28,5 @@ /* ##########################

for(let key in types){
if(types.hasOwnProperty(key) && types[key](test)) return key
if(types.hasOwnProperty(key) && types[key](test)){
return key
}
}

@@ -43,3 +45,3 @@ }

static isArray(test){
return typeof Array.isArray === 'function' && Array.isArray(test) || TypeUtils.getObjectType(test) === '[object Array]'
return typeof Array.isArray === 'function' && Array.isArray(test)
}

@@ -56,6 +58,3 @@ static isBoolean(test){

static isObject(test){
if(test === undefined) return false
if(test === null) return false
if(TypeUtils.isArray(test)) return false
return test.constructor.toString().contains("Object") || typeof test == 'object'
return test === Object(test) && typeof test === 'object' && !TypeUtils.isArray(test)
}

@@ -218,6 +217,6 @@ static isString(test){

number: TypeUtils.isNumber,
object: TypeUtils.isObject,
string: TypeUtils.isString,
symbol: TypeUtils.isSymbol,
object: TypeUtils.isObject,
'undefined': TypeUtils.isUndefined,

@@ -224,0 +223,0 @@ 'null': TypeUtils.isNull

@@ -6,3 +6,3 @@ /* ##########################

import $ from 'jquery'
import { TypeUtils as Types } from './TypeUtils.js'
import TypeUtils from './TypeUtils'

@@ -154,5 +154,5 @@ /* ##########################

handleMeta(key, options){
this.fields[key].displayName = Types.isUndefined(options.displayName) ? key.toReadable().capitalize() : options.displayName
this.fields[key].functionName = Types.isUndefined(options.functionName) ? `isValid${key.toCamelCase().capitalize()}` : options.functionName
handleMeta(key, options){
this.fields[key].displayName = TypeUtils.isUndefined(options.displayName) ? key.toReadable().capitalize() : options.displayName
this.fields[key].functionName = TypeUtils.isUndefined(options.functionName) ? `isValid${key.toCamelCase().capitalize()}` : options.functionName
}

@@ -162,3 +162,3 @@

let patterns = options.pattern || options.patterns
let type = Types.getType(patterns)
let type = TypeUtils.getType(patterns)

@@ -175,3 +175,3 @@ switch(type){

for(let pattern in patterns){
let pType = Types.getType(pattern)
let pType = TypeUtils.getType(pattern)
switch(pType){

@@ -187,3 +187,3 @@ case 'regexp':

throw new Error(`Cannot define validator with pattern of type ${pType}, must be [string|regexp]`)
}
}
}

@@ -201,3 +201,3 @@ }

let predicates = options.predicate || options.predicates
let type = Types.getType(predicates)
let type = TypeUtils.getType(predicates)

@@ -211,3 +211,3 @@ switch(type){

for(let predicate in predicates){
let pType = Types.getType(predicate)
let pType = TypeUtils.getType(predicate)
switch(pType){

@@ -251,7 +251,7 @@ case 'function':

const defaults = Validator.defaults.string
const isEmpty = Types.isEmptyString(test)
const isEmpty = TypeUtils.isEmptyString(test)
requirements = Object.assign({}, defaults, requirements)
if(Types.isUndefined(test) || Types.isNull(test)) {
if(TypeUtils.isUndefined(test) || TypeUtils.isNull(test)) {
errors.push(`${requirements.displayName} field value was undefined or null!`)

@@ -268,8 +268,8 @@ } else {

}
if(Types.isRegExp(requirements.pattern) && !requirements.pattern.test(test)){
if(TypeUtils.isRegExp(requirements.pattern) && !requirements.pattern.test(test)){
errors.push(`${requirements.displayName}'s field did not match the required pattern, was ${test} \n pattern: '${requirements.pattern}'`)
}
if(Types.isArray(requirements.pattern)){
if(TypeUtils.isArray(requirements.pattern)){
for(let pattern in requirements.pattern){
if(Types.isRegExp(pattern) && !pattern.test(test)){
if(TypeUtils.isRegExp(pattern) && !pattern.test(test)){
errors.push(`${requirements.displayName}'s field did not match one of the required pattern, was ${test} \n pattern: '${requirements.match}'`)

@@ -279,8 +279,8 @@ }

}
if(Types.isFunction(requirements.predicate) && !requirements.predicate()){
if(TypeUtils.isFunction(requirements.predicate) && !requirements.predicate()){
errors.push(`${requirements.displayName}'s field did not match the required predicate, was ${test}'`)
}
if(Types.isArray(requirements.predicate)){
if(TypeUtils.isArray(requirements.predicate)){
for(let predicate in requirements.predicate){
if(Types.isRegExp(pattern) && !pattern.test(test)){
if(TypeUtils.isRegExp(pattern) && !pattern.test(test)){
errors.push(`${requirements.displayName}'s field did not match one of the required predicates, was ${test}'`)

@@ -299,3 +299,3 @@ }

if(Types.isUndefined(test) || Types.isNull(test)) {
if(TypeUtils.isUndefined(test) || TypeUtils.isNull(test)) {
errors.push(`${requirements.displayName} field value was undefined or null!`)

@@ -312,8 +312,8 @@ } else {

}
if(Types.isFunction(requirements.predicate) && !requirements.predicate()){
if(TypeUtils.isFunction(requirements.predicate) && !requirements.predicate()){
errors.push(`${requirements.displayName}'s field did not match the required predicate, was ${test}'`)
}
if(Types.isArray(requirements.predicate)){
if(TypeUtils.isArray(requirements.predicate)){
for(let predicate in requirements.predicate){
if(Types.isRegExp(pattern) && !pattern.test(test)){
if(TypeUtils.isRegExp(pattern) && !pattern.test(test)){
errors.push(`${requirements.displayName}'s field did not match one of the required predicates, was ${test}'`)

@@ -320,0 +320,0 @@ }

@@ -5,3 +5,3 @@ const jsdom = require("jsdom");

const assert = require('assert')
const Types = require('../src/Types').default
const Types = require('../src/TypeUtils').default
const jQuery = require('jquery')

@@ -43,2 +43,3 @@

string: 'test',
object: {},
'null': null,

@@ -107,3 +108,3 @@ 'undefined': undefined,

})
})
})
describe('Numbers', function(){

@@ -133,3 +134,3 @@ it("Should return 'number' when '1' is passed in", function(done){

done()
})
})
})

@@ -140,2 +141,3 @@ describe('Objects', function(){

let result = Types.getType(test)
assert.equal(result, Types.getNativeType(test))

@@ -506,3 +508,2 @@ done()

let result
for (let test of tests){

@@ -509,0 +510,0 @@ result = Types.isObject(test)

import assert from 'assert'
import Validator from '../src/Validator'
import Types from '../src/TypeUtils'
describe('Validator', function(){

@@ -42,3 +40,3 @@ describe('#constructor', function(){

let result
let result

@@ -45,0 +43,0 @@ for(let test in tests){

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