SmartJSONEditor / PublicDocuments

Public Documents
MIT License
51 stars 10 forks source link

"GUID" as pre-defined transform data [feature] #20

Open ghost opened 3 years ago

ghost commented 3 years ago

I was surprised to find that there's no option to insert GUIDs as data for Smart Object values. It looks like there's a couple of ways to manually craft a token string or scriptify it. Just seems like something that'd be there out-the-gate.

markst commented 3 years ago

Also be nice to have.

@ghost could use a custom value transformer:

var ValueTransformer = function() {

    this.displayName = "UUID Value";
    this.shortDescription = "Random UUID Value Generator"
    this.transform = function(inputValue, jsonValue, arrayIndex, parameters, info) {
        return uuidv4();
    };

    function uuidv4() {
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random() * 16 | 0,
                v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }
}