Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Merge fe555e0 into b5c4a85
Browse files Browse the repository at this point in the history
  • Loading branch information
ktutnik committed Nov 20, 2019
2 parents b5c4a85 + fe555e0 commit 6e73e24
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ function dateConverter(rawValue: {}) {
return isNaN(stamp) ? undefined : new Date(stamp)
}

function stringConverter(rawValue: {}) {
return safeToString(rawValue)
}

const defaultConverters = new Map<Class, Converter>([
[Boolean, booleanConverter],
[Date, dateConverter],
[Number, numberConverter]
[Number, numberConverter],
[String, stringConverter]
])

export { defaultConverters, Converter, safeToString }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions test/converter-string.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import createConverter from "../src"

const convert = createConverter({ type: String })

describe("String Converter", () => {

it("Should convert string", () => {
const result = convert("123")
expect(result.value).toBe("123")
})

it("Should convert number", () => {
const result = convert(123)
expect(result.value).toBe("123")
})

it("Should convert boolean", () => {
const result = convert(false)
expect(result.value).toBe("false")
})
})

0 comments on commit 6e73e24

Please sign in to comment.