Skip to content

leismore/jsonify_function

Repository files navigation

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)

About

Convert a JavaScript function into stringified JSON.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •