Skip to content

Commit

Permalink
fixed fnjson exports
Browse files Browse the repository at this point in the history
  • Loading branch information
abumq committed Jul 25, 2023
1 parent 64c9a05 commit e0a599c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,6 @@ const result = await getDetail(getAge());

Try it on [RunKit](https://npm.runkit.com/airsync)

```javascript
const getName = ({ firstName, lastName }) => `${firstName} ${lastName}`;

const getNameSync = fnjson(getName);
```

Now if you pass in JSON with unresolved promises to the function, it would be correctly passed in to `getName` function

# Misc Features

## Options
Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
const { fn, exec, fnExport } = require('./fn');
const { json, spread } = require('./json');

const fnjson = (theSyncFunc, opts = {}) => fn(async (obj, ...anythingElse) => theSyncFunc(await json(obj), ...anythingElse), opts);

// default export
module.exports = fn;
module.exports = fnjson;

// name exports from fn
module.exports.fnExport = fnExport;
module.exports.exec = exec;
module.exports.fnjson = (theSyncFunc, opts = {}) => fn(async (obj, ...anythingElse) => theSyncFunc(await json(obj), ...anythingElse), opts);
module.exports.fnjson = fnjson;

module.exports.fn = module.exports.fnjson;
module.exports.fn = fnjson;

// name exports from json
module.exports.json = json;
Expand Down
4 changes: 2 additions & 2 deletions tests/fn-with-json-param-convert-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const assert = require('assert');
const airsync = require('../src');

describe('Test fnjson()', () => {
describe('Test fn with json like params', () => {

describe('Given a sync function', () => {
const myfn = ({ p1, p2 }) => `result => ${p1} & ${p2}`;
Expand All @@ -15,7 +15,7 @@ describe('Test fnjson()', () => {
})

describe('When converted to async', () => {
const myfnAsync = airsync.fnjson(myfn);
const myfnAsync = airsync.fn(myfn);

it('Returns same result without promises', async () => {
assert.equal(await myfnAsync({ p1: 'abumq', p2: 'Majid Q.' }), 'result => abumq & Majid Q.');
Expand Down

0 comments on commit e0a599c

Please sign in to comment.