New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-powertools

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-powertools - npm Package Compare versions

Comparing version 1.0.9 to 1.0.10

30

dist/index.js

@@ -147,11 +147,3 @@ (function (root, factory) {

Powertools.force = function (input, type, options) {
if (type === 'string') {
return forceString(input);
} else if (type === 'number') {
return forceNumber(input);
} else if (type === 'boolean') {
return forceBoolean(input);
} else if (type === 'array') {
return forceArray(input, options);
}
return forceType(input, type, options);
};

@@ -212,2 +204,16 @@

function forceType(input, type, options) {
if (type === 'string') {
return forceString(input);
} else if (type === 'number') {
return forceNumber(input);
} else if (type === 'boolean') {
return forceBoolean(input);
} else if (type === 'array') {
return forceArray(input, options);
} else if (type === 'undefined') {
return undefined;
}
}
function forceString(input) {

@@ -307,2 +313,8 @@ if (typeof input === 'string') {

// If only one type is allowed, force it
if (types.length === 1 && types[0] !== 'any') {
return isValidType ? value : forceType(value, types[0]);
}
// If multiple types are allowed, return the value if it is valid type, otherwise return the default
return isValidType ? value : def;

@@ -309,0 +321,0 @@ }

{
"name": "node-powertools",
"version": "1.0.9",
"version": "1.0.10",
"description": "Powerful assistive functions for Node and Browser environments.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -147,11 +147,3 @@ (function (root, factory) {

Powertools.force = function (input, type, options) {
if (type === 'string') {
return forceString(input);
} else if (type === 'number') {
return forceNumber(input);
} else if (type === 'boolean') {
return forceBoolean(input);
} else if (type === 'array') {
return forceArray(input, options);
}
return forceType(input, type, options);
};

@@ -212,2 +204,16 @@

function forceType(input, type, options) {
if (type === 'string') {
return forceString(input);
} else if (type === 'number') {
return forceNumber(input);
} else if (type === 'boolean') {
return forceBoolean(input);
} else if (type === 'array') {
return forceArray(input, options);
} else if (type === 'undefined') {
return undefined;
}
}
function forceString(input) {

@@ -307,2 +313,8 @@ if (typeof input === 'string') {

// If only one type is allowed, force it
if (types.length === 1 && types[0] !== 'any') {
return isValidType ? value : forceType(value, types[0]);
}
// If multiple types are allowed, return the value if it is valid type, otherwise return the default
return isValidType ? value : def;

@@ -309,0 +321,0 @@ }

@@ -283,3 +283,3 @@ const package = require('../package.json');

min: 1,
max: 2,
max: 10,
},

@@ -352,3 +352,3 @@ admin: {

it('should enforce acceptable types', () => {
it('should disallow unacceptable types', () => {
const user = {

@@ -365,6 +365,20 @@ name: 123,

assert.strictEqual(result.name, defaults[planId].name.default);
assert.strictEqual(result.name, `${user.name}`);
assert.strictEqual(result.stats.level, defaults[planId].stats.level.default);
});
it('should enforce acceptable types', () => {
const user = {
stats: {
level: '3',
},
};
const planId = 'basic';
const result = powertools.defaults(user, defaults[planId]);
assert.strictEqual(typeof result.stats.level, typeof defaults[planId].stats.level.default);
assert.strictEqual(result.stats.level, parseInt(user.stats.level));
});
it('should enforce min and max constraints', () => {

@@ -374,3 +388,3 @@ const user = {

stats: {
level: 5,
level: 50,
},

@@ -377,0 +391,0 @@ };

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