Skip to content

maryrosecook/stamplet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Stamplet

Stamplet's job is to take a piece of specially-templatted json like this:

{
  "users{{repeat(3)}}":[
    { "someString": "{{ randomString }}" }
  ]
}

and return this:

{
  "users":[
    { someString: "alske" },
    { someString: "bfkdt" },
    { someString: "qlcys" },
  ]
}

Templates

Templates use a double curly bracket syntax like Mustache or Handlerbars. When stamplet sees an embedded template, it looks up a generator or interpolater function with that name and then calls that funciton to transform the json.

Genenerators and Interpolators

In short, generators operate on overall structure and are found in the keys of a json object. Interpolaters fill in the values at the "leaves" of a structure and are embedded in the values of an object.

Customization

Stamplet is designed to be extended with custom generators and interpolaters:

stamplet.addGenerator('myGenerator', function(node){
  // return the new object or array
});

stamplet.addInterpolater('myInterpolater', function(value){
  // return new value
});

Installation

git clone https://github.com/tjlahr/stamplet.git
cd stamplet
npm install

Running Examples

node example.js

Running Tests

npm test

Generating Documentation

docco script/*.js (html documentation will be exported to docs)

About

fake json generator

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%