Skip to content

Commit

Permalink
Adding a few functions to help with the JSON builder UI
Browse files Browse the repository at this point in the history
  • Loading branch information
narupley committed May 31, 2018
1 parent 1831298 commit d93d67f
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,30 @@ private static void appendMiscFunctions(StringBuilder builder) {
builder.append(" return 0;\n");
builder.append("}\n");

// Helper function to create a new String but leave undefined/null values alone
builder.append("function newStringOrUndefined(value) {\n");
builder.append(" if ('undefined' !== typeof value && value != null) {\n");
builder.append(" value = new String(value);\n");
builder.append(" }\n");
builder.append(" return value;\n");
builder.append("}\n");

// Helper function to create a new Boolean but leave undefined/null values alone
builder.append("function newBooleanOrUndefined(value) {\n");
builder.append(" if ('undefined' !== typeof value && value != null) {\n");
builder.append(" value = new Boolean(value);\n");
builder.append(" }\n");
builder.append(" return value;\n");
builder.append("}\n");

// Helper function to create a new Number but leave undefined/null values alone
builder.append("function newNumberOrUndefined(value) {\n");
builder.append(" if ('undefined' !== typeof value && value != null) {\n");
builder.append(" value = new Number(value);\n");
builder.append(" }\n");
builder.append(" return value;\n");
builder.append("}\n");

/*
* Since we use a sealed shared scope everywhere, importClass won't be available. To allow
* this to still work for migration, we override importClass to call importPackage instead.
Expand Down

0 comments on commit d93d67f

Please sign in to comment.