Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including tailorr with all npm packages installed. Try it out:

var tailorr = require("tailorr")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

tailorr v2.1.0

Conform a data object to a pre-defined pattern/model, trimming all extraneous keys


Conform a data object to a pre-defined pattern/model, trimming all extraneous keys

Motivated by GoLang Marshall


Install the package

$ npm install tailorr

trim(input, model [, options])

  • input is the object desired to be trimmed
  • model is the object that describes the pattern you'd like to trim to
  • options is an optional third argument that currently takes in one key, strict. If strict is true or options are null, then type strictness will be applied, otherwise key value pairs that don't match type won't be populated.

This method will return a new object with all of the keys of the model with the values populated from the input object, effectively trimming the input into the model.

If the input object does not contain the corresponding model key or the types do not match (assuming strict), the value in the return object will be set to null


  const tailorr = require('tailorr')

  const input = {
    a: {
      b: 'blah'
    c: 'testing'

  const model = {
    a: '',
    c: ''

  const options = {
    strict: true

  const populated = tailorr.trim(input, model, options)
  // returns { a: null, c: 'testing' }




RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free