@leismore/jsonify_function
Version:
Convert a JavaScript function into a stringified JSON string.
51 lines (31 loc) • 1.3 kB
Markdown
Convert a JavaScript function into a stringified JSON string.
Buy me a coffee via [](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SPPJPYRY4D6WC&item_name=Give+people+an+option+to+support+my+open+source+software.¤cy_code=AUD&source=url)
[](http://couchdb.apache.org) 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}"
}
```
[](http://couchdb.apache.org) itself does not provide a tool for convert JavaScript functions to the JSON structure. So I wrote this simple command-line converter.
`npm install @leismore/jsonify_function`
`npm test`
```typescript
import {jsonify_function} from '@leismore/jsonify_function';
// Define your function here
function test()
{
console.log('test');
}
// Output
console.log( jsonify_function(test) );
```
GNU Affero General Public License v3.0
[](https://www.kylechine.name) (Initial Author)