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

graphql-input-number

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-input-number - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

54

lib/float.js

@@ -30,3 +30,3 @@ 'use strict';

exports.default = function (_ref) {
var argName = _ref.argName;
var error = _ref.error;
var max = _ref.max;

@@ -37,16 +37,19 @@ var min = _ref.min;

var test = _ref.test;
var typeName = _ref.typeName;
var name = _ref.name;
if (!typeName) {
throw new Error('"typeName" is required');
if (!name) {
throw new Error('"name" is required');
}
if (!argName) {
throw new Error('"argName" is required');
if (typeof error !== 'function') {
error = function error(_ref2) {
var value = _ref2.value;
var ast = _ref2.ast;
var message = _ref2.message;
var more = message ? ' ' + message + '.' : '';
throw new _error.GraphQLError('Invalid value ' + JSON.stringify(value) + '.' + more, ast ? [ast] : []);
};
}
var error = function error(value, ast, message) {
throw new _error.GraphQLError('Argument "' + argName + '" has invalid value ' + JSON.stringify(value) + '.' + (message ? ' ' + message : '') + '.', ast ? [ast] : []);
};
var parseValue = function parseValue(value, ast) {

@@ -58,2 +61,4 @@ value = coerceFloat(value);

// Sanitization Phase
if (sanitize) {

@@ -66,14 +71,35 @@ value = sanitize(value);

// Validation Phase
if (min != null && value < min) {
error(value, ast, 'Expected minimum "' + min + '"');
return error({
type: 'min',
value: value,
min: min,
message: 'Expected minimum "' + min + '"',
ast: ast
});
}
if (max != null && value > max) {
error(value, ast, 'Expected maximum "' + max + '"');
return error({
type: 'max',
value: value,
max: max,
message: 'Expected maximum "' + max + '"',
ast: ast
});
}
if (test && !test(value)) {
return null;
return error({
type: 'test',
value: value,
test: test,
ast: ast
});
}
// Parse Phase
if (parse) {

@@ -87,3 +113,3 @@ return parse(value);

return new _graphql.GraphQLScalarType({
name: typeName,
name: name,
serialize: coerceFloat,

@@ -90,0 +116,0 @@ parseValue: parseValue,

@@ -32,3 +32,3 @@ 'use strict';

exports.default = function (_ref) {
var argName = _ref.argName;
var error = _ref.error;
var max = _ref.max;

@@ -39,16 +39,19 @@ var min = _ref.min;

var test = _ref.test;
var typeName = _ref.typeName;
var name = _ref.name;
if (!typeName) {
throw new Error('"typeName" is required');
if (!name) {
throw new Error('"name" is required');
}
if (!argName) {
throw new Error('"argName" is required');
if (typeof error !== 'function') {
error = function error(_ref2) {
var value = _ref2.value;
var ast = _ref2.ast;
var message = _ref2.message;
var more = message ? ' ' + message + '.' : '';
throw new _error.GraphQLError('Invalid value ' + JSON.stringify(value) + '.' + more, ast ? [ast] : []);
};
}
var error = function error(value, ast, message) {
throw new _error.GraphQLError('Argument "' + argName + '" has invalid value ' + JSON.stringify(value) + '.' + (message ? ' ' + message : '') + '.', ast ? [ast] : []);
};
var parseValue = function parseValue(value, ast) {

@@ -60,2 +63,4 @@ value = coerceInt(value);

// Sanitization Phase
if (sanitize) {

@@ -68,14 +73,35 @@ value = sanitize(value);

// Validation Phase
if (min != null && value < min) {
error(value, ast, 'Expected minimum "' + min + '"');
return error({
type: 'min',
value: value,
min: min,
message: 'Expected minimum "' + min + '"',
ast: ast
});
}
if (max != null && value > max) {
error(value, ast, 'Expected maximum "' + max + '"');
return error({
type: 'max',
value: value,
max: max,
message: 'Expected maximum "' + max + '"',
ast: ast
});
}
if (test && !test(value)) {
return null;
return error({
type: 'test',
value: value,
test: test,
ast: ast
});
}
// Parse Phase
if (parse) {

@@ -89,3 +115,3 @@ return parse(value);

return new _graphql.GraphQLScalarType({
name: typeName,
name: name,
serialize: coerceInt,

@@ -92,0 +118,0 @@ parseValue: parseValue,

{
"name": "graphql-input-number",
"version": "0.0.7",
"version": "0.0.8",
"description": "A configurable custom input number type for GraphQL with sanitization and validation.",

@@ -5,0 +5,0 @@ "main": "lib/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