All Projects → apiaryio → Drafter.js

apiaryio / Drafter.js

Licence: mit
API Blueprint parser in JS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Drafter.js

Pki.js
PKI.js is a pure JavaScript library implementing the formats that are used in PKI applications (signing, encryption, certificate requests, OCSP and TSP requests/responses). It is built on WebCrypto (Web Cryptography API) and requires no plug-ins.
Stars: ✭ 960 (+1820%)
Mutual labels:  javascript-library
React Native Heic Converter
Convert your HEIC files with React Native
Stars: ✭ 43 (-14%)
Mutual labels:  javascript-library
Simpletones.js
The goal of simpleTones.js is to provide every JavaScript developer with a lightweight solution for creating custom sounds in their web applications. This documentation has been written in hopes that the least experienced developer can read, understand and go on to do great things. You can check out several examples at this link:
Stars: ✭ 45 (-10%)
Mutual labels:  javascript-library
Byte Size
Isomorphic function to convert a bytes value (e.g. 3456) to a human-readable string ('3.5 kB')
Stars: ✭ 33 (-34%)
Mutual labels:  javascript-library
Minisauras
An open-source CI/CD automation tool based on GitHub Actions that pulls all the JavaScript and CSS files from your base branch, minify them and creates a pull-request with a new branch.
Stars: ✭ 40 (-20%)
Mutual labels:  javascript-library
Apidocs
API documentation for The Grid
Stars: ✭ 43 (-14%)
Mutual labels:  api-blueprint
Zumly
Zumly is a JS library for building zooming user interfaces
Stars: ✭ 22 (-56%)
Mutual labels:  javascript-library
Chroma.js
JavaScript library for all kinds of color manipulations
Stars: ✭ 8,364 (+16628%)
Mutual labels:  javascript-library
Redash
Tiny functional programming suite for JavaScript.
Stars: ✭ 40 (-20%)
Mutual labels:  javascript-library
Filepond Boilerplate Php
🔥 A FilePond PHP project starter kit
Stars: ✭ 45 (-10%)
Mutual labels:  javascript-library
Pmtoapib
Tool to convert Postman collection exports to Api Blueprint documentation
Stars: ✭ 34 (-32%)
Mutual labels:  api-blueprint
Svg World Map
🗺 A JavaScript library to easily integrate one or more SVG world maps with all nations (countries) and second-level political subdivisions (countries, provinces, states).
Stars: ✭ 38 (-24%)
Mutual labels:  javascript-library
Apib Mode
Emacs API Blueprint major mode
Stars: ✭ 44 (-12%)
Mutual labels:  api-blueprint
React Equalizer
Pure React Match Height Component
Stars: ✭ 32 (-36%)
Mutual labels:  javascript-library
Angular Tree Component
A simple yet powerful tree component for Angular (>=2)
Stars: ✭ 1,031 (+1962%)
Mutual labels:  javascript-library
Js Proxy Deep
A proxy API for deeply nested JavaScript objects
Stars: ✭ 29 (-42%)
Mutual labels:  javascript-library
Vue Prism
Simple Vue.js Syntax highlighting with Prism.js
Stars: ✭ 43 (-14%)
Mutual labels:  javascript-library
Flowy
The minimal javascript library to create flowcharts ✨
Stars: ✭ 8,636 (+17172%)
Mutual labels:  javascript-library
Adder
Executing untrusted code with ease.
Stars: ✭ 45 (-10%)
Mutual labels:  javascript-library
Ansi Escape Sequences
A simple, isomorphic library containing all known terminal ansi escape codes and sequences.
Stars: ✭ 44 (-12%)
Mutual labels:  javascript-library

logo

drafter.js Circle CI

Snowcrash parser harness

drafter.js is a pure JavaScript version of the drafter library. It is built from the C++ sources using emscripten. It's API compatible with Protagonist, the Drafter Node binding.

Installation

drafter.js can be installed from NPM, or it can be downloaded from the releases page.

NOTE: If you're using Node, we recommend that you use the Drafter NPM package instead of drafter.js directly. Drafter NPM will attempt to install the pure C++ parser and fallback to using drafter.js.

$ npm install drafter.js

Usage

Node

If you've installed drafter.js via NPM and using drafter.js in Node, you can require it via:

var drafter = require('drafter.js')

Node versions supported: >=4

It works on 0.10 or 0.12 too but without any guarantees and expect it to be significantly slower.

Web Browser

If instead, you are using drafter.js in a Browser. You can include it via the HTML script tag.

<script src="./drafter.js"></script>
<script src="./drafter.js.mem"></script>

API

Once you've included drafter.js, you can parse an API Blueprint:

var res = drafter.parse('# API Blueprint...', {generateSourceMap: true}, function (err, res) {
    if (err) {
        console.log(err)
    }
    console.log(res);
});

Supported options:

  • generateSourceMap: Set to export sourcemap information.
  • json: Set to false to disable parsing of the JSON data. You will instead get a JSON string as the result.
  • requireBlueprintName: Set to generate an error if the blueprint is missing a title.
  • generateMessageBody - Enable generation of messageBody from MSON (default: true)
  • generateMessageBodySchema - Enable generation of messageBodySchema from MSON (default: true)

Or if you want just to validate it and are interested only in parsing errors and warnings:

var res = drafter.validate('# API Blueprint...', {requireBlueprintname: true}, function (err, res) {
    if (err) {
        console.log(err)
    }

    if (res) {
        console.log("Document has semantic issues!");
        console.log(res);
    } else {
        console.log("Document is valid with no warnings.");
    }
});

Supported options:

  • json: Set to false to disable parsing of the JSON data. You will instead get a JSON string as the result.
  • requireBlueprintName: Set to generate an error if the blueprint is missing a title.

Note

These are not a real async API calls - their presence is merely for API compatibility with protagonist

Synchronous API

Both functions have their synchronous counterpart which instead of callback return the result and in case of error throw exception.

  • parseSync(source, options)
  • validateSync(source, options)

Build drafter.js

Unfortunately building drafter.js works only on a *nix environment at the moment.

  1. Building is easy using Docker.

  2. Build

    $ ./scripts/wrap.js
    $ docker pull "apiaryio/emcc:1.37"
    $ docker run -v $(pwd):/src -t apiaryio/emcc:1.37 emcc/emcbuild.sh
    

    or with npm

    $ npm run build
    
  3. Check out the ./scripts/test.js and ./scripts/test.html files for example usage. You can also use npm install and then npm test to run the tests.

The resulting stand-alone library drafter.js is in the ./lib directory. Don't forget to serve the drafter.js.mem file as it is required by drafter.js. There is also a single-file version in drafter.nomem.js that can be used, but it may take longer to load in a web browser environment. It is the default for node.js enviroment.

To get a debug version or version enabled to be used with emrun run the emcbuild.sh script it with -d or -e respectively.

Squeeze the size

If you want to squeeze the size to a minimum install uglify-js and try running uglifyjs lib/drafter.js -o drafter.js -c;, this will use uglify-js with compression, beware that this might cause some errors, if you encounter them try drafter.js without it to verify that it is caused by uglify-js and report it please.

License

MIT License. See the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].