Skip to content

Commit

Permalink
Stringify async function (#97)
Browse files Browse the repository at this point in the history
* fix the stringify function so it doesn't blank out [object AsyncFunction]

* bump ver 0.1.50
  • Loading branch information
geoffhendrey authored Jan 15, 2025
1 parent 4b50653 commit 36f6d4c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stated-js",
"version": "0.1.49",
"version": "0.1.50",
"license": "Apache-2.0",
"description": "JSONata embedded in JSON",
"main": "./dist/src/index.js",
Expand Down
17 changes: 17 additions & 0 deletions src/test/TemplateProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5694,6 +5694,23 @@ test("test import with props", async () => {
}
});

test("test async function stringifyy", async () => {
const foo = async function(){
return 'bar';
};

const o = {
a:42,
b: foo
};
expect(JSON.parse(stringifyTemplateJSON(o))).toStrictEqual({
a:42,
b: "{function:}"
})
});






2 changes: 1 addition & 1 deletion src/utils/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const circularReplacer = (key: any, value: any) => {
if (tag === '[object Timeout]'|| (_idleTimeout !== undefined && _onTimeout !== undefined)) { //Node.js
return "--interval/timeout--";
}
if (tag === '[object Function]') {
if (tag === '[object Function]' || tag==='[object AsyncFunction]') {
return "{function:}";
}
// Check if value is a module-like object
Expand Down

0 comments on commit 36f6d4c

Please sign in to comment.