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

fefe

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fefe - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

1

dist/array.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.array = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function array(elementValidator, { minLength, maxLength } = {}) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.boolean = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function boolean() {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.date = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function date({ min, max } = {}) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.enumerate = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function enumerate(...args) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FefeError = exports.ExtendableError = void 0;
class ExtendableError extends Error {

@@ -4,0 +5,0 @@ constructor(message) {

31

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.union = exports.string = exports.parseNumber = exports.parseJson = exports.parseDate = exports.parseBoolean = exports.defaultTo = exports.optional = exports.object = exports.number = exports.enumerate = exports.date = exports.boolean = exports.array = exports.FefeError = void 0;
var errors_1 = require("./errors");
exports.FefeError = errors_1.FefeError;
Object.defineProperty(exports, "FefeError", { enumerable: true, get: function () { return errors_1.FefeError; } });
var array_1 = require("./array");
exports.array = array_1.array;
Object.defineProperty(exports, "array", { enumerable: true, get: function () { return array_1.array; } });
var boolean_1 = require("./boolean");
exports.boolean = boolean_1.boolean;
Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return boolean_1.boolean; } });
var date_1 = require("./date");
exports.date = date_1.date;
Object.defineProperty(exports, "date", { enumerable: true, get: function () { return date_1.date; } });
var enumerate_1 = require("./enumerate");
exports.enumerate = enumerate_1.enumerate;
Object.defineProperty(exports, "enumerate", { enumerable: true, get: function () { return enumerate_1.enumerate; } });
var number_1 = require("./number");
exports.number = number_1.number;
Object.defineProperty(exports, "number", { enumerable: true, get: function () { return number_1.number; } });
var object_1 = require("./object");
exports.object = object_1.object;
exports.optional = object_1.optional;
exports.defaultTo = object_1.defaultTo;
Object.defineProperty(exports, "object", { enumerable: true, get: function () { return object_1.object; } });
Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return object_1.optional; } });
Object.defineProperty(exports, "defaultTo", { enumerable: true, get: function () { return object_1.defaultTo; } });
var parse_boolean_1 = require("./parse-boolean");
exports.parseBoolean = parse_boolean_1.parseBoolean;
Object.defineProperty(exports, "parseBoolean", { enumerable: true, get: function () { return parse_boolean_1.parseBoolean; } });
var parse_date_1 = require("./parse-date");
exports.parseDate = parse_date_1.parseDate;
Object.defineProperty(exports, "parseDate", { enumerable: true, get: function () { return parse_date_1.parseDate; } });
var parse_json_1 = require("./parse-json");
exports.parseJson = parse_json_1.parseJson;
Object.defineProperty(exports, "parseJson", { enumerable: true, get: function () { return parse_json_1.parseJson; } });
var parse_number_1 = require("./parse-number");
exports.parseNumber = parse_number_1.parseNumber;
Object.defineProperty(exports, "parseNumber", { enumerable: true, get: function () { return parse_number_1.parseNumber; } });
var string_1 = require("./string");
exports.string = string_1.string;
Object.defineProperty(exports, "string", { enumerable: true, get: function () { return string_1.string; } });
var union_1 = require("./union");
exports.union = union_1.union;
Object.defineProperty(exports, "union", { enumerable: true, get: function () { return union_1.union; } });
//# sourceMappingURL=index.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;

@@ -8,0 +20,0 @@ };

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.number = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function number({ min, max, integer, allowNaN = false, allowInfinity = false } = {}) {

@@ -9,8 +9,18 @@ import { Validator } from './validate';

export declare type ObjectDefinition = Record<string, ObjectDefinitionValue<any>>;
declare type ObjectReturnType<T> = T extends ObjectDefinitionValue<infer U> ? U | (T extends {
optional: true;
} ? undefined : never) : never;
declare type ObjectReturnType<T> = T extends ObjectDefinitionValue<infer U> ? U : never;
declare type FilterObject<T, C> = {
[k in keyof T]: T[k] extends C ? k : never;
};
declare type MatchingKeys<T, C> = FilterObject<T, C>[keyof T];
declare type NotFilterObject<T, C> = {
[k in keyof T]: T[k] extends C ? never : k;
};
declare type NonMatchingKeys<T, C> = NotFilterObject<T, C>[keyof T];
export declare function object<D extends ObjectDefinition>(definition: D, { allowExcessProperties }?: {
allowExcessProperties?: boolean;
}): (value: unknown) => { [k in keyof D]: ObjectReturnType<D[k]>; };
}): (value: unknown) => { [k in NonMatchingKeys<D, {
optional: true;
}>]: ObjectReturnType<D[k]>; } & { [k_1 in MatchingKeys<D, {
optional: true;
}>]?: ObjectReturnType<D[k_1]> | undefined; };
export declare function defaultTo<R>(validator: Validator<R>, _default: R | (() => R)): ObjectOptions<R>;

@@ -17,0 +27,0 @@ export declare function optional<R>(validator: Validator<R>): {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.optional = exports.defaultTo = exports.object = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function object(definition, { allowExcessProperties = false } = {}) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBoolean = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function parseBoolean() {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseDate = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ const isoDateRegex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseJson = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function parseJson() {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseNumber = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function parseNumber() {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.string = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function string({ minLength, maxLength, regex } = {}) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.union = void 0;
const errors_1 = require("./errors");

@@ -4,0 +5,0 @@ function union(...validators) {

{
"name": "fefe",
"version": "2.0.2",
"version": "2.0.3",
"description": "Validate, sanitize and transform values with proper types.",

@@ -11,3 +11,3 @@ "main": "dist/index.js",

"prepublishOnly": "npm run build",
"test": "mocha --opts ./mocha.opts",
"test": "mocha",
"test-cover": "nyc npm test",

@@ -41,15 +41,19 @@ "test-cover-submit": "nyc report --reporter=json && codecov -f coverage/*.json"

"devDependencies": {
"@types/chai": "^4.2.7",
"@types/mocha": "^5.2.7",
"@types/ramda": "^0.26.39",
"@types/chai": "^4.2.13",
"@types/mocha": "^8.0.3",
"@types/ramda": "^0.27.20",
"chai": "^4.2.0",
"codecov": "^3.6.1",
"mocha": "^6.2.2",
"nyc": "^15.0.0",
"ramda": "^0.26.1",
"ts-node": "^8.5.4",
"tslint": "^5.20.1",
"codecov": "^3.8.0",
"mocha": "^8.1.3",
"nyc": "^15.1.0",
"ramda": "^0.27.1",
"ts-node": "^9.0.0",
"tslint": "^6.1.3",
"tslint-config-standard": "^9.0.0",
"typescript": "^3.7.4"
"typescript": "^4.0.3"
},
"mocha": {
"require": "ts-node/register",
"spec": "src/**/*.test.ts"
}
}

@@ -15,5 +15,13 @@ import { FefeError } from './errors'

type ObjectReturnType<T> = T extends ObjectDefinitionValue<infer U>
? U | (T extends {optional: true} ? undefined : never)
? U
: never
type FilterObject<T, C> = { [k in keyof T]: T[k] extends C ? k : never}
type MatchingKeys<T, C> = FilterObject<T, C>[keyof T]
type NotFilterObject<T, C> = { [k in keyof T]: T[k] extends C ? never : k}
type NonMatchingKeys<T, C> = NotFilterObject<T, C>[keyof T]
type MandatoryKeys<D> = NonMatchingKeys<D, {optional: true}>
type OptionalKeys<D> = MatchingKeys<D, {optional: true}>
export function object<D extends ObjectDefinition> (

@@ -40,4 +48,6 @@ definition: D,

const validated = {} as {[k in keyof D]: ObjectReturnType<D[k]>}
Object.entries(definition).forEach(([key, definitionValue]: [keyof D, ObjectDefinitionValue<any>]) => {
const validated = {} as
{ [k in MandatoryKeys<D>]: ObjectReturnType<D[k]> } &
{ [k in OptionalKeys<D>]?: ObjectReturnType<D[k]> }
Object.entries(definition).forEach(([key, definitionValue]: [string, ObjectDefinitionValue<any>]) => {
const options: ObjectOptions<any> = typeof definitionValue === 'object' ?

@@ -52,3 +62,3 @@ definitionValue :

if (options.default !== undefined) {
validated[key] = typeof options.default === 'function' ? options.default() : options.default
validated[key as keyof typeof validated] = typeof options.default === 'function' ? options.default() : options.default
return

@@ -62,3 +72,3 @@ }

try {
validated[key] = options.validator(currentValue)
validated[key as keyof typeof validated] = options.validator(currentValue)
} catch (error) {

@@ -65,0 +75,0 @@ if (error instanceof FefeError) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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