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

@byll/validated

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@byll/validated - npm Package Compare versions

Comparing version 1.12.1 to 1.12.2

45

lib/src/index.js

@@ -8,2 +8,3 @@ "use strict";

const moment = require('moment-timezone');
const isPositiveNumberInteger = /^[0-9]+$/;
moment.tz.add('Europe/Berlin|CET CEST CEMT|-10 -20 -30|01010101010101210101210101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-2aFe0 11d0 1iO0 11A0 1o00 11A0 Qrc0 6i00 WM0 1fA0 1cM0 1cM0 1cM0 kL0 Nc0 m10 WM0 1ao0 1cp0 dX0 jz0 Dd0 1io0 17c0 1fA0 1a00 1ehA0 1a00 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00|41e5');

@@ -241,2 +242,46 @@ exports.factories = {}; // for validators

/**
* Pagination validator. Validates values of form "offset,limit"
* @param requirement max offset+limit (last reachable element)
*/
exports.factories.page = (requirement) => {
const last = requirement ? parseInt(requirement, 10) : 10000;
if (!Number.isInteger(last) || last < 0 || last > 10000) {
throw new Error(`Invalid page requirement "${requirement}"`);
}
return (value) => {
if (typeof value !== 'string' || value.length > 9) {
return 'Can be a string with max length 9';
}
const parts = value.split(',');
if (parts.length !== 2 || !isPositiveNumberInteger.test(parts[0])
|| !isPositiveNumberInteger.test(parts[1])
|| parseInt(parts[0], 10) + parseInt(parts[1], 10) > last) {
return 'Can be of format offset,limit';
}
return null;
};
};
/**
* Sort column validator. Validates values of form "column,direction"
* @param requirement comma separated list of sortable columns
*/
exports.factories.sort = (requirement) => {
if (!requirement) {
throw new Error('No list of sortable columns provided to "sort"-validator');
}
const valid = requirement.split(',');
const error = `Can be of format column,direction. Allowed columns: ${valid.join(', ')}. Allowed directions: asc,desc.`;
return (value) => {
if (typeof value !== 'string') {
return error;
}
const parts = value.split(',');
if (parts.length !== 2 || valid.indexOf(parts[0]) === -1
|| (parts[1] !== 'asc' && parts[1] !== 'desc')) {
return error;
}
return null;
};
};
/**
* @param value

@@ -243,0 +288,0 @@ * @param {Validator[]} validators

2

package.json
{
"name": "@byll/validated",
"version": "1.12.1",
"version": "1.12.2",
"main": "lib/src/index.js",

@@ -5,0 +5,0 @@ "typings": "lib/src/index",

@@ -6,2 +6,3 @@ import { isValidDecimalString } from './helpers/isValidDecimalString'

const moment = require('moment-timezone')
const isPositiveNumberInteger = /^[0-9]+$/
moment.tz.add('Europe/Berlin|CET CEST CEMT|-10 -20 -30|01010101010101210101210101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-2aFe0 11d0 1iO0 11A0 1o00 11A0 Qrc0 6i00 WM0 1fA0 1cM0 1cM0 1cM0 kL0 Nc0 m10 WM0 1ao0 1cp0 dX0 jz0 Dd0 1io0 17c0 1fA0 1a00 1ehA0 1a00 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1cM0 1fA0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00 11A0 1qM0 WM0 1qM0 WM0 1qM0 WM0 1qM0 11A0 1o00 11A0 1o00|41e5')

@@ -211,2 +212,44 @@

/**
* Pagination validator. Validates values of form "offset,limit"
* @param requirement max offset+limit (last reachable element)
*/
factories.page = (requirement?: string): Validator => {
const last = requirement ? parseInt(requirement, 10) : 10000
if (!Number.isInteger(last) || last < 0 || last > 10000) {
throw new Error(`Invalid page requirement "${requirement}"`)
}
return (value: any) => {
if (typeof value !== 'string' || value.length > 9) { return 'Can be a string with max length 9' }
const parts = value.split(',')
if (parts.length !== 2 || !isPositiveNumberInteger.test(parts[0])
|| !isPositiveNumberInteger.test(parts[1])
|| parseInt(parts[0], 10) + parseInt(parts[1], 10) > last
) {
return 'Can be of format offset,limit'
}
return null
}
}
/**
* Sort column validator. Validates values of form "column,direction"
* @param requirement comma separated list of sortable columns
*/
factories.sort = (requirement?: string): Validator => {
if (!requirement) { throw new Error('No list of sortable columns provided to "sort"-validator') }
const valid = requirement.split(',')
const error = `Can be of format column,direction. Allowed columns: ${valid.join(', ')}. Allowed directions: asc,desc.`
return (value: any) => {
if (typeof value !== 'string') { return error }
const parts = value.split(',')
if (parts.length !== 2 || valid.indexOf(parts[0]) === -1
|| (parts[1] !== 'asc' && parts[1] !== 'desc')
) {
return error
}
return null
}
}
/**
* @param value

@@ -213,0 +256,0 @@ * @param {Validator[]} validators

@@ -18,2 +18,3 @@ {

"strictNullChecks": true,
"lib": ["ES6"],
"target": "ES6"

@@ -20,0 +21,0 @@ },

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