Skip to content

Commit

Permalink
Merge pull request #1 from frankthelen/feature-floating-elements
Browse files Browse the repository at this point in the history
Feature floating elements
  • Loading branch information
frankthelen committed Mar 25, 2018
2 parents d17631e + 6fd997e commit 27d71e8
Show file tree
Hide file tree
Showing 5 changed files with 1,503 additions and 172 deletions.
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

0 comments on commit 27d71e8

Please sign in to comment.