Custom Types with Archetype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Archetype = require('archetype'); | |
// `Str` is a utility type for strings unrelated | |
// to archetype: https://www.npmjs.com/package/string | |
// It provides several convenient string utilities, | |
// including `.capitalize()`. | |
const Str = require('string'); | |
const NameType = new Archetype({ | |
// Archetype custom types are trivial: any function, | |
// including any class, is a viable `$type`. | |
first: { $type: Str }, | |
last: { $type: Str } | |
}).compile('NameType'); | |
const { first, last } = new NameType({ first: 'hello', last: 'world' }); | |
// "Hello World" | |
console.log(first.capitalize().toString(), last.capitalize().toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment