diff --git a/README.md b/README.md index 7dd861b..7c403f0 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,12 @@ reviveFunctionsInObjectCurried(options)(jsonLikeObject)(data) ``` * `options` is an object with three keys: - * `functions` is an object containing key value pairs of function names and function bodies. Defaults to `{}` + * `functions` is an object containing key value pairs of function names and function bodies. Defaults to `{}`. It can be useful to pass selected functions from libraries such as Ramda or lodash/fp. * `addFunctionTag` is a function which, given a function name (e.g. `get`), returns a function tag (e.g. `$get`). Defaults to `name=>"$"+name`, i.e. using "$" as a function tag. * `stringifyFirst`: for `reviveFunctionsInObject` and `reviveFunctionsInObjectCurried`, allows explicit determination of whether to run `JSON.stringify` on the input value, before passing to `JSON.parse`. Defaults to `undefined`, meaning this is done on objects only. * `data` an optional Javascript value to be passed as a curried last argument to `functions` -* `jsonLikeObject` is a JSON-like Javascript structure, or a string containing valid JSON, in objects containing function specifications like `{$functionname: [param1, param2, ...]}` will be substituted with the result of calling the function with the specified parameters (and, optionally, the data object, applied as a last, curried argument). If only one parameter is needed, the array can be omitted (e.g. `{$functionname: param1}`). Parameters can be generated recursively, from nested function calls (see examples below). -* `jsonString` is a string as would normally be passed to JSON.parse +* `jsonLikeObject` is a JSON-like Javascript structure, or a string containing valid JSON, in which objects containing function specifications like `{$functionname: [param1, param2, ...]}` will be substituted with the result of calling the function with the specified parameters (and, optionally, the data object, applied as a last, curried argument). If only one parameter is needed, the array can be omitted (e.g. `{$functionname: param1}`). Parameters can be generated recursively, from nested function calls (see examples below). The whole JSON-like tree is parsed. Items which are not recognised as function specifications are passed through unchanged, as per normal `JSON.parse` behaviour. +* `jsonString` is a string as would normally be passed to `JSON.parse` ## Examples @@ -59,7 +59,7 @@ const res2 = reviveFunctionsInObject({ addFunctionTag: f => 'fn::' + f, }, { - sum: {"fn::add": [2,{"fn::get": "test"}] }, + sum: {"fn::add": [2, {"fn::get": "test"}] }, unchanged: "other values get passed through" }, {test: 42} @@ -91,4 +91,6 @@ const res3 = data.map(reviver); See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse for details of `JSON.parse` and its reviver function parameter. -See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html for an example of this kind of substitution being used in Amazon Web Services (AWS) Cloudformation. \ No newline at end of file +See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html for an example of this kind of substitution being used in Amazon Web Services (AWS) Cloudformation. + +NPM: https://www.npmjs.com/package/revive-functions \ No newline at end of file