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.
- Host: GitHub
- URL: https://github.com/electerious/rosid-handler-node
- Owner: electerious
- License: mit
- Created: 2016-12-09T16:27:29.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-08T15:52:04.000Z (over 4 years ago)
- Last Synced: 2025-04-18T06:42:55.355Z (about 1 year ago)
- Topics: html, js, node, transpiler
- Language: JavaScript
- Size: 61.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rosid-handler-node
[](https://travis-ci.org/electerious/rosid-handler-node) [](https://coveralls.io/github/electerious/rosid-handler-node?branch=master) [](https://david-dm.org/electerious/rosid-handler-node#info=dependencies) [](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.