JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q48690F
  • License ISC

A lightweight module to simplify the process of generating pretty strings of code

Package Exports

  • rapunzel

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rapunzel) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

rapunzel [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]

This lightweight module simplifies the process of generating code strings

Install

$ npm install --save rapunzel

Usage

var rapunzel = require('rapunzel');

var h_obj = {
    "example":
    {
        "of": "stringifying a simple object",
        "that": "only has objects and strings",
    }
};

var stringify_obj = function(add, h_part) {
    if('string' === typeof h_part) {
        add("'"+h_part.replace(/'/g, "\\'")+"'", true);
    }
    else {
        add.open('{', ',', true);
        for(var s_property in h_part) {
            add(s_property+': ');
            stringify_obj(add, h_part[s_property]);
        }
        add.close('}');
    }
};

var k_builder = rapunzel({
    preamble: function(add) {
        add('// this is the beginning');
    },
    body: function(add) {
        stringify_obj(add, h_obj);
    },
    closing: function(add) {
        add('// this is the end');
    },
});

k_builder.produce({
    indent: '\t',
});

yields:

// this is the beginning
{
    example: {
        of: 'stringifying a simple object',
        that: 'only has objects and strings',
    },
}
// this is the end

License

ISC © Blake Regalia