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 0.9.8-rc to 0.9.8

7

CHANGELOG.md

@@ -16,2 +16,9 @@ # Changelog

# 0.9.8
* **New Feature**
* add decode and deprecate top level validate (@gcanti)
* **Internal**
* when checking validations use methods instead of top level functions (@gcanti)
# 0.9.7

@@ -18,0 +25,0 @@

6

lib/index.d.ts

@@ -36,4 +36,4 @@ import { Either } from 'fp-ts/lib/Either';

* Laws:
* 1. validate(x, T).fold(() => x, T.serialize) = x
* 2. validate(T.serialize(x), T) = Right(x)
* 1. T.decode(x).fold(() => x, T.serialize) = x
* 2. T.decode(T.serialize(x)) = right(x)
*

@@ -65,3 +65,3 @@ * where `T` is a runtime type

asEncoder(): Encoder<S, A>;
/** succeeds if a value of type S can be decoded to a value of type A */
/** a version of `validate` with a default context */
decode(s: S): Validation<A>;

@@ -68,0 +68,0 @@ }

@@ -24,4 +24,4 @@ "use strict";

* Laws:
* 1. validate(x, T).fold(() => x, T.serialize) = x
* 2. validate(T.serialize(x), T) = Right(x)
* 1. T.decode(x).fold(() => x, T.serialize) = x
* 2. T.decode(T.serialize(x)) = right(x)
*

@@ -57,3 +57,3 @@ * where `T` is a runtime type

};
/** succeeds if a value of type S can be decoded to a value of type A */
/** a version of `validate` with a default context */
Type.prototype.decode = function (s) {

@@ -60,0 +60,0 @@ return this.validate(s, exports.getDefaultContext(this));

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

@@ -12,3 +12,3 @@ "files": ["lib"],

"typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts",
"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts",
"mocha": "mocha -r ts-node/register test/*.ts",
"prettier":

@@ -38,3 +38,3 @@ "prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test}/**/*.ts\"",

"dependencies": {
"fp-ts": "^1.0.0-rc"
"fp-ts": "^0.6.4"
},

@@ -41,0 +41,0 @@ "devDependencies": {

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

* decode inputs (through `validate`)
* decode inputs (through `decode`)
* encode outputs (through `serialize`)

@@ -32,2 +32,4 @@ * be used as a custom type guard (through `is`)

) {}
/** a version of `validate` with a default context */
decode(s: S): Either<Errors, A>
}

@@ -67,6 +69,6 @@ ```

// ok
t.validate(JSON.parse('{"name":"Giulio","age":43}'), Person) // => Right({name: "Giulio", age: 43})
Person.decode(JSON.parse('{"name":"Giulio","age":43}')) // => Right({name: "Giulio", age: 43})
// ko
t.validate(JSON.parse('{"name":"Giulio"}'), Person) // => Left([...])
Person.decode(JSON.parse('{"name":"Giulio"}')) // => Left([...])
```

@@ -95,8 +97,8 @@

const validation = t.validate({ name: 'Giulio' }, Person)
const result = Person.decode({ name: 'Giulio' })
console.log(PathReporter.report(validation))
console.log(PathReporter.report(result))
// => ['Invalid value undefined supplied to : { name: string, age: number }/age: number']
ThrowReporter.report(validation)
ThrowReporter.report(result)
// => throws 'Invalid value undefined supplied to : { name: string, age: number }/age: number'

@@ -238,4 +240,4 @@ ```

t.validate({ name: 'Giulio', age: 43, surname: 'Canti' }, Person) // ok
t.validate({ name: 'Giulio', age: 43, surname: 'Canti' }, StrictPerson) // fails
Person.decode({ name: 'Giulio', age: 43, surname: 'Canti' }) // ok
StrictPerson.decode({ name: 'Giulio', age: 43, surname: 'Canti' }) // fails
```

@@ -305,6 +307,6 @@

t.validate(s, DateFromString)
DateFromString.decode(s)
// right(new Date('1973-11-29T23:00:00.000Z'))
t.validate('foo', DateFromString)
DateFromString.decode('foo')
// left(errors...)

@@ -375,3 +377,3 @@ ```

if (NODE_ENV !== 'production') {
return t.validate(value, type).getOrElse(errors => {
return type.decode(value).getOrElse(errors => {
throw new Error(failure(errors).join('\n'))

@@ -378,0 +380,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