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 named references for use in other templated properties #8

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

Conversation

elijahmanor
Copy link
Contributor

Over the past couple of years I have wanted the ability to reference the output of one templated item inside another property. This hasn't been available from what I've seen so I've make some minor tweaks to support this feature.

Basic Usage

If you want to name the output of a templated property then append the name with |$someKey. To use the value you would just reference the $someKey inside the value of your templated item. See the following for an example

$.mockJSON.generateFromTemplate({
    "name|$1": "@LOREM",
    "path": "My @LOREM",
    "created": "@DATE_YYYY@DATE_MM@DATE_DD",
    "created by|$2": "@LETTER_UPPER.@LAST_NAME",
    "title": "My $1 by $2",
});

The output of the above snippet would show something like the following

output

Limitations

  • You can't combine the naming feature (|$someKey) and the auto-increment feature (|+1)
  • You can only use a named reference for items already generated. You will notice I don't reference $1 or '$2` until after I have named them

This feature could be a lot better, but in the meantime it does provide value.

@elijahmanor
Copy link
Contributor Author

@mennovanslooten Do you have any questions about this pull request? Do you think it is helpful?

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.

1 participant