npm.io
3.0.2 • Published 4 years ago

@leismore/jsonify_function

Licence
AGPL-3.0-only
Version
3.0.2
Deps
0
Size
37 kB
Vulns
0
Weekly
0
Stars
1

jsonify_function

Convert a JavaScript function into a stringified JSON string.

Donation

Buy me a coffee via PayPal Donation

Motivation

CouchDB design document architecture requires that all database handlers (JavaScript functions) are stored in a JSON structure. Functions in the JSON structure must be presented as escaped stringified strings. Similar as this:

{
  "updatefun": "function test(a)\n{\n  console.log('test');\n}"
}

CouchDB itself does not provide a tool for convert JavaScript functions to the JSON structure. So I wrote this simple command-line converter.

Installation

npm install @leismore/jsonify_function

Test

npm test

Usage

import {jsonify_function} from '@leismore/jsonify_function';

// Define your function here
function test()
{
  console.log('test');
}

// Output
console.log( jsonify_function(test) );

License

GNU Affero General Public License v3.0

Authors

Kyle Chine (Initial Author)

Keywords