webroo / dummy-json

Generates random dummy JSON data in Node.js
MIT License
380 stars 61 forks source link

Remove the character from generated value #20

Closed kuncevic closed 4 years ago

kuncevic commented 7 years ago

How would you remove the # character in front of "{{hexColor}}" e.g: #33CC99 => 33CC99

p.s. Currently looking in to Overriding built-in helpers if there is no better way. But got stuck here:

var myHelpers = {
  hexColor: function() {
    return hexColorValue.substr(1);  //how would you access generated value(hexColorValue) here ?
  }
};
webroo commented 4 years ago

Going through some (very!) old issues and tidying up in case it helps people searching for similar problems. In order to fix your issue you can simply use an existing built-in helper:

var myHelpers = {
  hexColor: function(options) {
    return dummyjson.helpers.hexColor(options).substr(1);
  }
};

There's more info on using built-in helpers in your own helpers here: https://github.com/webroo/dummy-json#using-built-in-helpers-inside-your-own-helpers