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

Support shorthand object initializer syntax (fixes #9) #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Grynn
Copy link

@Grynn Grynn commented Apr 13, 2017

This allows usage of ES6 Object Initializer Shorthand Syntax in the template. (JSON should continue working)

Examples:
fony -t '{ name, age, address }' will expand the template to
{ "name": "name", "age": "age", "address": "address" } and then generate fony data as per usual.

fony -t '{ name, age, location: address }' will expand the template to
{ "name": "name", "age": "age", "location": "address" }

Nested / array support continues to work so
fony -t '{ names: { name1: name, name2: name }, location: address, phones: [ "phone", 3 ] }' will work just fine.

The template is transformed via a trivial babel plugin (src/transform.js).

Apart from less typing (always a good thing) it also makes working on Windows much easier, since quotes are no longer mandatory for keynames or values!

While this works, I realized we could support much more complex syntax and be more efficient if createData were to accept an AST instead of an object instance. We could for example allow syntax like this: (emmet flavoured?)

{name, age, phone, known_locations: address*3 }

If there is interest I will work on a PR for emmet like syntax.

@zachdtaylor
Copy link

Will this PR be merged in? I think it would be a cool feature to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants