Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
fix: ensureString parser
Browse files Browse the repository at this point in the history
  • Loading branch information
moltar committed Apr 29, 2021
1 parent e8fccd6 commit 4483f22
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const ensureArray = <T>(tag: string, codec: Codec<T>): Codec<T[]> => {
export const ensureString = Codec.custom({
decode: (x) =>
string.decode(x).chainLeft((error) => (typeof x === 'number' ? Right(String(x)) : Left(error))),
encode: string.encode,
encode: (x: string) => string.encode(x),
schema: () => ({ oneOf: [{ type: 'string' }, { type: 'number' }] }),
})

Expand Down
8 changes: 1 addition & 7 deletions test/unit/parsing.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Ajv from 'ajv'
import { date, number, string } from 'purify-ts/Codec'
import { date, number } from 'purify-ts/Codec'
import { Right } from 'purify-ts/Either'

import {
Expand Down Expand Up @@ -48,12 +48,6 @@ describe('ensureString', () => {
expect(ensureString.decode(5)).toStrictEqual(Right('5'))
})

it('has the same encode as the string codec', () => {
expect.assertions(1)

expect(ensureString.encode).toStrictEqual(string.encode)
})

it('generates a valid JSON schema for a string or number', () => {
expect.assertions(3)

Expand Down

0 comments on commit 4483f22

Please sign in to comment.