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 3.0.0-beta.4 to 3.0.0

dist/map-object-keys.d.ts

3

dist/boolean.d.ts

@@ -0,2 +1,3 @@

import { LeafError } from './errors';
import { Validator } from './transformer';
export declare function boolean(): Validator<boolean>;
export declare function boolean(): Validator<boolean, LeafError>;

@@ -0,1 +1,2 @@

import { LeafError } from './errors';
import { Validator } from './transformer';

@@ -6,2 +7,2 @@ export interface DateOptions {

}
export declare function date({ min, max }?: DateOptions): Validator<Date>;
export declare function date({ min, max }?: DateOptions): Validator<Date, LeafError>;

@@ -0,2 +1,3 @@

import { LeafError } from './errors';
import { Validator } from './transformer';
export declare function enumerate<T extends (string | number)[]>(...args: T): Validator<T[number]>;
export declare function enumerate<T extends (string | number)[]>(...args: T): Validator<T[number], LeafError>;

@@ -9,2 +9,3 @@ export * from './errors';

export * from './enumerate';
export * from './map-object-keys';
export * from './number';

@@ -11,0 +12,0 @@ export * from './object';

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

__exportStar(require("./enumerate"), exports);
__exportStar(require("./map-object-keys"), exports);
__exportStar(require("./number"), exports);

@@ -23,0 +24,0 @@ __exportStar(require("./object"), exports);

@@ -0,1 +1,2 @@

import { LeafError } from './errors';
import { Validator } from './transformer';

@@ -9,2 +10,2 @@ export interface NumberOptions {

}
export declare function number({ min, max, integer, allowNaN, allowInfinity, }?: NumberOptions): Validator<number>;
export declare function number({ min, max, integer, allowNaN, allowInfinity, }?: NumberOptions): Validator<number, LeafError>;

@@ -0,2 +1,3 @@

import { LeafError } from './errors';
import { Transformer } from './transformer';
export declare function parseBoolean(): Transformer<string, boolean>;
export declare function parseBoolean(): Transformer<string, boolean, LeafError>;

@@ -0,4 +1,5 @@

import { LeafError } from './errors';
import { Transformer } from './transformer';
export declare function parseDate({ iso }?: {
iso?: boolean;
}): Transformer<string, Date>;
}): Transformer<string, Date, LeafError>;

@@ -0,2 +1,3 @@

import { LeafError } from './errors';
import { Transformer } from './transformer';
export declare function parseJson(): Transformer<string, unknown>;
export declare function parseJson(): Transformer<string, unknown, LeafError>;

@@ -0,2 +1,3 @@

import { LeafError } from './errors';
import { Transformer } from './transformer';
export declare function parseNumber(): Transformer<string, number>;
export declare function parseNumber(): Transformer<string, number, LeafError>;
import { Either } from 'fp-ts/lib/Either';
import { FefeError } from './errors';
export declare type Result<T> = Either<FefeError, T>;
export declare const success: <T>(value: T) => Result<T>;
export declare type Result<T, E extends FefeError = FefeError> = Either<E, T>;
export declare const success: <T>(value: T) => Result<T, never>;
export declare const isSuccess: <E, A>(ma: Either<E, A>) => ma is import("fp-ts/lib/Either").Right<A>;
export declare const failure: (error: FefeError) => Result<never>;
export declare const failure: <E extends FefeError>(error: E) => Result<never, E>;
export declare const isFailure: <E, A>(ma: Either<E, A>) => ma is import("fp-ts/lib/Either").Left<E>;

@@ -0,1 +1,2 @@

import { LeafError } from './errors';
import { Validator } from './transformer';

@@ -7,2 +8,2 @@ export interface StringOptions {

}
export declare function string({ minLength, maxLength, regex, }?: StringOptions): Validator<string>;
export declare function string({ minLength, maxLength, regex, }?: StringOptions): Validator<string, LeafError>;

@@ -0,4 +1,5 @@

import { FefeError } from './errors';
import { Result } from './result';
export declare type Transformer<V, T> = (v: V) => Result<T>;
export declare type Validator<T> = Transformer<unknown, T>;
export declare type Transformer<V, T, E extends FefeError = FefeError> = (v: V) => Result<T, E>;
export declare type Validator<T, E extends FefeError = FefeError> = Transformer<unknown, T, E>;
export declare type ValidatorReturnType<T> = T extends Validator<infer U> ? U : never;

@@ -0,2 +1,3 @@

import { LeafError } from './errors';
import { Validator, ValidatorReturnType } from './transformer';
export declare function union<T extends Validator<unknown>[]>(...validators: T): Validator<ValidatorReturnType<T[number]>>;
export declare function union<T extends Validator<unknown>[]>(...validators: T): Validator<ValidatorReturnType<T[number]>, LeafError>;
{
"name": "fefe",
"version": "3.0.0-beta.4",
"version": "3.0.0",
"description": "Validate, sanitize and transform values with proper types.",

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

@@ -23,4 +23,2 @@ # fefe

The
### 🔎 Validation example

@@ -148,2 +146,3 @@

For simplifying the transition from a 2.x codebase you can use the `toThrow(t: Transformer<V, T>)` function that returns a funtion `(v: V) => T` that returns the value directly and throws instead of returning a `FefeError` in the case of an error. Note that the thrown `FefeThrowError` has a different structure than the pre-3.x `FefeError`.

@@ -230,2 +229,25 @@

### `mapObjectKeys(map): Transformer<S, T>`
Returns a transformer that takes the input object and returns a new object with the keys of `map`. For each key `k` the resulting object's value is the value for the key `map[k]` of the input object.
Options:
* `map: Record<string, keyof S>`: maps output object keys to input object keys.
This function is very useful in combination with `object()`:
```typescript
const validateEnv = pipe(
object({
FOO: string(),
BAR: optional(pipe(string()).pipe(parseNumber())),
})
)
.pipe(mapObjectKeys({ foo: 'FOO', bar: 'BAR' }))
const result = validatEnv({ FOO: 'str', BAR: '1337' })
```
Then `isSuccess(result)` will be `true` and `result.right` equals to `{ foo: 'str', bar: 1337 }`.
### `number(options?): Validator<number>`

@@ -232,0 +254,0 @@

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