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

@gucciogucci/contented

Package Overview
Dependencies
Maintainers
4
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gucciogucci/contented - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

dist/combineIntoObject.d.ts

3

dist/combine.d.ts
import { ContentedError } from './ContentedError';
import { ExpectedType, NonFatalErrorType, Type } from './Type';
import { ErrorType, ExpectedType, NonFatalErrorType, Type } from './Type';
export declare function combine<E extends ContentedError, Ts extends Type<unknown, E>[], O>(fn: (...args: [...ExpectedTypes<Ts>]) => O, ...types: [...Ts]): Type<CombinationOf<Ts, O>, UnionOfErrorTypes<Ts>>;
declare type CombinationOf<Ts, O> = UnionOfNonFatalErrorTypes<Ts> extends never ? O : O | [O, UnionOfNonFatalErrorTypes<Ts>[]];
declare type UnionOfNonFatalErrorTypes<Ts> = NonFatalErrorTypes<Ts>[number];
declare type ErrorType<T> = T extends Type<any, infer E> ? E : never;
declare type ExpectedTypes<Ts> = Ts extends [infer Head, ...infer Tail] ? [ExpectedType<Head>, ...ExpectedTypes<Tail>] : [];

@@ -8,0 +7,0 @@ declare type UnionOfErrorTypes<Ts> = ErrorTypes<Ts>[number];

@@ -6,5 +6,7 @@ export * from './always';

export * from './combine';
export * from './combineIntoObject';
export * from './fallback';
export * from './match';
export * from './number';
export * from './permissiveArrayOf';
export * from './optional';

@@ -11,0 +13,0 @@ export * from './string';

@@ -19,5 +19,7 @@ "use strict";

__exportStar(require("./combine"), exports);
__exportStar(require("./combineIntoObject"), exports);
__exportStar(require("./fallback"), exports);
__exportStar(require("./match"), exports);
__exportStar(require("./number"), exports);
__exportStar(require("./permissiveArrayOf"), exports);
__exportStar(require("./optional"), exports);

@@ -24,0 +26,0 @@ __exportStar(require("./string"), exports);

@@ -15,2 +15,3 @@ import { ContentedError } from './ContentedError';

export declare type ExpectedType<T> = [T] extends [Type<infer A, any>] ? ExpectedType<A> : HasNonFatalErrors<T> extends true ? T extends [infer U, any] ? U : never : T;
export declare type ErrorType<T> = T extends Type<any, infer E> ? E : never;
declare type OrErrors<E, F> = EnumerateErrors<StripJoint<E>, StripJoint<F>> extends never ? never : Joint<EnumerateErrors<StripJoint<E>, StripJoint<F>>>;

@@ -17,0 +18,0 @@ declare type EnumerateErrors<E, F> = E extends never ? never : F extends never ? never : E extends unknown[] ? F extends unknown[] ? [...E, ...F] : [...E, F] : F extends unknown[] ? [E, ...F] : [E, F];

{
"name": "@gucciogucci/contented",
"description": "A library to coerce values at run-time.",
"version": "1.1.0",
"version": "1.2.0",
"author": "Gucci <npm@gucci.com>",

@@ -6,0 +6,0 @@ "license": "LGPL-3.0-only",

@@ -36,2 +36,3 @@ <div align="center">

- [`combine(fn, ...Ts)`](#combinefn-ts)
- [`combineIntoObject({ [...Keys]: [...Ts] })`](#combineintoobject-keys-ts-)
- [`T1.or(T2)`](#t1ort2)

@@ -137,3 +138,3 @@ - [`optional(T)`](#optionalt)

const stringAtAB = at(['a', 'b'], string)
const stringAtAB = at(['a', 'b'], string);

@@ -272,2 +273,31 @@ coerceTo(stringAtAB, { a: { b: 'hello' } });

#### `combineIntoObject({ [...Keys]: [...Ts] })`
`combineIntObject` is a convenience function that may be used every time there is the need of combining some known run-time types `Ts` into an object of known keys. In other words, instead of writing the following:
```typescript
import { string, number, at, combine, coerceTo } from '@gucciogucci/contented';
const Image = combine(
(url, size) => ({ url, size }),
at('url', string),
at(['metadata', 'size'], number)
);
const image = coerceTo(Image, data);
```
One may simply write:
```typescript
import { string, number, at, combineIntoObject, coerceTo } from '@gucciogucci/contented';
const Image = combineIntoObject({
url: at('url', string),
size: at(['metadata', 'size'], number)
});
const image = coerceTo(Image, data);
```
#### `T1.or(T2)`

@@ -274,0 +304,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