diff --git a/docs/css/all.css b/docs/css/all.css deleted file mode 100644 index bc6cb79..0000000 --- a/docs/css/all.css +++ /dev/null @@ -1,340 +0,0 @@ -/* - * TABLE OF CONTENTS: - * - Browser reset - * - HTML elements - * - JsDoc styling - */ - - - - - - -/* - * BEGIN BROWSER RESET - */ - -body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,p,pre,form,fieldset,input,textarea,p,blockquote,th,td { - margin:0; - padding:0 -} -html { - height:100%; - overflow:-moz-scrollbars-vertical; - overflow-x:auto -} -table { - border:0; - border-collapse:collapse; - border-spacing:0 -} -fieldset,img { - border:0 -} -address,caption,cite,code,dfn,em,strong,th,var { - font-style:normal; - font-weight:normal -} -em,cite { - font-style:italic -} -strong { - font-weight:bold -} -ol,ul { - list-style:none -} -caption,th { - text-align:left -} -h1,h2,h3,h4,h5,h6 { - font-size:100%; - font-weight:normal; - margin:0; - padding:0 -} -q:before,q:after { - content:'' -} -abbr,acronym { - border:0 -} - -/* - * END BROWSER RESET - */ - - - - - - -/* - * HTML ELEMENTS - */ - -@font-face { - font-family: 'M1m'; - src: url('fonts/mplus-1m-regular-webfont.eot'); - src: local('☺'), url('fonts/mplus-1m-regular-webfont.woff') format('woff'), url('fonts/mplus-1m-regular-webfont.ttf') format('truetype'), url('fonts/mplus-1m-regular-webfont.svg#webfontVd14f4NN') format('svg'); - font-weight: normal; - font-style: normal; -} - -@font-face { - font-family: 'M1m'; - src: url('fonts/mplus-1m-bold-webfont.eot'); - src: local('☺'), url('fonts/mplus-1m-bold-webfont.woff') format('woff'), url('fonts/mplus-1m-bold-webfont.ttf') format('truetype'), url('fonts/mplus-1m-bold-webfont.svg#webfontIjI5mZqE') format('svg'); - font-weight: bold; - font-style: normal; -} - - - -* { - line-height: 1.4em; -} - -html { - font-size: 100%; -} - -body { - font-size: 0.75em; - padding: 15px 0; - background: #eee; - background-image: -moz-linear-gradient(left, #dddddd, #f9f9f9) fixed; - background-image: -webkit-gradient(linear,left bottom,right bottom,color-stop(0, #dddddd),color-stop(1, #f9f9f9)) fixed; - } - -body, -input, -select, -textarea { - color: #000; - font-family: Arial, Geneva, sans-serif; -} - -a:link, -a:hover, -a:active, -a:visited { - color: #19199e; -} -a:hover, -a:focus { - color: #00f; - text-decoration: none; -} - -p { - margin: 0 0 1.5em 0; -} - -/* - * END HTML ELEMENTS - */ - - - -/* - * BEGIN HACK - */ - -div.containerMain:after, -div.safeBox:after { - content:""; - display:block; - height:0; - clear:both; -} - -/* - * END HACK - */ - - - -/* - * BEGIN JSDOC - */ - -/* Start menu */ -div.index *.heading1 { - margin-bottom: 0.5em; - border-bottom: 1px solid #999999; - font-family: M1m, Arial, sans-serif; - font-size: 1.6em; - letter-spacing: 1px; - line-height: 1.3em; -} - -div.index div.menu { - background-color: #FFFFFF; -} -*+html div.index div.menu { - background-color: #FFFFFF; -} -* html div.index div.menu { - background-color: #FFFFFF; -} - -div.index div.menu div { - text-align: left; -} - -div.index div.menu a { - text-decoration: none; -} -div.index div.menu a:hover { - text-decoration: underline; -} - -div.index ul.classList a { - display: block; - padding: 4px 0 2px 20px; - text-indent: -20px; -} - -div.index div.fineprint { - color: #777; - font-size: 0.9em; -} -div.index div.fineprint a { - color: #777; -} -/* End menu */ - - - -/* Start content */ -div.content *.classTitle { - font-family: M1m, sans-serif; - font-size: 2.5em; - letter-spacing: 2px; - text-shadow: 1px 1px 1px #999999; -} - -div.content *.classTitle span { - font-weight: bold; -} - -div.content p.summary { - font-size: 1.25em; -} - -div.content ul *.classname a, -div.content ul *.filename a { - font-family: Consolas, "Courier New", Courier, monospace; - text-decoration: none; - font-weight: bold; -} -div.content ul *.classname a:hover, -div.content ul *.filename a:hover { - text-decoration: underline; -} - -div.content div.props { - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; - background: #fff; - background: -moz-linear-gradient(top, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.2)); /* FF3.6 */ - background: -webkit-gradient(linear,left top,left bottom,color-stop(0, rgba(255, 255, 255, 0.7)),color-stop(1, rgba(255, 255, 255, 0.2))); - -moz-box-shadow: 0px 0px 10px #ccc; - -webkit-box-shadow: 0px 0px 5px #bbb; - box-shadow: 0px 0px 5px #bbb; -} - -div.content div.props div.sectionTitle { - font-family: M1m, sans-serif; - font-size: 1.6em; - letter-spacing: 1px; -} - - - -table.summaryTable caption { - font-family: M1m, sans-serif; - font-size: 1.6em; - letter-spacing: 1px; -} - -table.summaryTable td, -table.summaryTable th { - vertical-align: top; -} -table.summaryTable tr:last-child td { - padding-bottom: 0; -} - -table.summaryTable th { - font-weight: bold; -} - -table.summaryTable td.attributes { - font-family: Consolas, "Courier New", Courier, monospace; - color: #666; -} - -table.summaryTable td.nameDescription div.fixedFont { - font-weight: bold; -} - -table.summaryTable div.description { - color: #333; -} - - - -dl.detailList dt { - font-weight: bold; -} - - - -.fixedFont { - font-family: Consolas, "Courier New", Courier, monospace; -} - -.fixedFont.heading { - font-size: 1.25em; - line-height: 1.1em -} - -.fixedFont.heading + .description { - font-size: 1.2em; -} - -.fixedFont.heading .light, -.fixedFont.heading .lighter { - font-weight: bold; -} - -pre.code { - overflow: auto; - font-family: Consolas, "Courier New", Courier, monospace; - background: #eee; -} -/* Start content */ - - - -/* Start general styles */ -.light { - color: #666; -} - -.lighter { - color: #999; -} - -span.break { - font-size: 1px; - line-height: 1px; -} -/* End general styles */ - -/* - * END JSDOC - */ \ No newline at end of file diff --git a/docs/css/fonts/mplus-1m-bold-webfont.eot b/docs/css/fonts/mplus-1m-bold-webfont.eot deleted file mode 100644 index 6c64f8d..0000000 Binary files a/docs/css/fonts/mplus-1m-bold-webfont.eot and /dev/null differ diff --git a/docs/css/fonts/mplus-1m-bold-webfont.svg b/docs/css/fonts/mplus-1m-bold-webfont.svg deleted file mode 100644 index 5129512..0000000 --- a/docs/css/fonts/mplus-1m-bold-webfont.svg +++ /dev/null @@ -1,134 +0,0 @@ - - - - -This is a custom SVG webfont generated by Font Squirrel. -Foundry URL : http://mplus-fonts.sourceforge.jp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/css/fonts/mplus-1m-bold-webfont.ttf b/docs/css/fonts/mplus-1m-bold-webfont.ttf deleted file mode 100644 index 0cf54cb..0000000 Binary files a/docs/css/fonts/mplus-1m-bold-webfont.ttf and /dev/null differ diff --git a/docs/css/fonts/mplus-1m-bold-webfont.woff b/docs/css/fonts/mplus-1m-bold-webfont.woff deleted file mode 100644 index f90475d..0000000 Binary files a/docs/css/fonts/mplus-1m-bold-webfont.woff and /dev/null differ diff --git a/docs/css/fonts/mplus-1m-regular-webfont.eot b/docs/css/fonts/mplus-1m-regular-webfont.eot deleted file mode 100644 index a53f8b5..0000000 Binary files a/docs/css/fonts/mplus-1m-regular-webfont.eot and /dev/null differ diff --git a/docs/css/fonts/mplus-1m-regular-webfont.svg b/docs/css/fonts/mplus-1m-regular-webfont.svg deleted file mode 100644 index 3c835a3..0000000 --- a/docs/css/fonts/mplus-1m-regular-webfont.svg +++ /dev/null @@ -1,134 +0,0 @@ - - - - -This is a custom SVG webfont generated by Font Squirrel. -Foundry URL : http://mplus-fonts.sourceforge.jp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/css/fonts/mplus-1m-regular-webfont.ttf b/docs/css/fonts/mplus-1m-regular-webfont.ttf deleted file mode 100644 index 684abfd..0000000 Binary files a/docs/css/fonts/mplus-1m-regular-webfont.ttf and /dev/null differ diff --git a/docs/css/fonts/mplus-1m-regular-webfont.woff b/docs/css/fonts/mplus-1m-regular-webfont.woff deleted file mode 100644 index 49585d8..0000000 Binary files a/docs/css/fonts/mplus-1m-regular-webfont.woff and /dev/null differ diff --git a/docs/css/handheld.css b/docs/css/handheld.css deleted file mode 100644 index 529bebb..0000000 --- a/docs/css/handheld.css +++ /dev/null @@ -1,207 +0,0 @@ -/* - * TABLE OF CONTENTS: - * - Browser reset - * - HTML elements - * - JsDoc styling - * - Media query check - */ - - - - - - -/* - * HTML ELEMENTS - */ - -body { - padding: 1% 4% 1% 4%; -} - -/* - * HTML ELEMENTS - */ - - - - - -/* - * BEGIN JSDOC - */ - -/* Start menu */ -div.index div.menu { - position: fixed; - top: 0; - right: 0; - -moz-border-radius-bottomleft: 15px; - -webkit-border-bottom-left-radius: 15px; - -border-bottom-left-radius: 15px; - padding: 4px 5px 8px 10px; - -moz-box-shadow: 0px 0px 10px #c4c4c4; - -webkit-box-shadow: 0px 0px 10px #c4c4c4; - box-shadow: 0px 0px 10px #c4c4c4; - background-color: rgba(255, 255, 255, 0.9); -} - -div.index div.indexLinks a { - float: right; - clear: both; - font-size: 1.1em; -} - -div.index *.heading1 { - display:none; -} - -div.index ul.classList { - display:none; -} - -div.index div.fineprint { - display:none; -} - -div.indexStatic { - display: none; -} -/* End menu */ - - - -/* Start content */ -div.content *.classTitle { - margin-right: 60px; - margin-bottom: 0.8em; - font-size: 2em -} - -div.content p.description.summary { - margin-bottom: 0.2em; -} - -div.content div.props { - margin: 1.5em -2% 0 -2%; - padding: 2%; -} - -table.summaryTable { - position: relative; - left: -10px; - width: 100%; - border-collapse: collapse; - box-sizing: content-box; - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; - -ms-box-sizing: content-box; - -o-box-sizing: content-box; - -icab-box-sizing: content-box; - -khtml-box-sizing: content-box; -} - -table.summaryTable caption { - padding: 0 10px 10px 10px; -} - -table.summaryTable td, -table.summaryTable th { - padding: 0px 10px 10px 10px; -} -table.summaryTable tr:last-child td { - padding-bottom: 0; -} - -table.summaryTable td.attributes { - width: 35%; -} - -table.summaryTable td.nameDescription { - width: 65% -} - - - -dl.detailList { - margin-top: 0.5em; -} - -dl.detailList.nomargin + dl.detailList.nomargin { - margin-top: 0; -} - -dl.detailList dt { - display: inline; - margin-right: 5px; -} - -dl.detailList dt:before { - display: block; - content: ""; -} - -dl.detailList dd { - display: inline; -} - -dl.detailList.params dt { - display: block; -} -dl.detailList.params dd { - display: block; - padding-left: 2em; - padding-bottom: 0.4em; -} - - - - -ul.fileList li { - margin-bottom: 1.5em; -} - - - -.fixedFont.heading { - margin-bottom: 0.5em; -} - -pre.code { - margin: 10px 0 10px 0; - padding: 10px; - border: 1px solid #ccc; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; - border-radius: 2px; -} -/* End content */ - -/* - * END JSDOC - */ - - - - - - - -/* - * START MEDIA QUERY CHECK - */ - -.cssLoadCheck { - position: absolute; - top: -99999px; - left: -99999px; - border: 0; - width: 100px; - padding: 0; - overflow: hidden; -} - -/* - * END MEDIA QUERY CHECK - */ - diff --git a/docs/css/screen.css b/docs/css/screen.css deleted file mode 100644 index 786765a..0000000 --- a/docs/css/screen.css +++ /dev/null @@ -1,280 +0,0 @@ -/* - * TABLE OF CONTENTS: - * - JsDoc styling - * - Media query check - */ - - - - - - -/* - * BEGIN JSDOC - */ - -/* Start menu */ -div.index { - position: fixed; - top: 0; - bottom: 0; - float: left; - width: 30%; - min-width: 100px; - max-width: 300px; - padding: 0 0 10px 0; - overflow: auto; -} - -div.index *.heading1 { - padding: 8px 0 0.4em 0; -} - -div.index div.menu { - margin: 0 15px 0 -15px; - -moz-border-radius-bottomright: 15px; - -webkit-border-bottom-right-radius: 15px; - -border-bottom-right-radius: 15px; - padding: 15px 15px 15px 30px; - -moz-box-shadow: 0px 0px 10px #c4c4c4; - -webkit-box-shadow: 0px 0px 10px #c4c4c4; - box-shadow: 0px 0px 10px #c4c4c4; - background-color: rgba(255, 255, 255, 0.5); -} - -div.index div.indexLinks { - margin-top: 13px; - position: absolute; - right: 30px; -} - -div.index div.indexLinks a { - color: #999999; - text-transform: lowercase; -} - -div.index div.indexLinks a:first-child { - margin-right: 3px; - border-right: 1px solid #999999; - padding-right: 5px; -} - -div.index ul.classList a { - line-height: 1.1em; - font-family: Consolas, "Courier New", Courier, monospace; -} - -div.index ul.classList a + a { - margin-left: 0.5em; -} - -div.index div.fineprint { - margin: 1em 0 0 15px; - color: #777; - font-size: 0.9em; -} - -div.index div.fineprint a { - color: #777; -} - -div.indexStatic { - position: static; - min-height: 1em; -} -/* End menu */ - - -/* Start content */ -div.content { - float: left; - width: 70%; - min-width: 300px; - max-width: 600px; -} -div.innerContent { - padding: 0 0 0 2.5em; -} - -div.content ul, -div.content ol { - margin-bottom: 3em; -} - -div.content *.classTitle { - position: relative; - left: -10px; - margin: -30px 0 0.5em 0; - -moz-border-radius: 15px; - -webkit-border-radius: 15px; - border-radius: 15px; - padding: 25px 15px 15px 15px; - background-color: #FFFFFF; - background-color: rgba(255, 255, 255, 0.5); - -moz-box-shadow: 0px 0px 10px #c4c4c4; - -webkit-box-shadow: 0px 0px 10px #c4c4c4; - box-shadow: 0px 0px 10px #c4c4c4; -} - -div.content p.summary { - margin-bottom: 0.5em; -} - -div.content ul.summary { - margin-bottom: 1.5em; -} - -div.content ul *.classname a, -div.content ul *.filename a { - font-family: Consolas, "Courier New", Courier, monospace; - text-decoration: none; - font-weight: bold; -} -div.content ul *.classname a:hover, -div.content ul *.filename a:hover { - text-decoration: underline; -} - -div.content div.props { - position: relative; - left: -10px; - margin-bottom: 2.5em; - padding: 10px 15px 15px 15px; - overflow: hidden; -} - -div.content div.props div.sectionTitle { - padding-bottom: 10px; -} - -div.content div.hr { - margin: 0 10px 0 0; - height: 4em; -} - - - -table.summaryTable { - position: relative; - left: -10px; - width: 100%; - border-collapse: collapse; - box-sizing: content-box; - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; - -ms-box-sizing: content-box; - -o-box-sizing: content-box; - -icab-box-sizing: content-box; - -khtml-box-sizing: content-box; -} - -table.summaryTable caption { - padding: 0 10px 10px 10px; -} - -table.summaryTable td, -table.summaryTable th { - padding: 0px 10px 10px 10px; -} -table.summaryTable tr:last-child td { - padding-bottom: 0; -} - -table.summaryTable td.attributes { - width: 35%; -} - -table.summaryTable td.nameDescription { - width: 65% -} - - - -dl.detailList { - margin-top: 0.5em; -} - -dl.detailList.nomargin + dl.detailList.nomargin { - margin-top: 0; -} - -dl.detailList dt { - display: inline; - margin-right: 5px; -} - -dl.detailList dt:before { - display: block; - content: ""; -} - -dl.detailList dd { - display: inline; -} - -dl.detailList.params dt { - display: block; -} -dl.detailList.params dd { - display: block; - padding-left: 2em; - padding-bottom: 0.4em; -} - - - - -ul.fileList li { - margin-bottom: 1.5em; -} - - - -.fixedFont.heading { - margin-bottom: 0.5em; -} - -pre.code { - margin: 10px 0 10px 0; - padding: 10px; - border: 1px solid #ccc; - -moz-border-radius: 2px; - -webkit-border-radius: 2px; - border-radius: 2px; -} -/* End content */ - -.clear { - clear: both; - width: 100%; - min-height: 0; -} - -/* - * END JSDOC - */ - - - - - - - -/* - * START MEDIA QUERY CHECK - */ - -.cssLoadCheck { - position: absolute; - top: -99999px; - left: -99999px; - border: 0; - width: 100px; - padding: 0; - overflow: hidden; -} - -/* - * END MEDIA QUERY CHECK - */ - diff --git a/docs/files.html b/docs/files.html index 876f7dc..2bc2109 100644 --- a/docs/files.html +++ b/docs/files.html @@ -215,7 +215,7 @@

jsv.js

Version:
-
3.0
+
3.2
@@ -227,7 +227,7 @@

jsv.js

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:26:00 GMT-0700 (MST)
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 1b24624..c4e9e19 100644 --- a/docs/index.html +++ b/docs/index.html @@ -244,7 +244,7 @@

ValidationError

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:26:00 GMT-0700 (MST)
\ No newline at end of file diff --git a/docs/javascript/wbos.csstools.mediaqueryfallback.js b/docs/javascript/wbos.csstools.mediaqueryfallback.js deleted file mode 100644 index 51a5bc6..0000000 --- a/docs/javascript/wbos.csstools.mediaqueryfallback.js +++ /dev/null @@ -1,185 +0,0 @@ -/** - * @fileOverview Media Query FallBack - * @author Wouter Bos (www.thebrightlines.com) - * @since 1.0 - 2010-09-10 - * @version 1.0 - 2010-09-10 - */ - - - - - - -if (typeof(wbos) == "undefined") { - /** - * @namespace wbos = Wouter Bos (www.thebrightlines.com) - */ - wbos = {} -} -if (typeof(wbos.CssTools) == "undefined") { - /** - * @namespace Namespace for CSS-related functionality - */ - wbos.CssTools = {} -} - - - - -/** - * @namespace Fallback for CSS advanced media query - * @class - * @since 1.0 - 2010-09-10 - * @version 1.0 - 2010-09-10 - */ -wbos.CssTools.MediaQueryFallBack = ( function() { - var config = { - cssScreen: "/css/screen.css", - cssHandheld: "/css/handheld.css", - mobileMaxWidth: 660, - testDivClass: "cssLoadCheck", - dynamicCssLinkId: "DynCssLink", - resizeDelay: 30 - } - var noMediaQuery = false; - var delay; - var currentCssMediaType; - - // Adding events to elements in the DOM without overwriting it - function addEvent(element, newFunction, eventType) { - var oldEvent = eval("element." + eventType); - var eventContentType = eval("typeof element." + eventType) - - if ( eventContentType != 'function' ) { - eval("element." + eventType + " = newFunction") - } else { - eval("element." + eventType + " = function(e) { oldEvent(e); newFunction(e); }") - } - } - - // Get the the inner width of the browser window - function getWindowWidth() { - if (window.innerWidth) { - return window.innerWidth; - } else if (document.documentElement.clientWidth) { - return document.documentElement.clientWidth; - } else if (document.body.clientWidth) { - return document.body.clientWidth; - } else{ - return 0; - } - } - - function addCssLink(cssHref) { - var cssNode = document.createElement('link'); - var windowWidth; - cssNode.type = 'text/css'; - cssNode.rel = 'stylesheet'; - cssNode.media = 'screen, handheld, fallback'; - //cssNode.id = config.dynamicCssLinkId; - cssNode.href = cssHref; - document.getElementsByTagName("head")[0].appendChild(cssNode); - } - - - - /* Start public */ - return { - /** - * Adds link to CSS in the head if no CSS is loaded - * - * @since 1.0 - 2010-08-21 - * @version 1.0 - 2010-08-21 - * @param {String|Object} cssScreen URL to CSS file for larger screens - * @param {String|Object} cssHandheld URL to CSS file for smaller screens - * @param {Number} mobileMaxWidth Maximum width for handheld devices - * @example - * wbos.CssTools.MediaQueryFallBack.LoadCss(['screen.css', 'screen2.css'], 'mobile.css', 480) - */ - LoadCss: function(cssScreen, cssHandheld, mobileMaxWidth) { - // Set config values - if (typeof(cssScreen) != "undefined") { - config.cssScreen = cssScreen; - } - if (typeof(cssHandheld) != "undefined") { - config.cssHandheld = cssHandheld; - } - if (typeof(mobileMaxWidth) != "undefined") { - config.mobileMaxWidth = mobileMaxWidth; - } - - // Check if CSS is loaded - var cssloadCheckNode = document.createElement('div'); - cssloadCheckNode.className = config.testDivClass; - document.getElementsByTagName("body")[0].appendChild(cssloadCheckNode); - if (cssloadCheckNode.offsetWidth != 100 && noMediaQuery == false) { - noMediaQuery = true; - } - cssloadCheckNode.parentNode.removeChild(cssloadCheckNode) - - if (noMediaQuery == true) { - // Browser does not support Media Queries, so JavaScript will supply a fallback - var cssHref = ""; - - // Determines what CSS file to load - if (getWindowWidth() <= config.mobileMaxWidth) { - cssHref = config.cssHandheld; - newCssMediaType = "handheld"; - } else { - cssHref = config.cssScreen; - newCssMediaType = "screen"; - } - - // Add CSS link to of page - if (cssHref != "" && currentCssMediaType != newCssMediaType) { - var currentCssLinks = document.styleSheets - for (var i = 0; i < currentCssLinks.length; i++) { - for (var ii = 0; ii < currentCssLinks[i].media.length; ii++) { - if (typeof(currentCssLinks[i].media) == "object") { - if (currentCssLinks[i].media.item(ii) == "fallback") { - currentCssLinks[i].ownerNode.parentNode.removeChild(currentCssLinks[i].ownerNode) - i-- - break; - } - } else { - if (currentCssLinks[i].media.indexOf("fallback") >= 0) { - currentCssLinks[i].owningElement.parentNode.removeChild(currentCssLinks[i].owningElement) - i-- - break; - } - } - } - } - if (typeof(cssHref) == "object") { - for (var i = 0; i < cssHref.length; i++) { - addCssLink(cssHref[i]) - } - } else { - addCssLink(cssHref) - } - - currentCssMediaType = newCssMediaType; - } - - - // Check screen size again if user resizes window - addEvent(window, wbos.CssTools.MediaQueryFallBack.LoadCssDelayed, 'onresize') - } - }, - - /** - * Runs LoadCSS after a short delay - * - * @since 1.0 - 2010-08-21 - * @version 1.0 - 2010-08-21 - * @example - * wbos.CssTools.MediaQueryFallBack.LoadCssDelayed() - */ - LoadCssDelayed: function() { - clearTimeout(delay); - delay = setTimeout( "wbos.CssTools.MediaQueryFallBack.LoadCss()", config.resizeDelay) - } - - } - /* End public */ -})(); diff --git a/docs/symbols/Environment.html b/docs/symbols/Environment.html index ddfd74e..ff5bff0 100644 --- a/docs/symbols/Environment.html +++ b/docs/symbols/Environment.html @@ -329,6 +329,15 @@

+ +   + +
getOption(name) +
+
Returns the specified environment option.
+ + +   @@ -347,6 +356,15 @@

+ +   + +
setOption(name, value) +
+
Sets the specified environment option to the specified value.
+ + +   @@ -643,6 +661,13 @@

+
+
Deprecated:
+
+ Use Environment#getOption with option "defaultFragmentDelimiter" +
+
+ @@ -688,6 +713,49 @@

+
+ + +
+ + {Any} + getOption(name) + +
+
+ Returns the specified environment option. + + +
+ + + + +
+
Parameters:
+ +
+ {String} name + +
+
The name of the environment option to set
+ +
+ + + + + +
+
Returns:
+ +
{Any} The value of the environment option
+ +
+ + + +
@@ -718,6 +786,13 @@

+
+
Deprecated:
+
+ Use Environment#setOption with option "defaultFragmentDelimiter" +
+
+ @@ -754,6 +829,55 @@

+
+
Deprecated:
+
+ Use Environment#setOption with option "defaultSchemaURI" +
+
+ + + + + + + +
+ + +
+ + + setOption(name, value) + +
+
+ Sets the specified environment option to the specified value. + + +
+ + + + +
+
Parameters:
+ +
+ {String} name + +
+
The name of the environment option to set
+ +
+ {Any} value + +
+
The new value of the environment option
+ +
+ + @@ -823,7 +947,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:25:59 GMT-0700 (MST)
diff --git a/docs/symbols/JSONInstance.html b/docs/symbols/JSONInstance.html index 344cf00..d308131 100644 --- a/docs/symbols/JSONInstance.html +++ b/docs/symbols/JSONInstance.html @@ -818,7 +818,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:25:59 GMT-0700 (MST)
diff --git a/docs/symbols/JSONSchema.html b/docs/symbols/JSONSchema.html index 1944422..9be66b2 100644 --- a/docs/symbols/JSONSchema.html +++ b/docs/symbols/JSONSchema.html @@ -286,6 +286,15 @@

+ +   + +
getAttributes() +
+
Returns all the attributes of the schema.
+ + +   @@ -307,7 +316,7 @@

  -
validate(instance, report, parent, parentSchema) +
validate(instance, report, parent, parentSchema, name)
Validates the provided instance against the target schema and returns a Report.
@@ -484,6 +493,38 @@

+
+ + +
+ + {Object} + getAttributes() + +
+
+ Returns all the attributes of the schema. + + +
+ + + + + + + + +
+
Returns:
+ +
{Object} A map of all parsed attribute values
+ +
+ + + +
@@ -578,7 +619,7 @@

{Report} - validate(instance, report, parent, parentSchema) + validate(instance, report, parent, parentSchema, name)
@@ -617,6 +658,12 @@

The schema of the parent/containing instance
+
+ {String} name + Optional +
+
The name of the parent object's property that references the instance
+ @@ -647,7 +694,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:25:59 GMT-0700 (MST)
diff --git a/docs/symbols/JSV.html b/docs/symbols/JSV.html index eda3026..a4a14ff 100644 --- a/docs/symbols/JSV.html +++ b/docs/symbols/JSV.html @@ -388,36 +388,36 @@

<static>   -
JSV.keys(o) +
JSV.inherits(base, extra, extension)
-
Returns an array of the names of all properties of an object.
+
Merges two schemas/instance together.
<static>   -
JSV.mapArray(arr, iterator, scope) +
JSV.keys(o)
-
Returns a new array with each item transformed by the iterator.
+
Returns an array of the names of all properties of an object.
<static>   -
JSV.mapObject(obj, iterator, scope) +
JSV.mapArray(arr, iterator, scope)
-
Returns a new object with each property transformed by the iterator.
+
Returns a new array with each item transformed by the iterator.
<static>   -
JSV.mergeSchemas(base, extra, isSchema) +
JSV.mapObject(obj, iterator, scope)
-
Attempts to merge the values of two schemas together.
+
Returns a new object with each property transformed by the iterator.
@@ -1012,15 +1012,15 @@


- +
<static> - {Array} - JSV.keys(o) + {Any} + JSV.inherits(base, extra, extension)
- Returns an array of the names of all properties of an object. + Merges two schemas/instance together.
@@ -1032,10 +1032,22 @@

Parameters:
- {Object|Array} o + {JSONSchema|Any} base
-
The object in question
+
The old value to merge
+ +
+ {JSONSchema|Any} extra + +
+
The new value to merge
+ +
+ {Boolean} extension + +
+
If the merge is a JSON Schema extension
@@ -1046,7 +1058,7 @@

Returns:
-
{Array} The names of all properties
+
{Any} The modified base value
@@ -1055,15 +1067,15 @@


- +
<static> {Array} - JSV.mapArray(arr, iterator, scope) + JSV.keys(o)
- Returns a new array with each item transformed by the iterator. + Returns an array of the names of all properties of an object.
@@ -1075,22 +1087,10 @@

Parameters:
- {Array} arr - -
-
The array to transform
- -
- {Function} iterator - -
-
A function that returns the new value of the provided item
- -
- {Object} scope + {Object|Array} o
-
The value of this in the iterator
+
The object in question
@@ -1101,7 +1101,7 @@

Returns:
-
{Array} A new array with each item transformed
+
{Array} The names of all properties
@@ -1110,15 +1110,15 @@


- +
<static> - {Object} - JSV.mapObject(obj, iterator, scope) + {Array} + JSV.mapArray(arr, iterator, scope)
- Returns a new object with each property transformed by the iterator. + Returns a new array with each item transformed by the iterator.
@@ -1130,20 +1130,20 @@

Parameters:
- {Object} obj + {Array} arr
-
The object to transform
+
The array to transform
{Function} iterator
-
A function that returns the new value of the provided property
+
A function that returns the new value of the provided item
{Object} scope - Optional +
The value of this in the iterator
@@ -1156,7 +1156,7 @@

Returns:
-
{Object} A new object with each property transformed
+
{Array} A new array with each item transformed
@@ -1165,15 +1165,15 @@


- +
<static> - {Any} - JSV.mergeSchemas(base, extra, isSchema) + {Object} + JSV.mapObject(obj, iterator, scope)
- Attempts to merge the values of two schemas together. This method aproximately reproduces the results expected from extends in JSON Schema. + Returns a new object with each property transformed by the iterator.
@@ -1185,22 +1185,22 @@

Parameters:
- {Any} base + {Object} obj
-
The value to extend
+
The object to transform
- {Any} extra + {Function} iterator
-
The value to extend with
+
A function that returns the new value of the provided property
- {Boolean} isSchema - + {Object} scope + Optional
-
If the value is a schema
+
The value of this in the iterator
@@ -1211,7 +1211,7 @@

Returns:
-
{Any} The modified base object
+
{Object} A new object with each property transformed
@@ -1445,7 +1445,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:26:00 GMT-0700 (MST)
diff --git a/docs/symbols/Report.html b/docs/symbols/Report.html index 8ea205a..7393616 100644 --- a/docs/symbols/Report.html +++ b/docs/symbols/Report.html @@ -735,7 +735,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:26:00 GMT-0700 (MST)
diff --git a/docs/symbols/ValidationError.html b/docs/symbols/ValidationError.html index bfdb275..00c8dc9 100644 --- a/docs/symbols/ValidationError.html +++ b/docs/symbols/ValidationError.html @@ -493,7 +493,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:10 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:26:00 GMT-0700 (MST)
diff --git a/docs/symbols/_global_.html b/docs/symbols/_global_.html index ad99412..77e2b57 100644 --- a/docs/symbols/_global_.html +++ b/docs/symbols/_global_.html @@ -253,7 +253,7 @@

- Documentation generated by JsDoc Toolkit 2.4.0 on Wed Oct 06 2010 19:11:09 GMT-0600 (MDT) + Documentation generated by JsDoc Toolkit 2.4.0 on Mon Nov 15 2010 19:25:59 GMT-0700 (MST)
diff --git a/docs/symbols/src/jsv.js.html b/docs/symbols/src/jsv.js.html index 650b997..a20bcc5 100644 --- a/docs/symbols/src/jsv.js.html +++ b/docs/symbols/src/jsv.js.html @@ -10,7 +10,7 @@ 3 * 4 * @fileOverview A JavaScript implementation of a extendable, fully compliant JSON Schema validator. 5 * @author <a href="mailto:gary.court@gmail.com">Gary Court</a> - 6 * @version 3.0 + 6 * @version 3.2 7 * @see http://github.com/garycourt/JSV 8 */ 9 @@ -51,7 +51,7 @@ 44 45 (function () { 46 - 47 var URL = require("url"), + 47 var URI = require("./uri/uri").URI, 48 O = {}, 49 I2H = "0123456789abcdef".split(""), 50 mapArray, filterArray, searchArray, @@ -168,1025 +168,1081 @@ 161 return arr; 162 } 163 -164 //Warning: Not a generic clone function -165 //Produces a JSV acceptable clone -166 function clone(obj, deep) { -167 var newObj, x; -168 -169 switch (typeOf(obj)) { -170 case "object": -171 if (deep) { -172 newObj = {}; -173 for (x in obj) { -174 if (obj[x] !== O[x]) { -175 newObj[x] = clone(obj[x], deep); -176 } -177 } -178 return newObj; -179 } else { -180 return createObject(obj); -181 } -182 break; -183 case "array": -184 if (deep) { -185 newObj = new Array(obj.length); -186 x = obj.length; -187 while (--x >= 0) { -188 newObj[x] = clone(obj[x], deep); -189 } -190 return newObj; -191 } else { -192 return Array.pototype.slice.call(obj); -193 } -194 break; -195 default: -196 return obj; -197 } -198 } -199 -200 function randomUUID() { -201 return [ -202 I2H[Math.floor(Math.random() * 0x10)], -203 I2H[Math.floor(Math.random() * 0x10)], -204 I2H[Math.floor(Math.random() * 0x10)], -205 I2H[Math.floor(Math.random() * 0x10)], -206 I2H[Math.floor(Math.random() * 0x10)], -207 I2H[Math.floor(Math.random() * 0x10)], -208 I2H[Math.floor(Math.random() * 0x10)], -209 I2H[Math.floor(Math.random() * 0x10)], -210 "-", -211 I2H[Math.floor(Math.random() * 0x10)], -212 I2H[Math.floor(Math.random() * 0x10)], -213 I2H[Math.floor(Math.random() * 0x10)], -214 I2H[Math.floor(Math.random() * 0x10)], -215 "-4", //set 4 high bits of time_high field to version -216 I2H[Math.floor(Math.random() * 0x10)], -217 I2H[Math.floor(Math.random() * 0x10)], -218 I2H[Math.floor(Math.random() * 0x10)], -219 "-", -220 I2H[(Math.floor(Math.random() * 0x10) & 0x3) | 0x8], //specify 2 high bits of clock sequence -221 I2H[Math.floor(Math.random() * 0x10)], -222 I2H[Math.floor(Math.random() * 0x10)], -223 I2H[Math.floor(Math.random() * 0x10)], -224 "-", -225 I2H[Math.floor(Math.random() * 0x10)], -226 I2H[Math.floor(Math.random() * 0x10)], -227 I2H[Math.floor(Math.random() * 0x10)], -228 I2H[Math.floor(Math.random() * 0x10)], -229 I2H[Math.floor(Math.random() * 0x10)], -230 I2H[Math.floor(Math.random() * 0x10)], -231 I2H[Math.floor(Math.random() * 0x10)], -232 I2H[Math.floor(Math.random() * 0x10)], -233 I2H[Math.floor(Math.random() * 0x10)], -234 I2H[Math.floor(Math.random() * 0x10)], -235 I2H[Math.floor(Math.random() * 0x10)], -236 I2H[Math.floor(Math.random() * 0x10)] -237 ].join(""); -238 } -239 -240 function escapeURIComponent(str) { -241 return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A'); -242 } -243 -244 function formatURI(uri) { -245 if (typeof uri === "string" && uri.indexOf("#") === -1) { -246 uri += "#"; -247 } -248 return uri; -249 } -250 -251 //merge two objects together that is (roughly) extends compliant -252 function mergeSchemas(base, extra, isSchema) { -253 var key; -254 for (key in extra) { -255 if (extra[key] !== O[key]) { -256 if (isSchema && key === "extends") { -257 base[key] = toArray(base[key]).concat(toArray(extra[key])); -258 } else if (typeOf(base[key]) === "object" && typeOf(extra[key]) === "object") { -259 mergeSchemas(base[key], extra[key], !isSchema || key !== "properties"); //FIXME: An attribute other then "properties" may be a plain object -260 } else { -261 base[key] = extra[key]; -262 } -263 } -264 } -265 return base; -266 } +164 function randomUUID() { +165 return [ +166 I2H[Math.floor(Math.random() * 0x10)], +167 I2H[Math.floor(Math.random() * 0x10)], +168 I2H[Math.floor(Math.random() * 0x10)], +169 I2H[Math.floor(Math.random() * 0x10)], +170 I2H[Math.floor(Math.random() * 0x10)], +171 I2H[Math.floor(Math.random() * 0x10)], +172 I2H[Math.floor(Math.random() * 0x10)], +173 I2H[Math.floor(Math.random() * 0x10)], +174 "-", +175 I2H[Math.floor(Math.random() * 0x10)], +176 I2H[Math.floor(Math.random() * 0x10)], +177 I2H[Math.floor(Math.random() * 0x10)], +178 I2H[Math.floor(Math.random() * 0x10)], +179 "-4", //set 4 high bits of time_high field to version +180 I2H[Math.floor(Math.random() * 0x10)], +181 I2H[Math.floor(Math.random() * 0x10)], +182 I2H[Math.floor(Math.random() * 0x10)], +183 "-", +184 I2H[(Math.floor(Math.random() * 0x10) & 0x3) | 0x8], //specify 2 high bits of clock sequence +185 I2H[Math.floor(Math.random() * 0x10)], +186 I2H[Math.floor(Math.random() * 0x10)], +187 I2H[Math.floor(Math.random() * 0x10)], +188 "-", +189 I2H[Math.floor(Math.random() * 0x10)], +190 I2H[Math.floor(Math.random() * 0x10)], +191 I2H[Math.floor(Math.random() * 0x10)], +192 I2H[Math.floor(Math.random() * 0x10)], +193 I2H[Math.floor(Math.random() * 0x10)], +194 I2H[Math.floor(Math.random() * 0x10)], +195 I2H[Math.floor(Math.random() * 0x10)], +196 I2H[Math.floor(Math.random() * 0x10)], +197 I2H[Math.floor(Math.random() * 0x10)], +198 I2H[Math.floor(Math.random() * 0x10)], +199 I2H[Math.floor(Math.random() * 0x10)], +200 I2H[Math.floor(Math.random() * 0x10)] +201 ].join(""); +202 } +203 +204 function escapeURIComponent(str) { +205 return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A'); +206 } +207 +208 function formatURI(uri) { +209 if (typeof uri === "string" && uri.indexOf("#") === -1) { +210 uri += "#"; +211 } +212 return uri; +213 } +214 +215 /** +216 * Defines an error, found by a schema, with an instance. +217 * This class can only be instantiated by {@link Report#addError}. +218 * +219 * @name ValidationError +220 * @class +221 * @see Report#addError +222 */ +223 +224 /** +225 * The URI of the instance that has the error. +226 * +227 * @name ValidationError.prototype.uri +228 * @type String +229 */ +230 +231 /** +232 * The URI of the schema that generated the error. +233 * +234 * @name ValidationError.prototype.schemaUri +235 * @type String +236 */ +237 +238 /** +239 * The name of the schema attribute that generated the error. +240 * +241 * @name ValidationError.prototype.attribute +242 * @type String +243 */ +244 +245 /** +246 * An user-friendly (English) message about what failed to validate. +247 * +248 * @name ValidationError.prototype.message +249 * @type String +250 */ +251 +252 /** +253 * The value of the schema attribute that generated the error. +254 * +255 * @name ValidationError.prototype.details +256 * @type Any +257 */ +258 +259 /** +260 * Reports are returned from validation methods to describe the result of a validation. +261 * +262 * @name Report +263 * @class +264 * @see JSONSchema#validate +265 * @see Environment#validate +266 */ 267 -268 /** -269 * Defines an error, found by a schema, with an instance. -270 * This class can only be instantiated by {@link Report#addError}. -271 * -272 * @name ValidationError -273 * @class -274 * @see Report#addError -275 */ -276 -277 /** -278 * The URI of the instance that has the error. -279 * -280 * @name ValidationError.prototype.uri -281 * @type String -282 */ -283 -284 /** -285 * The URI of the schema that generated the error. -286 * -287 * @name ValidationError.prototype.schemaUri -288 * @type String -289 */ -290 -291 /** -292 * The name of the schema attribute that generated the error. -293 * -294 * @name ValidationError.prototype.attribute -295 * @type String -296 */ -297 -298 /** -299 * An user-friendly (English) message about what failed to validate. -300 * -301 * @name ValidationError.prototype.message -302 * @type String -303 */ -304 -305 /** -306 * The value of the schema attribute that generated the error. -307 * -308 * @name ValidationError.prototype.details -309 * @type Any -310 */ -311 -312 /** -313 * Reports are returned from validation methods to describe the result of a validation. -314 * -315 * @name Report -316 * @class -317 * @see JSONSchema#validate -318 * @see Environment#validate -319 */ -320 -321 function Report() { -322 /** -323 * An array of {@link ValidationError} objects that define all the errors generated by the schema against the instance. -324 * -325 * @name Report.prototype.errors -326 * @type Array -327 * @see Report#addError -328 */ -329 this.errors = []; -330 -331 /** -332 * A hash table of every instance and what schemas were validated against it. -333 * <p> -334 * The key of each item in the table is the URI of the instance that was validated. -335 * The value of this key is an array of strings of URIs of the schema that validated it. -336 * </p> -337 * -338 * @name Report.prototype.validated -339 * @type Object -340 * @see Report#registerValidation -341 * @see Report#isValidatedBy -342 */ -343 this.validated = {}; -344 -345 /** -346 * If the report is generated by {@link Environment#validate}, this field is the generated instance. -347 * -348 * @name Report.prototype.instance -349 * @type JSONInstance -350 * @see Environment#validate -351 */ -352 -353 /** -354 * If the report is generated by {@link Environment#validate}, this field is the generated schema. -355 * -356 * @name Report.prototype.schema -357 * @type JSONSchema -358 * @see Environment#validate -359 */ -360 -361 /** -362 * If the report is generated by {@link Environment#validate}, this field is the schema's schema. -363 * This value is the same as calling <code>schema.getSchema()</code>. -364 * -365 * @name Report.prototype.schemaSchema -366 * @type JSONSchema -367 * @see Environment#validate -368 * @see JSONSchema#getSchema -369 */ -370 } -371 -372 /** -373 * Adds a {@link ValidationError} object to the <a href="#errors"><code>errors</code></a> field. -374 * -375 * @param {JSONInstance} instance The instance that is invalid -376 * @param {JSONSchema} schema The schema that was validating the instance -377 * @param {String} attr The attribute that failed to validated -378 * @param {String} message A user-friendly message on why the schema attribute failed to validate the instance -379 * @param {Any} details The value of the schema attribute -380 */ -381 -382 Report.prototype.addError = function (instance, schema, attr, message, details) { -383 this.errors.push({ -384 uri : instance.getURI(), -385 schemaUri : schema.getURI(), -386 attribute : attr, -387 message : message, -388 details : details -389 }); -390 }; -391 -392 /** -393 * Registers that the provided instance URI has been validated by the provided schema URI. -394 * This is recorded in the <a href="#validated"><code>validated</code></a> field. -395 * -396 * @param {String} uri The URI of the instance that was validated -397 * @param {String} schemaUri The URI of the schema that validated the instance -398 */ -399 -400 Report.prototype.registerValidation = function (uri, schemaUri) { -401 if (!this.validated[uri]) { -402 this.validated[uri] = [ schemaUri ]; -403 } else { -404 this.validated[uri].push(schemaUri); -405 } -406 }; +268 function Report() { +269 /** +270 * An array of {@link ValidationError} objects that define all the errors generated by the schema against the instance. +271 * +272 * @name Report.prototype.errors +273 * @type Array +274 * @see Report#addError +275 */ +276 this.errors = []; +277 +278 /** +279 * A hash table of every instance and what schemas were validated against it. +280 * <p> +281 * The key of each item in the table is the URI of the instance that was validated. +282 * The value of this key is an array of strings of URIs of the schema that validated it. +283 * </p> +284 * +285 * @name Report.prototype.validated +286 * @type Object +287 * @see Report#registerValidation +288 * @see Report#isValidatedBy +289 */ +290 this.validated = {}; +291 +292 /** +293 * If the report is generated by {@link Environment#validate}, this field is the generated instance. +294 * +295 * @name Report.prototype.instance +296 * @type JSONInstance +297 * @see Environment#validate +298 */ +299 +300 /** +301 * If the report is generated by {@link Environment#validate}, this field is the generated schema. +302 * +303 * @name Report.prototype.schema +304 * @type JSONSchema +305 * @see Environment#validate +306 */ +307 +308 /** +309 * If the report is generated by {@link Environment#validate}, this field is the schema's schema. +310 * This value is the same as calling <code>schema.getSchema()</code>. +311 * +312 * @name Report.prototype.schemaSchema +313 * @type JSONSchema +314 * @see Environment#validate +315 * @see JSONSchema#getSchema +316 */ +317 } +318 +319 /** +320 * Adds a {@link ValidationError} object to the <a href="#errors"><code>errors</code></a> field. +321 * +322 * @param {JSONInstance} instance The instance that is invalid +323 * @param {JSONSchema} schema The schema that was validating the instance +324 * @param {String} attr The attribute that failed to validated +325 * @param {String} message A user-friendly message on why the schema attribute failed to validate the instance +326 * @param {Any} details The value of the schema attribute +327 */ +328 +329 Report.prototype.addError = function (instance, schema, attr, message, details) { +330 this.errors.push({ +331 uri : instance.getURI(), +332 schemaUri : schema.getURI(), +333 attribute : attr, +334 message : message, +335 details : details +336 }); +337 }; +338 +339 /** +340 * Registers that the provided instance URI has been validated by the provided schema URI. +341 * This is recorded in the <a href="#validated"><code>validated</code></a> field. +342 * +343 * @param {String} uri The URI of the instance that was validated +344 * @param {String} schemaUri The URI of the schema that validated the instance +345 */ +346 +347 Report.prototype.registerValidation = function (uri, schemaUri) { +348 if (!this.validated[uri]) { +349 this.validated[uri] = [ schemaUri ]; +350 } else { +351 this.validated[uri].push(schemaUri); +352 } +353 }; +354 +355 /** +356 * Returns if an instance with the provided URI has been validated by the schema with the provided URI. +357 * +358 * @param {String} uri The URI of the instance +359 * @param {String} schemaUri The URI of a schema +360 * @returns {Boolean} If the instance has been validated by the schema. +361 */ +362 +363 Report.prototype.isValidatedBy = function (uri, schemaUri) { +364 return !!this.validated[uri] && searchArray(this.validated[uri], schemaUri) !== -1; +365 }; +366 +367 /** +368 * A wrapper class for binding an Environment, URI and helper methods to an instance. +369 * This class is most commonly instantiated with {@link Environment#createInstance}. +370 * +371 * @name JSONInstance +372 * @class +373 * @param {Environment} env The environment this instance belongs to +374 * @param {JSONInstance|Any} json The value of the instance +375 * @param {String} [uri] The URI of the instance. If undefined, the URI will be a randomly generated UUID. +376 * @param {String} [fd] The fragment delimiter for properties. If undefined, uses the environment default. +377 */ +378 +379 function JSONInstance(env, json, uri, fd) { +380 if (json instanceof JSONInstance) { +381 if (typeof fd !== "string") { +382 fd = json._fd; +383 } +384 if (typeof uri !== "string") { +385 uri = json._uri; +386 } +387 json = json._value; +388 } +389 +390 if (typeof uri !== "string") { +391 uri = "urn:uuid:" + randomUUID() + "#"; +392 } else if (uri.indexOf(":") === -1) { +393 uri = formatURI(URI.resolve("urn:uuid:" + randomUUID() + "#", uri)); +394 } +395 +396 this._env = env; +397 this._value = json; +398 this._uri = uri; +399 this._fd = fd || this._env._options["defaultFragmentDelimiter"]; +400 } +401 +402 /** +403 * Returns the environment the instance is bound to. +404 * +405 * @returns {Environment} The environment of the instance +406 */ 407 -408 /** -409 * Returns if an instance with the provided URI has been validated by the schema with the provided URI. -410 * -411 * @param {String} uri The URI of the instance -412 * @param {String} schemaUri The URI of a schema -413 * @returns {Boolean} If the instance has been validated by the schema. -414 */ -415 -416 Report.prototype.isValidatedBy = function (uri, schemaUri) { -417 return !!this.validated[uri] && searchArray(this.validated[uri], schemaUri) !== -1; -418 }; -419 -420 /** -421 * A wrapper class for binding an Environment, URI and helper methods to an instance. -422 * This class is most commonly instantiated with {@link Environment#createInstance}. -423 * -424 * @name JSONInstance -425 * @class -426 * @param {Environment} env The environment this instance belongs to -427 * @param {JSONInstance|Any} json The value of the instance -428 * @param {String} [uri] The URI of the instance. If undefined, the URI will be a randomly generated UUID. -429 * @param {String} [fd] The fragment delimiter for properties. If undefined, uses the environment default. -430 */ +408 JSONInstance.prototype.getEnvironment = function () { +409 return this._env; +410 }; +411 +412 /** +413 * Returns the name of the type of the instance. +414 * +415 * @returns {String} The name of the type of the instance +416 */ +417 +418 JSONInstance.prototype.getType = function () { +419 return typeOf(this._value); +420 }; +421 +422 /** +423 * Returns the JSON value of the instance. +424 * +425 * @returns {Any} The actual JavaScript value of the instance +426 */ +427 +428 JSONInstance.prototype.getValue = function () { +429 return this._value; +430 }; 431 -432 function JSONInstance(env, json, uri, fd) { -433 if (json instanceof JSONInstance) { -434 if (typeof fd !== "string") { -435 fd = json._fd; -436 } -437 if (typeof uri !== "string") { -438 uri = json._uri; -439 } -440 json = json._value; -441 } -442 -443 if (typeof uri !== "string") { -444 uri = "urn:uuid:" + randomUUID() + "#"; -445 } else if (uri.indexOf(":") === -1) { -446 uri = formatURI(URL.resolve("urn:uuid:" + randomUUID() + "#", uri)); -447 } -448 -449 this._env = env; -450 this._value = json; -451 this._uri = uri; -452 this._fd = fd || this._env._defaultFragmentDelimiter; -453 } -454 -455 /** -456 * Returns the environment the instance is bound to. -457 * -458 * @returns {Environment} The environment of the instance -459 */ -460 -461 JSONInstance.prototype.getEnvironment = function () { -462 return this._env; -463 }; -464 -465 /** -466 * Returns the name of the type of the instance. -467 * -468 * @returns {String} The name of the type of the instance -469 */ -470 -471 JSONInstance.prototype.getType = function () { -472 return typeOf(this._value); -473 }; -474 -475 /** -476 * Returns the JSON value of the instance. -477 * -478 * @returns {Any} The actual JavaScript value of the instance -479 */ -480 -481 JSONInstance.prototype.getValue = function () { -482 return this._value; -483 }; -484 -485 /** -486 * Returns the URI of the instance. -487 * -488 * @returns {String} The URI of the instance -489 */ -490 -491 JSONInstance.prototype.getURI = function () { -492 return this._uri; -493 }; -494 -495 /** -496 * Returns a resolved URI of a provided relative URI against the URI of the instance. -497 * -498 * @param {String} uri The relative URI to resolve -499 * @returns {String} The resolved URI -500 */ -501 -502 JSONInstance.prototype.resolveURI = function (uri) { -503 return formatURI(URL.resolve(this._uri, uri)); -504 }; -505 -506 /** -507 * Returns an array of the names of all the properties. -508 * -509 * @returns {Array} An array of strings which are the names of all the properties -510 */ -511 -512 JSONInstance.prototype.getPropertyNames = function () { -513 return keys(this._value); -514 }; -515 -516 /** -517 * Returns a {@link JSONInstance} of the value of the provided property name. -518 * -519 * @param {String} key The name of the property to fetch -520 * @returns {JSONInstance} The instance of the property value -521 */ -522 -523 JSONInstance.prototype.getProperty = function (key) { -524 var value = this._value ? this._value[key] : undefined; -525 if (value instanceof JSONInstance) { -526 return value; -527 } -528 //else -529 return new JSONInstance(this._env, value, this._uri + this._fd + escapeURIComponent(key), this._fd); -530 }; -531 -532 /** -533 * Returns all the property instances of the target instance. -534 * <p> -535 * If the target instance is an Object, then the method will return a hash table of {@link JSONInstance}s of all the properties. -536 * If the target instance is an Array, then the method will return an array of {@link JSONInstance}s of all the items. -537 * </p> -538 * -539 * @returns {Object|Array|undefined} The list of instances for all the properties -540 */ -541 -542 JSONInstance.prototype.getProperties = function () { -543 var type = typeOf(this._value), -544 self = this; -545 -546 if (type === "object") { -547 return mapObject(this._value, function (value, key) { -548 if (value instanceof JSONInstance) { -549 return value; -550 } -551 return new JSONInstance(self._env, value, self._uri + self._fd + escapeURIComponent(key), self._fd); -552 }); -553 } else if (type === "array") { -554 return mapArray(this._value, function (value, key) { -555 if (value instanceof JSONInstance) { -556 return value; -557 } -558 return new JSONInstance(self._env, value, self._uri + self._fd + escapeURIComponent(key), self._fd); -559 }); -560 } -561 }; -562 -563 /** -564 * Returns the JSON value of the provided property name. -565 * This method is a faster version of calling <code>instance.getProperty(key).getValue()</code>. -566 * -567 * @param {String} key The name of the property -568 * @returns {Any} The JavaScript value of the instance -569 * @see JSONInstance#getProperty -570 * @see JSONInstance#getValue -571 */ -572 -573 JSONInstance.prototype.getValueOfProperty = function (key) { -574 if (this._value) { -575 if (this._value[key] instanceof JSONInstance) { -576 return this._value[key]._value; -577 } -578 return this._value[key]; -579 } -580 }; -581 -582 /** -583 * Return if the provided value is the same as the value of the instance. -584 * -585 * @param {JSONInstance|Any} instance The value to compare -586 * @returns {Boolean} If both the instance and the value match -587 */ -588 -589 JSONInstance.prototype.equals = function (instance) { -590 if (instance instanceof JSONInstance) { -591 return this._value === instance._value; -592 } -593 //else -594 return this._value === instance; -595 }; -596 -597 /** -598 * This class binds a {@link JSONInstance} with a {@link JSONSchema} to provided context aware methods. -599 * -600 * @name JSONSchema -601 * @class -602 * @param {Environment} env The environment this schema belongs to -603 * @param {JSONInstance|Any} json The value of the schema -604 * @param {String} [uri] The URI of the schema. If undefined, the URI will be a randomly generated UUID. -605 * @param {JSONSchema|Boolean} [schema] The schema to bind to the instance. If <code>undefined</code>, the environment's default schema will be used. If <code>true</code>, the instance's schema will be itself. -606 * @extends JSONInstance -607 */ -608 -609 function JSONSchema(env, json, uri, schema) { -610 var fr; -611 JSONInstance.call(this, env, json, uri); -612 -613 if (schema === true) { -614 this._schema = this; -615 } else if (json instanceof JSONSchema && !(schema instanceof JSONSchema)) { -616 this._schema = json._schema; //TODO: Make sure cross environments don't mess everything up -617 } else { -618 this._schema = schema instanceof JSONSchema ? schema : this._env.getDefaultSchema() || JSONSchema.createEmptySchema(this._env); -619 } -620 -621 //determine fragment delimiter from schema -622 fr = this._schema.getValueOfProperty("fragmentResolution"); -623 if (fr === "dot-delimited") { -624 this._fd = "."; -625 } else if (fr === "slash-delimited") { -626 this._fd = "/"; -627 } -628 } -629 -630 JSONSchema.prototype = createObject(JSONInstance.prototype); -631 -632 /** -633 * Creates an empty schema. -634 * -635 * @param {Environment} env The environment of the schema -636 * @returns {JSONSchema} The empty schema, who's schema is itself. -637 */ -638 -639 JSONSchema.createEmptySchema = function (env) { -640 var schema = createObject(JSONSchema.prototype); -641 JSONInstance.call(schema, env, {}, undefined, undefined); -642 schema._schema = schema; -643 return schema; +432 /** +433 * Returns the URI of the instance. +434 * +435 * @returns {String} The URI of the instance +436 */ +437 +438 JSONInstance.prototype.getURI = function () { +439 return this._uri; +440 }; +441 +442 /** +443 * Returns a resolved URI of a provided relative URI against the URI of the instance. +444 * +445 * @param {String} uri The relative URI to resolve +446 * @returns {String} The resolved URI +447 */ +448 +449 JSONInstance.prototype.resolveURI = function (uri) { +450 return formatURI(URI.resolve(this._uri, uri)); +451 }; +452 +453 /** +454 * Returns an array of the names of all the properties. +455 * +456 * @returns {Array} An array of strings which are the names of all the properties +457 */ +458 +459 JSONInstance.prototype.getPropertyNames = function () { +460 return keys(this._value); +461 }; +462 +463 /** +464 * Returns a {@link JSONInstance} of the value of the provided property name. +465 * +466 * @param {String} key The name of the property to fetch +467 * @returns {JSONInstance} The instance of the property value +468 */ +469 +470 JSONInstance.prototype.getProperty = function (key) { +471 var value = this._value ? this._value[key] : undefined; +472 if (value instanceof JSONInstance) { +473 return value; +474 } +475 //else +476 return new JSONInstance(this._env, value, this._uri + this._fd + escapeURIComponent(key), this._fd); +477 }; +478 +479 /** +480 * Returns all the property instances of the target instance. +481 * <p> +482 * If the target instance is an Object, then the method will return a hash table of {@link JSONInstance}s of all the properties. +483 * If the target instance is an Array, then the method will return an array of {@link JSONInstance}s of all the items. +484 * </p> +485 * +486 * @returns {Object|Array|undefined} The list of instances for all the properties +487 */ +488 +489 JSONInstance.prototype.getProperties = function () { +490 var type = typeOf(this._value), +491 self = this; +492 +493 if (type === "object") { +494 return mapObject(this._value, function (value, key) { +495 if (value instanceof JSONInstance) { +496 return value; +497 } +498 return new JSONInstance(self._env, value, self._uri + self._fd + escapeURIComponent(key), self._fd); +499 }); +500 } else if (type === "array") { +501 return mapArray(this._value, function (value, key) { +502 if (value instanceof JSONInstance) { +503 return value; +504 } +505 return new JSONInstance(self._env, value, self._uri + self._fd + escapeURIComponent(key), self._fd); +506 }); +507 } +508 }; +509 +510 /** +511 * Returns the JSON value of the provided property name. +512 * This method is a faster version of calling <code>instance.getProperty(key).getValue()</code>. +513 * +514 * @param {String} key The name of the property +515 * @returns {Any} The JavaScript value of the instance +516 * @see JSONInstance#getProperty +517 * @see JSONInstance#getValue +518 */ +519 +520 JSONInstance.prototype.getValueOfProperty = function (key) { +521 if (this._value) { +522 if (this._value[key] instanceof JSONInstance) { +523 return this._value[key]._value; +524 } +525 return this._value[key]; +526 } +527 }; +528 +529 /** +530 * Return if the provided value is the same as the value of the instance. +531 * +532 * @param {JSONInstance|Any} instance The value to compare +533 * @returns {Boolean} If both the instance and the value match +534 */ +535 +536 JSONInstance.prototype.equals = function (instance) { +537 if (instance instanceof JSONInstance) { +538 return this._value === instance._value; +539 } +540 //else +541 return this._value === instance; +542 }; +543 +544 /** +545 * Warning: Not a generic clone function +546 * Produces a JSV acceptable clone +547 */ +548 +549 function clone(obj, deep) { +550 var newObj, x; +551 +552 if (obj instanceof JSONInstance) { +553 obj = obj.getValue(); +554 } +555 +556 switch (typeOf(obj)) { +557 case "object": +558 if (deep) { +559 newObj = {}; +560 for (x in obj) { +561 if (obj[x] !== O[x]) { +562 newObj[x] = clone(obj[x], deep); +563 } +564 } +565 return newObj; +566 } else { +567 return createObject(obj); +568 } +569 break; +570 case "array": +571 if (deep) { +572 newObj = new Array(obj.length); +573 x = obj.length; +574 while (--x >= 0) { +575 newObj[x] = clone(obj[x], deep); +576 } +577 return newObj; +578 } else { +579 return Array.pototype.slice.call(obj); +580 } +581 break; +582 default: +583 return obj; +584 } +585 } +586 +587 /** +588 * This class binds a {@link JSONInstance} with a {@link JSONSchema} to provided context aware methods. +589 * +590 * @name JSONSchema +591 * @class +592 * @param {Environment} env The environment this schema belongs to +593 * @param {JSONInstance|Any} json The value of the schema +594 * @param {String} [uri] The URI of the schema. If undefined, the URI will be a randomly generated UUID. +595 * @param {JSONSchema|Boolean} [schema] The schema to bind to the instance. If <code>undefined</code>, the environment's default schema will be used. If <code>true</code>, the instance's schema will be itself. +596 * @extends JSONInstance +597 */ +598 +599 function JSONSchema(env, json, uri, schema) { +600 var fr; +601 JSONInstance.call(this, env, json, uri); +602 +603 if (schema === true) { +604 this._schema = this; +605 } else if (json instanceof JSONSchema && !(schema instanceof JSONSchema)) { +606 this._schema = json._schema; //TODO: Make sure cross environments don't mess everything up +607 } else { +608 this._schema = schema instanceof JSONSchema ? schema : this._env.getDefaultSchema() || JSONSchema.createEmptySchema(this._env); +609 } +610 +611 //determine fragment delimiter from schema +612 fr = this._schema.getValueOfProperty("fragmentResolution"); +613 if (fr === "dot-delimited") { +614 this._fd = "."; +615 } else if (fr === "slash-delimited") { +616 this._fd = "/"; +617 } +618 } +619 +620 JSONSchema.prototype = createObject(JSONInstance.prototype); +621 +622 /** +623 * Creates an empty schema. +624 * +625 * @param {Environment} env The environment of the schema +626 * @returns {JSONSchema} The empty schema, who's schema is itself. +627 */ +628 +629 JSONSchema.createEmptySchema = function (env) { +630 var schema = createObject(JSONSchema.prototype); +631 JSONInstance.call(schema, env, {}, undefined, undefined); +632 schema._schema = schema; +633 return schema; +634 }; +635 +636 /** +637 * Returns the schema of the schema. +638 * +639 * @returns {JSONSchema} The schema of the schema +640 */ +641 +642 JSONSchema.prototype.getSchema = function () { +643 return this._schema; 644 }; 645 646 /** -647 * Returns the schema of the schema. -648 * -649 * @returns {JSONSchema} The schema of the schema -650 */ -651 -652 JSONSchema.prototype.getSchema = function () { -653 return this._schema; -654 }; -655 -656 /** -657 * Returns the value of the provided attribute name. -658 * <p> -659 * This method is different from {@link JSONInstance#getProperty} as the named property -660 * is converted using a parser defined by the schema's schema before being returned. This -661 * makes the return value of this method attribute dependent. -662 * </p> -663 * -664 * @param {String} key The name of the attribute -665 * @param {Any} [arg] Some attribute parsers accept special arguments for returning resolved values. This is attribute dependent. -666 * @returns {JSONSchema|Any} The value of the attribute -667 */ -668 -669 JSONSchema.prototype.getAttribute = function (key, arg) { -670 if (this._attributes && !arg) { -671 return this._attributes[key]; -672 } -673 -674 var schemaProperty = this._schema.getProperty("properties").getProperty(key), -675 parser = schemaProperty.getValueOfProperty("parser"), -676 property = this.getProperty(key); -677 if (typeof parser === "function") { -678 return parser(property, schemaProperty, arg); -679 } -680 //else -681 return property.getValue(); -682 }; -683 -684 /** -685 * Convenience method for retrieving a link or link object from a schema. -686 * This method is the same as calling <code>schema.getAttribute("links", [rel, instance])[0];</code>. -687 * -688 * @param {String} rel The link relationship -689 * @param {JSONInstance} [instance] The instance to resolve any URIs from -690 * @returns {String|Object|undefined} If <code>instance</code> is provided, a string containing the resolve URI of the link is returned. -691 * If <code>instance</code> is not provided, a link object is returned with details of the link. -692 * If no link with the provided relationship exists, <code>undefined</code> is returned. -693 * @see JSONSchema#getAttribute -694 */ -695 -696 JSONSchema.prototype.getLink = function (rel, instance) { -697 var schemaLinks = this.getAttribute("links", [rel, instance]); -698 if (schemaLinks && schemaLinks.length && schemaLinks[schemaLinks.length - 1]) { -699 return schemaLinks[schemaLinks.length - 1]; -700 } +647 * Returns the value of the provided attribute name. +648 * <p> +649 * This method is different from {@link JSONInstance#getProperty} as the named property +650 * is converted using a parser defined by the schema's schema before being returned. This +651 * makes the return value of this method attribute dependent. +652 * </p> +653 * +654 * @param {String} key The name of the attribute +655 * @param {Any} [arg] Some attribute parsers accept special arguments for returning resolved values. This is attribute dependent. +656 * @returns {JSONSchema|Any} The value of the attribute +657 */ +658 +659 JSONSchema.prototype.getAttribute = function (key, arg) { +660 if (this._attributes && !arg) { +661 return this._attributes[key]; +662 } +663 +664 var schemaProperty = this._schema.getProperty("properties").getProperty(key), +665 parser = schemaProperty.getValueOfProperty("parser"), +666 property = this.getProperty(key); +667 if (typeof parser === "function") { +668 return parser(property, schemaProperty, arg); +669 } +670 //else +671 return property.getValue(); +672 }; +673 +674 /** +675 * Returns all the attributes of the schema. +676 * +677 * @returns {Object} A map of all parsed attribute values +678 */ +679 +680 JSONSchema.prototype.getAttributes = function () { +681 var properties, schemaProperties, key, schemaProperty, parser; +682 +683 if (!this._attributes && this.getType() === "object") { +684 properties = this.getProperties(); +685 schemaProperties = this._schema.getProperty("properties"); +686 this._attributes = {}; +687 for (key in properties) { +688 if (properties[key] !== O[key]) { +689 schemaProperty = schemaProperties && schemaProperties.getProperty(key); +690 parser = schemaProperty && schemaProperty.getValueOfProperty("parser"); +691 if (typeof parser === "function") { +692 this._attributes[key] = parser(properties[key], schemaProperty); +693 } else { +694 this._attributes[key] = properties[key].getValue(); +695 } +696 } +697 } +698 } +699 +700 return clone(this._attributes, false); 701 }; 702 703 /** -704 * Validates the provided instance against the target schema and returns a {@link Report}. -705 * -706 * @param {JSONInstance|Any} instance The instance to validate; may be a {@link JSONInstance} or any JavaScript value -707 * @param {Report} [report] A {@link Report} to concatenate the result of the validation to. If <code>undefined</code>, a new {@link Report} is created. -708 * @param {JSONInstance} [parent] The parent/containing instance of the provided instance -709 * @param {JSONSchema} [parentSchema] The schema of the parent/containing instance -710 * @returns {Report} The result of the validation -711 */ -712 -713 JSONSchema.prototype.validate = function (instance, report, parent, parentSchema) { -714 var validator = this._schema.getValueOfProperty("validator"); -715 -716 if (!(instance instanceof JSONInstance)) { -717 instance = this.getEnvironment().createInstance(instance); -718 } -719 -720 if (!(report instanceof Report)) { -721 report = new Report(); -722 } -723 -724 if (typeof validator === "function" && !report.isValidatedBy(instance.getURI(), this.getURI())) { -725 report.registerValidation(instance.getURI(), this.getURI()); -726 validator(instance, this, this._schema, report, parent, parentSchema); -727 } -728 -729 return report; -730 }; -731 -732 /** -733 * An Environment is a sandbox of schemas thats behavior is different from other environments. -734 * -735 * @name Environment -736 * @class -737 */ -738 -739 function Environment() { -740 this._id = randomUUID(); -741 this._schemas = {}; -742 this._defaultSchemaURI = ""; -743 this._defaultFragmentDelimiter = "/"; -744 } -745 -746 /** -747 * Returns a clone of the target environment. -748 * -749 * @returns {Environment} A new {@link Environment} that is a exact copy of the target environment -750 */ +704 * Convenience method for retrieving a link or link object from a schema. +705 * This method is the same as calling <code>schema.getAttribute("links", [rel, instance])[0];</code>. +706 * +707 * @param {String} rel The link relationship +708 * @param {JSONInstance} [instance] The instance to resolve any URIs from +709 * @returns {String|Object|undefined} If <code>instance</code> is provided, a string containing the resolve URI of the link is returned. +710 * If <code>instance</code> is not provided, a link object is returned with details of the link. +711 * If no link with the provided relationship exists, <code>undefined</code> is returned. +712 * @see JSONSchema#getAttribute +713 */ +714 +715 JSONSchema.prototype.getLink = function (rel, instance) { +716 var schemaLinks = this.getAttribute("links", [rel, instance]); +717 if (schemaLinks && schemaLinks.length && schemaLinks[schemaLinks.length - 1]) { +718 return schemaLinks[schemaLinks.length - 1]; +719 } +720 }; +721 +722 /** +723 * Validates the provided instance against the target schema and returns a {@link Report}. +724 * +725 * @param {JSONInstance|Any} instance The instance to validate; may be a {@link JSONInstance} or any JavaScript value +726 * @param {Report} [report] A {@link Report} to concatenate the result of the validation to. If <code>undefined</code>, a new {@link Report} is created. +727 * @param {JSONInstance} [parent] The parent/containing instance of the provided instance +728 * @param {JSONSchema} [parentSchema] The schema of the parent/containing instance +729 * @param {String} [name] The name of the parent object's property that references the instance +730 * @returns {Report} The result of the validation +731 */ +732 +733 JSONSchema.prototype.validate = function (instance, report, parent, parentSchema, name) { +734 var validator = this._schema.getValueOfProperty("validator"); +735 +736 if (!(instance instanceof JSONInstance)) { +737 instance = this.getEnvironment().createInstance(instance); +738 } +739 +740 if (!(report instanceof Report)) { +741 report = new Report(); +742 } +743 +744 if (typeof validator === "function" && !report.isValidatedBy(instance.getURI(), this.getURI())) { +745 report.registerValidation(instance.getURI(), this.getURI()); +746 validator(instance, this, this._schema, report, parent, parentSchema, name); +747 } +748 +749 return report; +750 }; 751 -752 Environment.prototype.clone = function () { -753 var env = new Environment(); -754 env._schemas = createObject(this._schemas); -755 env._defaultSchemaURI = this._defaultSchemaURI; -756 env._defaultFragmentDelimiter = this._defaultFragmentDelimiter; -757 -758 return env; -759 }; -760 -761 /** -762 * Returns a new {@link JSONInstance} of the provided data. -763 * -764 * @param {JSONInstance|Any} data The value of the instance -765 * @param {String} [uri] The URI of the instance. If undefined, the URI will be a randomly generated UUID. -766 * @returns {JSONInstance} A new {@link JSONInstance} from the provided data -767 */ -768 -769 Environment.prototype.createInstance = function (data, uri) { -770 var instance; -771 uri = formatURI(uri); -772 -773 if (data instanceof JSONInstance && (!uri || data.getURI() === uri)) { -774 return data; -775 } -776 //else -777 instance = new JSONInstance(this, data, uri); -778 -779 return instance; -780 }; -781 -782 /** -783 * Creates a new {@link JSONSchema} from the provided data, and registers it with the environment. -784 * -785 * @param {JSONInstance|Any} data The value of the schema -786 * @param {JSONSchema|Boolean} [schema] The schema to bind to the instance. If <code>undefined</code>, the environment's default schema will be used. If <code>true</code>, the instance's schema will be itself. -787 * @param {String} [uri] The URI of the schema. If undefined, the URI will be a randomly generated UUID. -788 * @returns {JSONSchema} A new {@link JSONSchema} from the provided data -789 */ -790 -791 Environment.prototype.createSchema = function (data, schema, uri) { -792 var instance, -793 initializer, -794 instanceProperties, -795 schemaProperties, -796 schemaProperty, -797 parser, -798 key; -799 uri = formatURI(uri); -800 -801 if (data instanceof JSONSchema && (!uri || data._uri === uri) && (!schema || data._schema.equals(schema))) { -802 return data; -803 } -804 -805 instance = new JSONSchema(this, data, uri, schema); -806 -807 initializer = instance.getSchema().getValueOfProperty("initializer"); -808 if (typeof initializer === "function") { -809 instance = initializer(instance); -810 } -811 -812 //register schema -813 this._schemas[instance._uri] = instance; -814 -815 //build & cache the rest of the schema -816 if (!instance._attributes && instance.getType() === "object") { -817 instanceProperties = instance.getProperties(); -818 schemaProperties = instance._schema.getProperty("properties"); -819 instance._attributes = {}; -820 for (key in instanceProperties) { -821 if (instanceProperties[key] !== O[key]) { -822 schemaProperty = schemaProperties && schemaProperties.getProperty(key); -823 parser = schemaProperty && schemaProperty.getValueOfProperty("parser"); -824 if (typeof parser === "function") { -825 instance._attributes[key] = parser(instanceProperties[key], schemaProperty); -826 } else { -827 instance._attributes[key] = instanceProperties[key].getValue(); -828 } -829 } -830 } -831 } -832 -833 return instance; -834 }; -835 -836 /** -837 * Creates an empty schema. -838 * -839 * @param {Environment} env The environment of the schema -840 * @returns {JSONSchema} The empty schema, who's schema is itself. -841 */ -842 -843 Environment.prototype.createEmptySchema = function () { -844 return JSONSchema.createEmptySchema(this); -845 }; -846 -847 /** -848 * Returns the schema registered with the provided URI. -849 * -850 * @param {String} uri The absolute URI of the required schema -851 * @returns {JSONSchema|undefined} The request schema, or <code>undefined</code> if not found -852 */ -853 -854 Environment.prototype.findSchema = function (uri) { -855 return this._schemas[formatURI(uri)]; -856 }; -857 -858 /** -859 * Sets the default fragment delimiter of the environment. -860 * -861 * @param {String} fd The fragment delimiter character -862 */ -863 -864 Environment.prototype.setDefaultFragmentDelimiter = function (fd) { -865 if (typeof fd === "string" && fd.length > 0) { -866 this._defaultFragmentDelimiter = fd; -867 } -868 }; -869 -870 /** -871 * Returns the default fragment delimiter of the environment. -872 * -873 * @returns {String} The fragment delimiter character -874 */ -875 -876 Environment.prototype.getDefaultFragmentDelimiter = function () { -877 return this._defaultFragmentDelimiter; -878 }; -879 -880 /** -881 * Sets the URI of the default schema for the environment. -882 * -883 * @param {String} uri The default schema URI -884 */ -885 -886 Environment.prototype.setDefaultSchemaURI = function (uri) { -887 if (typeof uri === "string") { -888 this._defaultSchemaURI = formatURI(uri); -889 } -890 }; -891 -892 /** -893 * Returns the default schema of the environment. -894 * -895 * @returns {JSONSchema} The default schema -896 */ -897 -898 Environment.prototype.getDefaultSchema = function () { -899 return this.findSchema(this._defaultSchemaURI); -900 }; -901 -902 /** -903 * Validates both the provided schema and the provided instance, and returns a {@link Report}. -904 * If the schema fails to validate, the instance will not be validated. -905 * -906 * @param {JSONInstance|Any} instanceJSON The {@link JSONInstance} or JavaScript value to validate. -907 * @param {JSONSchema|Any} schemaJSON The {@link JSONSchema} or JavaScript value to use in the validation. This will also be validated againt the schema's schema. -908 * @returns {Report} The result of the validation -909 */ +752 /** +753 * Merges two schemas/instances together. +754 */ +755 +756 function inherits(base, extra, extension) { +757 var baseType = base instanceof JSONSchema ? "schema" : typeOf(base), +758 extraType = extra instanceof JSONSchema ? "schema" : typeOf(extra), +759 child, x; +760 +761 if (extraType === "undefined") { +762 return clone(base, true); +763 } else if (baseType === "undefined" || extraType !== baseType) { +764 return clone(extra, true); +765 } else if (extraType === "object" || extraType === "schema") { +766 if (baseType === "schema") { +767 base = base.getAttributes(); +768 extra = extra.getAttributes(); +769 if (extra["extends"] && extension && extra["extends"] instanceof JSONSchema) { +770 extra["extends"] = [ extra["extends"] ]; +771 } +772 } +773 child = clone(base, true); //this could be optimized as some properties get overwritten +774 for (x in extra) { +775 if (extra[x] !== O[x]) { +776 child[x] = inherits(base[x], extra[x], extension); +777 } +778 } +779 return child; +780 } else { +781 return clone(extra, true); +782 } +783 } +784 +785 /** +786 * An Environment is a sandbox of schemas thats behavior is different from other environments. +787 * +788 * @name Environment +789 * @class +790 */ +791 +792 function Environment() { +793 this._id = randomUUID(); +794 this._schemas = {}; +795 this._options = {}; +796 } +797 +798 /** +799 * Returns a clone of the target environment. +800 * +801 * @returns {Environment} A new {@link Environment} that is a exact copy of the target environment +802 */ +803 +804 Environment.prototype.clone = function () { +805 var env = new Environment(); +806 env._schemas = createObject(this._schemas); +807 env._options = createObject(this._options); +808 +809 return env; +810 }; +811 +812 /** +813 * Returns a new {@link JSONInstance} of the provided data. +814 * +815 * @param {JSONInstance|Any} data The value of the instance +816 * @param {String} [uri] The URI of the instance. If undefined, the URI will be a randomly generated UUID. +817 * @returns {JSONInstance} A new {@link JSONInstance} from the provided data +818 */ +819 +820 Environment.prototype.createInstance = function (data, uri) { +821 var instance; +822 uri = formatURI(uri); +823 +824 if (data instanceof JSONInstance && (!uri || data.getURI() === uri)) { +825 return data; +826 } +827 //else +828 instance = new JSONInstance(this, data, uri); +829 +830 return instance; +831 }; +832 +833 /** +834 * Creates a new {@link JSONSchema} from the provided data, and registers it with the environment. +835 * +836 * @param {JSONInstance|Any} data The value of the schema +837 * @param {JSONSchema|Boolean} [schema] The schema to bind to the instance. If <code>undefined</code>, the environment's default schema will be used. If <code>true</code>, the instance's schema will be itself. +838 * @param {String} [uri] The URI of the schema. If undefined, the URI will be a randomly generated UUID. +839 * @returns {JSONSchema} A new {@link JSONSchema} from the provided data +840 */ +841 +842 Environment.prototype.createSchema = function (data, schema, uri) { +843 var instance, +844 initializer; +845 uri = formatURI(uri); +846 +847 if (data instanceof JSONSchema && (!uri || data._uri === uri) && (!schema || data._schema.equals(schema))) { +848 return data; +849 } +850 +851 instance = new JSONSchema(this, data, uri, schema); +852 +853 initializer = instance.getSchema().getValueOfProperty("initializer"); +854 if (typeof initializer === "function") { +855 instance = initializer(instance); +856 } +857 +858 //register schema +859 this._schemas[instance._uri] = instance; +860 +861 //build & cache the rest of the schema +862 instance.getAttributes(); +863 +864 return instance; +865 }; +866 +867 /** +868 * Creates an empty schema. +869 * +870 * @param {Environment} env The environment of the schema +871 * @returns {JSONSchema} The empty schema, who's schema is itself. +872 */ +873 +874 Environment.prototype.createEmptySchema = function () { +875 return JSONSchema.createEmptySchema(this); +876 }; +877 +878 /** +879 * Returns the schema registered with the provided URI. +880 * +881 * @param {String} uri The absolute URI of the required schema +882 * @returns {JSONSchema|undefined} The request schema, or <code>undefined</code> if not found +883 */ +884 +885 Environment.prototype.findSchema = function (uri) { +886 return this._schemas[formatURI(uri)]; +887 }; +888 +889 /** +890 * Sets the specified environment option to the specified value. +891 * +892 * @param {String} name The name of the environment option to set +893 * @param {Any} value The new value of the environment option +894 */ +895 +896 Environment.prototype.setOption = function (name, value) { +897 this._options[name] = value; +898 }; +899 +900 /** +901 * Returns the specified environment option. +902 * +903 * @param {String} name The name of the environment option to set +904 * @returns {Any} The value of the environment option +905 */ +906 +907 Environment.prototype.getOption = function (name) { +908 return this._options[name]; +909 }; 910 -911 Environment.prototype.validate = function (instanceJSON, schemaJSON) { -912 var instance = this.createInstance(instanceJSON), -913 schema = this.createSchema(schemaJSON), -914 schemaSchema = schema.getSchema(), -915 report = new Report(); -916 -917 report.instance = instance; -918 report.schema = schema; -919 report.schemaSchema = schemaSchema; -920 -921 schemaSchema.validate(schema, report); -922 -923 if (report.errors.length) { -924 return report; -925 } -926 -927 return schema.validate(instance, report); -928 }; -929 +911 /** +912 * Sets the default fragment delimiter of the environment. +913 * +914 * @deprecated Use {@link Environment#setOption} with option "defaultFragmentDelimiter" +915 * @param {String} fd The fragment delimiter character +916 */ +917 +918 Environment.prototype.setDefaultFragmentDelimiter = function (fd) { +919 if (typeof fd === "string" && fd.length > 0) { +920 this._options["defaultFragmentDelimiter"] = fd; +921 } +922 }; +923 +924 /** +925 * Returns the default fragment delimiter of the environment. +926 * +927 * @deprecated Use {@link Environment#getOption} with option "defaultFragmentDelimiter" +928 * @returns {String} The fragment delimiter character +929 */ 930 -931 /** -932 * A globaly accessible object that provides the ability to create and manage {@link Environments}, -933 * as well as providing utility methods. -934 * -935 * @namespace -936 */ -937 -938 JSV = { -939 _environments : {}, -940 _defaultEnvironmentID : "", -941 -942 /** -943 * Returns if the provide value is an instance of {@link JSONInstance}. -944 * -945 * @param o The value to test -946 * @returns {Boolean} If the provide value is an instance of {@link JSONInstance} -947 */ -948 -949 isJSONInstance : function (o) { -950 return o instanceof JSONInstance; -951 }, -952 -953 /** -954 * Returns if the provide value is an instance of {@link JSONSchema}. -955 * -956 * @param o The value to test -957 * @returns {Boolean} If the provide value is an instance of {@link JSONSchema} -958 */ -959 -960 isJSONSchema : function (o) { -961 return o instanceof JSONSchema; -962 }, -963 -964 /** -965 * Creates and returns a new {@link Environment} that is a clone of the environment registered with the provided ID. -966 * If no environment ID is provided, the default environment is cloned. -967 * -968 * @param {String} [id] The ID of the environment to clone. If <code>undefined</code>, the default environment ID is used. -969 * @returns {Environment} A newly cloned {@link Environment} -970 * @throws {Error} If there is no environment registered with the provided ID -971 */ +931 Environment.prototype.getDefaultFragmentDelimiter = function () { +932 return this._options["defaultFragmentDelimiter"]; +933 }; +934 +935 /** +936 * Sets the URI of the default schema for the environment. +937 * +938 * @deprecated Use {@link Environment#setOption} with option "defaultSchemaURI" +939 * @param {String} uri The default schema URI +940 */ +941 +942 Environment.prototype.setDefaultSchemaURI = function (uri) { +943 if (typeof uri === "string") { +944 this._options["defaultSchemaURI"] = formatURI(uri); +945 } +946 }; +947 +948 /** +949 * Returns the default schema of the environment. +950 * +951 * @returns {JSONSchema} The default schema +952 */ +953 +954 Environment.prototype.getDefaultSchema = function () { +955 return this.findSchema(this._options["defaultSchemaURI"]); +956 }; +957 +958 /** +959 * Validates both the provided schema and the provided instance, and returns a {@link Report}. +960 * If the schema fails to validate, the instance will not be validated. +961 * +962 * @param {JSONInstance|Any} instanceJSON The {@link JSONInstance} or JavaScript value to validate. +963 * @param {JSONSchema|Any} schemaJSON The {@link JSONSchema} or JavaScript value to use in the validation. This will also be validated againt the schema's schema. +964 * @returns {Report} The result of the validation +965 */ +966 +967 Environment.prototype.validate = function (instanceJSON, schemaJSON) { +968 var instance = this.createInstance(instanceJSON), +969 schema = this.createSchema(schemaJSON), +970 schemaSchema = schema.getSchema(), +971 report = new Report(); 972 -973 createEnvironment : function (id) { -974 id = id || this._defaultEnvironmentID; -975 -976 if (!this._environments[id]) { -977 throw new Error("Unknown Environment ID"); -978 } -979 //else -980 return this._environments[id].clone(); -981 }, +973 report.instance = instance; +974 report.schema = schema; +975 report.schemaSchema = schemaSchema; +976 +977 schemaSchema.validate(schema, report); +978 +979 if (report.errors.length) { +980 return report; +981 } 982 -983 Environment : Environment, -984 -985 /** -986 * Registers the provided {@link Environment} with the provided ID. -987 * -988 * @param {String} id The ID of the environment -989 * @param {Environment} env The environment to register -990 */ -991 -992 registerEnvironment : function (id, env) { -993 id = id || (env || 0)._id; -994 if (id && !this._environments[id] && env instanceof Environment) { -995 env._id = id; -996 this._environments[id] = env; -997 } -998 }, -999 -1000 /** -1001 * Sets which registered ID is the default environment. -1002 * -1003 * @param {String} id The ID of the registered environment that is default -1004 * @throws {Error} If there is no registered environment with the provided ID -1005 */ -1006 -1007 setDefaultEnvironmentID : function (id) { -1008 if (typeof id === "string") { -1009 if (!this._environments[id]) { -1010 throw new Error("Unknown Environment ID"); -1011 } -1012 -1013 this._defaultEnvironmentID = id; -1014 } -1015 }, -1016 -1017 /** -1018 * Returns the ID of the default environment. -1019 * -1020 * @returns {String} The ID of the default environment -1021 */ -1022 -1023 getDefaultEnvironmentID : function () { -1024 return this._defaultEnvironmentID; -1025 }, -1026 -1027 // -1028 // Utility Functions -1029 // -1030 -1031 /** -1032 * Returns the name of the type of the provided value. -1033 * -1034 * @event //utility -1035 * @param {Any} o The value to determine the type of -1036 * @returns {String} The name of the type of the value -1037 */ -1038 typeOf : typeOf, -1039 -1040 /** -1041 * Return a new object that inherits all of the properties of the provided object. -1042 * -1043 * @event //utility -1044 * @param {Object} proto The prototype of the new object -1045 * @returns {Object} A new object that inherits all of the properties of the provided object +983 return schema.validate(instance, report); +984 }; +985 +986 +987 /** +988 * A globaly accessible object that provides the ability to create and manage {@link Environments}, +989 * as well as providing utility methods. +990 * +991 * @namespace +992 */ +993 +994 JSV = { +995 _environments : {}, +996 _defaultEnvironmentID : "", +997 +998 /** +999 * Returns if the provide value is an instance of {@link JSONInstance}. +1000 * +1001 * @param o The value to test +1002 * @returns {Boolean} If the provide value is an instance of {@link JSONInstance} +1003 */ +1004 +1005 isJSONInstance : function (o) { +1006 return o instanceof JSONInstance; +1007 }, +1008 +1009 /** +1010 * Returns if the provide value is an instance of {@link JSONSchema}. +1011 * +1012 * @param o The value to test +1013 * @returns {Boolean} If the provide value is an instance of {@link JSONSchema} +1014 */ +1015 +1016 isJSONSchema : function (o) { +1017 return o instanceof JSONSchema; +1018 }, +1019 +1020 /** +1021 * Creates and returns a new {@link Environment} that is a clone of the environment registered with the provided ID. +1022 * If no environment ID is provided, the default environment is cloned. +1023 * +1024 * @param {String} [id] The ID of the environment to clone. If <code>undefined</code>, the default environment ID is used. +1025 * @returns {Environment} A newly cloned {@link Environment} +1026 * @throws {Error} If there is no environment registered with the provided ID +1027 */ +1028 +1029 createEnvironment : function (id) { +1030 id = id || this._defaultEnvironmentID; +1031 +1032 if (!this._environments[id]) { +1033 throw new Error("Unknown Environment ID"); +1034 } +1035 //else +1036 return this._environments[id].clone(); +1037 }, +1038 +1039 Environment : Environment, +1040 +1041 /** +1042 * Registers the provided {@link Environment} with the provided ID. +1043 * +1044 * @param {String} id The ID of the environment +1045 * @param {Environment} env The environment to register 1046 */ -1047 createObject : createObject, -1048 -1049 /** -1050 * Returns a new object with each property transformed by the iterator. -1051 * -1052 * @event //utility -1053 * @param {Object} obj The object to transform -1054 * @param {Function} iterator A function that returns the new value of the provided property -1055 * @param {Object} [scope] The value of <code>this</code> in the iterator -1056 * @returns {Object} A new object with each property transformed -1057 */ -1058 mapObject : mapObject, -1059 -1060 /** -1061 * Returns a new array with each item transformed by the iterator. -1062 * -1063 * @event //utility -1064 * @param {Array} arr The array to transform -1065 * @param {Function} iterator A function that returns the new value of the provided item -1066 * @param {Object} scope The value of <code>this</code> in the iterator -1067 * @returns {Array} A new array with each item transformed -1068 */ -1069 mapArray : mapArray, -1070 -1071 /** -1072 * Returns a new array that only contains the items allowed by the iterator. -1073 * -1074 * @event //utility -1075 * @param {Array} arr The array to filter -1076 * @param {Function} iterator The function that returns true if the provided property should be added to the array -1077 * @param {Object} scope The value of <code>this</code> within the iterator -1078 * @returns {Array} A new array that contains the items allowed by the iterator -1079 */ -1080 filterArray : filterArray, -1081 -1082 /** -1083 * Returns the first index in the array that the provided item is located at. -1084 * -1085 * @event //utility -1086 * @param {Array} arr The array to search -1087 * @param {Any} o The item being searched for -1088 * @returns {Number} The index of the item in the array, or <code>-1</code> if not found -1089 */ -1090 searchArray : searchArray, -1091 -1092 /** -1093 * Returns an array representation of a value. -1094 * <ul> -1095 * <li>For array-like objects, the value will be casted as an Array type.</li> -1096 * <li>If an array is provided, the function will simply return the same array.</li> -1097 * <li>For a null or undefined value, the result will be an empty Array.</li> -1098 * <li>For all other values, the value will be the first element in a new Array. </li> -1099 * </ul> -1100 * -1101 * @event //utility -1102 * @param {Any} o The value to convert into an array -1103 * @returns {Array} The value as an array -1104 */ -1105 toArray : toArray, -1106 -1107 /** -1108 * Returns an array of the names of all properties of an object. -1109 * -1110 * @event //utility -1111 * @param {Object|Array} o The object in question -1112 * @returns {Array} The names of all properties +1047 +1048 registerEnvironment : function (id, env) { +1049 id = id || (env || 0)._id; +1050 if (id && !this._environments[id] && env instanceof Environment) { +1051 env._id = id; +1052 this._environments[id] = env; +1053 } +1054 }, +1055 +1056 /** +1057 * Sets which registered ID is the default environment. +1058 * +1059 * @param {String} id The ID of the registered environment that is default +1060 * @throws {Error} If there is no registered environment with the provided ID +1061 */ +1062 +1063 setDefaultEnvironmentID : function (id) { +1064 if (typeof id === "string") { +1065 if (!this._environments[id]) { +1066 throw new Error("Unknown Environment ID"); +1067 } +1068 +1069 this._defaultEnvironmentID = id; +1070 } +1071 }, +1072 +1073 /** +1074 * Returns the ID of the default environment. +1075 * +1076 * @returns {String} The ID of the default environment +1077 */ +1078 +1079 getDefaultEnvironmentID : function () { +1080 return this._defaultEnvironmentID; +1081 }, +1082 +1083 // +1084 // Utility Functions +1085 // +1086 +1087 /** +1088 * Returns the name of the type of the provided value. +1089 * +1090 * @event //utility +1091 * @param {Any} o The value to determine the type of +1092 * @returns {String} The name of the type of the value +1093 */ +1094 typeOf : typeOf, +1095 +1096 /** +1097 * Return a new object that inherits all of the properties of the provided object. +1098 * +1099 * @event //utility +1100 * @param {Object} proto The prototype of the new object +1101 * @returns {Object} A new object that inherits all of the properties of the provided object +1102 */ +1103 createObject : createObject, +1104 +1105 /** +1106 * Returns a new object with each property transformed by the iterator. +1107 * +1108 * @event //utility +1109 * @param {Object} obj The object to transform +1110 * @param {Function} iterator A function that returns the new value of the provided property +1111 * @param {Object} [scope] The value of <code>this</code> in the iterator +1112 * @returns {Object} A new object with each property transformed 1113 */ -1114 keys : keys, +1114 mapObject : mapObject, 1115 1116 /** -1117 * Mutates the array by pushing the provided value onto the array only if it is not already there. -1118 * +1117 * Returns a new array with each item transformed by the iterator. +1118 * 1119 * @event //utility -1120 * @param {Array} arr The array to modify -1121 * @param {Any} o The object to add to the array if it is not already there -1122 * @returns {Array} The provided array for chaining -1123 */ -1124 pushUnique : pushUnique, -1125 -1126 /** -1127 * Creates a copy of the target object. -1128 * <p> -1129 * This method will create a new instance of the target, and then mixin the properties of the target. -1130 * If <code>deep</code> is <code>true</code>, then each property will be cloned before mixin. -1131 * </p> -1132 * <p><b>Warning</b>: This is not a generic clone function, as it will only properly clone objects and arrays.</p> -1133 * -1134 * @event //utility -1135 * @param {Any} o The value to clone -1136 * @param {Boolean} [deep=false] If each property should be recursively cloned -1137 * @returns A cloned copy of the provided value -1138 */ -1139 clone : clone, -1140 -1141 /** -1142 * Generates a pseudo-random UUID. -1143 * -1144 * @event //utility -1145 * @returns {String} A new universally unique ID -1146 */ -1147 randomUUID : randomUUID, -1148 -1149 /** -1150 * Properly escapes a URI component for embedding into a URI string. -1151 * -1152 * @event //utility -1153 * @param {String} str The URI component to escape -1154 * @returns {String} The escaped URI component -1155 */ -1156 escapeURIComponent : escapeURIComponent, -1157 -1158 /** -1159 * Returns a URI that is formated for JSV. Currently, this only ensures that the URI ends with a hash tag (<code>#</code>). -1160 * -1161 * @event //utility -1162 * @param {String} uri The URI to format -1163 * @returns {String} The URI formatted for JSV -1164 */ -1165 formatURI : formatURI, -1166 -1167 /** -1168 * Attempts to merge the values of two schemas together. This method aproximately reproduces the results expected -1169 * from <code>extends</code> in JSON Schema. -1170 * -1171 * @event //utility -1172 * @param {Any} base The value to extend -1173 * @param {Any} extra The value to extend with -1174 * @param {Boolean} isSchema If the value is a schema -1175 * @returns {Any} The modified base object -1176 */ -1177 mergeSchemas : mergeSchemas -1178 }; -1179 -1180 this.JSV = JSV; //set global object -1181 exports.JSV = JSV; //export to CommonJS -1182 -1183 require("./environments"); //load default environments -1184 -1185 }()); \ No newline at end of file +1120 * @param {Array} arr The array to transform +1121 * @param {Function} iterator A function that returns the new value of the provided item +1122 * @param {Object} scope The value of <code>this</code> in the iterator +1123 * @returns {Array} A new array with each item transformed +1124 */ +1125 mapArray : mapArray, +1126 +1127 /** +1128 * Returns a new array that only contains the items allowed by the iterator. +1129 * +1130 * @event //utility +1131 * @param {Array} arr The array to filter +1132 * @param {Function} iterator The function that returns true if the provided property should be added to the array +1133 * @param {Object} scope The value of <code>this</code> within the iterator +1134 * @returns {Array} A new array that contains the items allowed by the iterator +1135 */ +1136 filterArray : filterArray, +1137 +1138 /** +1139 * Returns the first index in the array that the provided item is located at. +1140 * +1141 * @event //utility +1142 * @param {Array} arr The array to search +1143 * @param {Any} o The item being searched for +1144 * @returns {Number} The index of the item in the array, or <code>-1</code> if not found +1145 */ +1146 searchArray : searchArray, +1147 +1148 /** +1149 * Returns an array representation of a value. +1150 * <ul> +1151 * <li>For array-like objects, the value will be casted as an Array type.</li> +1152 * <li>If an array is provided, the function will simply return the same array.</li> +1153 * <li>For a null or undefined value, the result will be an empty Array.</li> +1154 * <li>For all other values, the value will be the first element in a new Array. </li> +1155 * </ul> +1156 * +1157 * @event //utility +1158 * @param {Any} o The value to convert into an array +1159 * @returns {Array} The value as an array +1160 */ +1161 toArray : toArray, +1162 +1163 /** +1164 * Returns an array of the names of all properties of an object. +1165 * +1166 * @event //utility +1167 * @param {Object|Array} o The object in question +1168 * @returns {Array} The names of all properties +1169 */ +1170 keys : keys, +1171 +1172 /** +1173 * Mutates the array by pushing the provided value onto the array only if it is not already there. +1174 * +1175 * @event //utility +1176 * @param {Array} arr The array to modify +1177 * @param {Any} o The object to add to the array if it is not already there +1178 * @returns {Array} The provided array for chaining +1179 */ +1180 pushUnique : pushUnique, +1181 +1182 /** +1183 * Creates a copy of the target object. +1184 * <p> +1185 * This method will create a new instance of the target, and then mixin the properties of the target. +1186 * If <code>deep</code> is <code>true</code>, then each property will be cloned before mixin. +1187 * </p> +1188 * <p><b>Warning</b>: This is not a generic clone function, as it will only properly clone objects and arrays.</p> +1189 * +1190 * @event //utility +1191 * @param {Any} o The value to clone +1192 * @param {Boolean} [deep=false] If each property should be recursively cloned +1193 * @returns A cloned copy of the provided value +1194 */ +1195 clone : clone, +1196 +1197 /** +1198 * Generates a pseudo-random UUID. +1199 * +1200 * @event //utility +1201 * @returns {String} A new universally unique ID +1202 */ +1203 randomUUID : randomUUID, +1204 +1205 /** +1206 * Properly escapes a URI component for embedding into a URI string. +1207 * +1208 * @event //utility +1209 * @param {String} str The URI component to escape +1210 * @returns {String} The escaped URI component +1211 */ +1212 escapeURIComponent : escapeURIComponent, +1213 +1214 /** +1215 * Returns a URI that is formated for JSV. Currently, this only ensures that the URI ends with a hash tag (<code>#</code>). +1216 * +1217 * @event //utility +1218 * @param {String} uri The URI to format +1219 * @returns {String} The URI formatted for JSV +1220 */ +1221 formatURI : formatURI, +1222 +1223 /** +1224 * Merges two schemas/instance together. +1225 * +1226 * @event //utility +1227 * @param {JSONSchema|Any} base The old value to merge +1228 * @param {JSONSchema|Any} extra The new value to merge +1229 * @param {Boolean} extension If the merge is a JSON Schema extension +1230 * @return {Any} The modified base value +1231 */ +1232 +1233 inherits : inherits +1234 }; +1235 +1236 this.JSV = JSV; //set global object +1237 exports.JSV = JSV; //export to CommonJS +1238 +1239 require("./environments"); //load default environments +1240 +1241 }()); \ No newline at end of file diff --git a/lib/jsv.js b/lib/jsv.js index 93a72fb..6dc4e5c 100644 --- a/lib/jsv.js +++ b/lib/jsv.js @@ -726,6 +726,7 @@ var exports = exports || this, * @param {Report} [report] A {@link Report} to concatenate the result of the validation to. If undefined, a new {@link Report} is created. * @param {JSONInstance} [parent] The parent/containing instance of the provided instance * @param {JSONSchema} [parentSchema] The schema of the parent/containing instance + * @param {String} [name] The name of the parent object's property that references the instance * @returns {Report} The result of the validation */