Socket
Socket
Sign inDemoInstall

io-ts

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-ts - npm Package Compare versions

Comparing version 1.8.1 to 1.8.2

5

CHANGELOG.md

@@ -17,2 +17,7 @@ # Changelog

# 1.8.2
- **Bug Fix**
- align the runtime behavior of `Exact.is` with the type system, fix #288 (@gcanti)
# 1.8.1

@@ -19,0 +24,0 @@

10

lib/index.d.ts

@@ -6,6 +6,2 @@ import { Either } from 'fp-ts/lib/Either';

*/
export declare type mixed = unknown;
/**
* @since 1.0.0
*/
export interface ContextEntry {

@@ -726,5 +722,11 @@ readonly key: string;

/**
* Use `unknown` instead
* @since 1.0.0
* @deprecated
*/
export declare type mixed = unknown;
/**
* @since 1.0.0
* @deprecated
*/
export declare const getValidationError: (value: unknown, context: Context) => ValidationError;

@@ -731,0 +733,0 @@ /**

18

lib/index.js

@@ -786,9 +786,8 @@ "use strict";

: function (a) {
for (var i = 0; i < len - 1; i++) {
var type_4 = codecs[i];
if (type_4.is(a)) {
return type_4.encode(a);
for (var i = 0; i < len; i++) {
var codec = codecs[i];
if (codec.is(a)) {
return codec.encode(a);
}
}
return a;
}, codecs);

@@ -878,4 +877,4 @@ };

var a = us[i];
var type_5 = codecs[i];
var validation = type_5.validate(a, exports.appendContext(c, String(i), type_5, a));
var type_4 = codecs[i];
var validation = type_4.validate(a, exports.appendContext(c, String(i), type_4, a));
if (validation.isLeft()) {

@@ -1223,3 +1222,3 @@ pushAll(errors, validation.value);

var props = getProps(codec);
return new ExactType(name, function (u) { return codec.is(u) && Object.getOwnPropertyNames(u).every(function (k) { return hasOwnProperty.call(props, k); }); }, function (u, c) {
return new ExactType(name, codec.is, function (u, c) {
var unknownRecordValidation = exports.UnknownRecord.validate(u, c);

@@ -1236,5 +1235,2 @@ if (unknownRecordValidation.isLeft()) {

};
//
// deprecations
//
/**

@@ -1241,0 +1237,0 @@ * @since 1.0.0

{
"name": "io-ts",
"version": "1.8.1",
"version": "1.8.2",
"description": "TypeScript compatible runtime type system for IO validation",

@@ -5,0 +5,0 @@ "files": [

@@ -61,12 +61,14 @@ [![build status](https://img.shields.io/travis/gcanti/io-ts/master.svg?style=flat-square)](https://travis-ci.org/gcanti/io-ts)

```ts
const Person = t.type({
name: t.string,
age: t.number
import * as t from 'io-ts'
const User = t.type({
userId: t.number,
name: t.string
})
// validation succeeded
Person.decode(JSON.parse('{"name":"Giulio","age":43}')) // => Right({name: "Giulio", age: 43})
User.decode(JSON.parse('{"userId":1,"name":"Giulio"}')) // => Right({ userId: 1, name: "Giulio" })
// validation failed
Person.decode(JSON.parse('{"name":"Giulio"}')) // => Left([...])
User.decode(JSON.parse('{"name":"Giulio"}')) // => Left([...])
```

@@ -105,6 +107,6 @@

const result = Person.decode({ name: 'Giulio' })
const result = User.decode({ name: 'Giulio' })
console.log(PathReporter.report(result))
// => ['Invalid value undefined supplied to : { name: string, age: number }/age: number']
// => [ 'Invalid value undefined supplied to : { userId: number, name: string }/userId: number' ]
```

@@ -133,4 +135,2 @@

```ts
import * as t from 'io-ts'
const getPaths = <A>(v: t.Validation<A>): Array<string> => {

@@ -140,8 +140,3 @@ return v.fold(errors => errors.map(error => error.context.map(({ key }) => key).join('.')), () => ['no errors'])

const Person = t.type({
name: t.string,
age: t.number
})
console.log(getPaths(Person.decode({}))) // => [ '.name', '.age' ]
console.log(getPaths(User.decode({}))) // => [ '.userId', '.name' ]
```

@@ -192,3 +187,3 @@

Note that the type annotation isn't needed, TypeScript infers the type automatically based on a schema.
Note that the type annotation isn't needed, TypeScript infers the type automatically based on a schema (and comments are preserved).

@@ -198,8 +193,8 @@ Static types can be extracted from codecs using the `TypeOf` operator

```ts
type Person = t.TypeOf<typeof Person>
type User = t.TypeOf<typeof User>
// same as
type Person = {
type User = {
userId: number
name: string
age: number
}

@@ -210,6 +205,2 @@ ```

```ts
import * as t from 'io-ts'
```
| Type | TypeScript | codec / combinator |

@@ -355,11 +346,6 @@ | --------------------------- | --------------------------- | -------------------------------------------------------------------- |

```ts
const Person = t.type({
name: t.string,
age: t.number
})
const ExactUser = t.exact(User)
const ExactPerson = t.exact(Person)
Person.decode({ name: 'Giulio', age: 43, surname: 'Canti' }) // ok, result is right({ name: 'Giulio', age: 43, surname: 'Canti' })
ExactPerson.decode({ name: 'Giulio', age: 43, surname: 'Canti' }) // ok but result is right({ name: 'Giulio', age: 43 })
User.decode({ userId: 1, name: 'Giulio', age: 45 }) // ok, result is right({ userId: 1, name: 'Giulio', age: 45 })
ExactUser.decode({ userId: 1, name: 'Giulio', age: 43 }) // ok but result is right({ userId: 1, name: 'Giulio' })
```

@@ -395,13 +381,8 @@

```ts
const Person = t.type({
name: t.string,
age: t.number
})
const PartialUser = t.partial(User.props)
const PartialPerson = t.partial(Person.props)
type PartialUser = t.TypeOf<typeof PartialUser>
type PartialPerson = t.TypeOf<typeof PartialPerson>
// same as
type PartialPerson = {
type PartialUser = {
name?: string

@@ -417,4 +398,2 @@ age?: number

```ts
import * as t from 'io-ts'
// represents a Date from an ISO string

@@ -462,6 +441,4 @@ const DateFromString = new t.Type<Date, string, unknown>(

```ts
import * as t from 'io-ts'
// t.Mixed = t.Type<any, any, unknown>
const ResponseBody = <RT extends t.Mixed>(type: RT) =>
const ResponseBody = <C extends t.Mixed>(codec: C) =>
t.interface({

@@ -493,4 +470,4 @@ result: type,

```ts
const NumberDecoder = new t.Type<number, string, string>(
'NumberDecoder',
const NumberCodec = new t.Type<number, string, string>(
'NumberCodec',
t.number.is,

@@ -505,3 +482,3 @@ (s, c) => {

const NumberFromString = t.string.pipe(
NumberDecoder,
NumberCodec,
'NumberFromString'

@@ -523,5 +500,5 @@ )

export function unsafeDecode<A, O, I>(value: I, type: t.Type<A, O, I>): Either<t.Errors, A> {
if (NODE_ENV !== 'production' || type.encode !== t.identity) {
return type.decode(value)
export function unsafeDecode<A, O, I>(value: I, codec: t.Type<A, O, I>): Either<t.Errors, A> {
if (NODE_ENV !== 'production' || codec.encode !== t.identity) {
return codec.decode(value)
} else {

@@ -537,5 +514,5 @@ // unsafe cast

export function unsafeGet<A, O, I>(value: I, type: t.Type<A, O, I>): A {
export function unsafeGet<A, O, I>(value: I, codec: t.Type<A, O, I>): A {
if (NODE_ENV !== 'production' || type.encode !== t.identity) {
return type.decode(value).getOrElseL(errors => {
return codec.decode(value).getOrElseL(errors => {
throw new Error(failure(errors).join('\n'))

@@ -542,0 +519,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