Skip to content

Instantly share code, notes, and snippets.

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
What would you like to do?
Custom Types with Archetype
const Archetype = require('archetype');
// `Str` is a utility type for strings unrelated
// to archetype:
// 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 }
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