Skip to content

Instantly share code, notes, and snippets.

@vkarpov15
Last active October 28, 2017 08:16
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Custom Types with Archetype
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