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

Added support for uuid for strings #707

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion dist/jsoneditor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/jsoneditor.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/jsoneditor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ JSONEditor.AbstractEditor = Class.extend({
if(type === "number") return 0.0;
if(type === "boolean") return false;
if(type === "integer") return 0;
if(type === "string") return "";
if(type === "string") return this.format ==="uuid" ? $uuid(this.options) : "";
if(type === "object") return {};
if(type === "array") return [];
}
Expand Down
16 changes: 16 additions & 0 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ var $triggerc = function(el,event) {

el.dispatchEvent(e);
};

var $uuid = function (options) {
'use strict';
// http://www.ietf.org/rfc/rfc4122.txt
if (options && options.short) return "_"+("000000" + (Math.random()*Math.pow(36,8) << 0).toString(36)).slice(-6);

var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = "-";
return s.join("");
};