3.0.2 • Published 2 years ago

@leismore/jsonify_function v3.0.2

Weekly downloads
4
License
AGPL-3.0-only
Repository
github
Last release
2 years ago

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)