An open API service indexing awesome lists of open source software.

https://github.com/electerious/rosid-handler-node

Load JS and transform to HTML.
https://github.com/electerious/rosid-handler-node

html js node transpiler

Last synced: about 1 year ago
JSON representation

Load JS and transform to HTML.

Awesome Lists containing this project

README

          

# rosid-handler-node

[![Travis Build Status](https://travis-ci.org/electerious/rosid-handler-node.svg?branch=master)](https://travis-ci.org/electerious/rosid-handler-node) [![Coverage Status](https://coveralls.io/repos/github/electerious/rosid-handler-node/badge.svg?branch=master)](https://coveralls.io/github/electerious/rosid-handler-node?branch=master) [![Dependencies](https://david-dm.org/electerious/rosid-handler-node.svg)](https://david-dm.org/electerious/rosid-handler-node#info=dependencies) [![Greenkeeper badge](https://badges.greenkeeper.io/electerious/rosid-handler-node.svg)](https://greenkeeper.io/)

A function that loads a JS file and transforms it to HTML by executing the exported default function. The export function can either be a asynchronous callback function or a async function returning a Promise.

## Install

```
npm install rosid-handler-node
```

## Usage

### API

```js
const handler = require('rosid-handler-node')

handler('index.js').then((data) => {})
handler('index.html').then((data) => {})
```

### Rosid

Add the following object to your `rosidfile.json`, `rosidfile.js` or [routes array](https://github.com/electerious/Rosid/blob/master/docs/Routes.md). `rosid-handler-node` will execute all matching JS files in your source folder and save the output as static HTML.

```json
{
"name" : "Node",
"path" : "[^_]*.{html,js}*",
"handler" : "rosid-handler-node"
}
```

```js
// index.js

// Works with asynchronous callback functions
export default (next) => next(null, '

Hello World

')
// or async functions
export default async () => await '

Hello World

'
```

```html

Hello World


```

## Parameters

- `filePath` `{String}` Absolute path to file.

## Returns

- `{Promise}` The transformed file content.