Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature floating elements #1

Merged
merged 3 commits into from
Mar 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,35 @@ my.cat.is.purring();
`{ key: 'is' }` in the example above is a *fix option*
which is a shorthand for `{ key: 'is', values: ['is'] }`.

### Floating elements

A phrasal function's `path` elements describe a fixed syntax, i.e., all the path elements have to be provided in exactly this order when calling the phrasal function.
In addition, you can specify floating elements which may occur optionally at any position (except the last) in the call of the phrasal function.

```javascript
const { proxy } = require('phrasal-functions');

const john = phrasal({
fn: function (options, arg) {
return { ...options, ...arg };
},
path: [
{ key: 'say', values: ['say', 'shout', 'yell', 'scream'] },
{ key: 'what', values: ['hello', 'goodbye', 'boo'] },
],
floating: [
{ key: 'not' },
],
});

john.say.goodbye({ to: 'Joe' });
// -> { say: 'say', what: 'goodbye', to: 'Joe' }
john.not.scream.boo({ to: 'Joe' });
// -> { not: 'not', say: 'scream', what: 'boo', to: 'Joe' }
john.yell.not.hello({ to: 'Joe' });
// -> { not: 'not', say: 'yell', what: 'hello', to: 'Joe' }
```

### Async functions

`fn` can also be an `async` function returning a promise.
Expand Down
Loading