@wider/utils_proto
Version:
A set of extensions to basic objects giving uniform behaviour in various technical environments
205 lines (171 loc) • 18.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>Source: proto_string/contextParse.js | YDR</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-jsdoc.css">
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/tui-doc.css">
</head>
<body>
<nav class="lnb" id="lnb">
<div class="logo" style="width: 50px">
<a href="http://y-d-r.co.uk" rel="noopener noreferrer" target="_blank">
<img src="http://y-d-r.co.uk/favicon.ico" width="100%" height="100%">
</a>
</div>
<div class="title">
<h1><a href="index.html" class="link">YDR</a></h1>
<span class="version">v1.0.23</span>
</div>
<div class="search-container" id="search-container">
<input type="text" placeholder="Search">
<ul></ul>
</div>
<ol class="lnb-tab">
<li id="api-tab">
<a href="#"><h4>API</h4></a>
</li>
<li id="examples-tab">
<a href="#"><h4>Examples</h4></a>
</li>
</ol>
<div class="lnb-examples hidden"><h3>Examples</h3><ul><li><a href="tutorial-Using Markdown with ydr_HTMLencode.html">Using Markdown with ydr_HTMLencode</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Using Markdown with ydr_HTMLencode_sub"></div></li><li><a href="tutorial-Using Object Prototype extensions.html">Using Object Prototype extensions</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="Using Object Prototype extensions_sub"></div></li></ul></div><div class="lnb-api hidden"><h3>Modules</h3><ul><li><a href="module-@wider_utils_proto.html">@wider/utils_proto</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto.html#~init">init</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_array.html">@wider/utils_proto/proto_array</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_array_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_array.html#~keySort()">keySort()</a></li><li><a href="module-@wider_utils_proto_proto_array.html#~numericSortAsc()">numericSortAsc()</a></li><li><a href="module-@wider_utils_proto_proto_array.html#~permute()">permute()</a></li><li><a href="module-@wider_utils_proto_proto_array.html#~plainSortAsc()">plainSortAsc()</a></li><li><a href="module-@wider_utils_proto_proto_array.html#~plainSortDesc()">plainSortDesc()</a></li><li><a href="module-@wider_utils_proto_proto_array.html#~pushUnique()">pushUnique()</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_array_test.html">@wider/utils_proto/proto_array/test</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_array/test_sub"></div></li><li><a href="module-@wider_utils_proto_proto_date.html">@wider/utils_proto/proto_date</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_date_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_date.html#~toISOString">toISOString</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_date_test.html">@wider/utils_proto/proto_date/test</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_date/test_sub"></div></li><li><a href="module-@wider_utils_proto_proto_function.html">@wider/utils_proto/proto_function</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_function_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_function.html#~describe()">describe()</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_function_test.html">@wider/utils_proto/proto_function/test</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_function/test_sub"></div></li><li><a href="module-@wider_utils_proto_proto_number.html">@wider/utils_proto/proto_number</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_number_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_number.html#~bitsUpTo()">bitsUpTo()</a></li><li><a href="module-@wider_utils_proto_proto_number.html#~two()">two()</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_number_test.html">@wider/utils_proto/proto_number/test</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_number/test_sub"></div></li><li><a href="module-@wider_utils_proto_proto_object.html">@wider/utils_proto/proto_object</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_object_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_object.html#~assign()">assign()</a></li><li><a href="module-@wider_utils_proto_proto_object.html#~deepMerge()">deepMerge()</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_object_test.html">@wider/utils_proto/proto_object/test</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_object/test_sub"></div></li><li><a href="module-@wider_utils_proto_proto_string.html">@wider/utils_proto/proto_string</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_string_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_string.html#~asHTML()">asHTML()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~attrEncode()">attrEncode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~camelIse()">camelIse()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~checkSum()">checkSum()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~checkSumValidate()">checkSumValidate()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~contextParse()">contextParse()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~deCamelIse()">deCamelIse()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~ellipses()">ellipses()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~escape()">escape()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~extendedCharCodeFixer()">extendedCharCodeFixer()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~formStrToXMLattr()">formStrToXMLattr()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~fuzzyValue()">fuzzyValue()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~HTMLencode()">HTMLencode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~HTMLencodeInit">HTMLencodeInit</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~isHTML()">isHTML()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~isHTMLerror()">isHTMLerror()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~proper()">proper()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~regExpEncode()">regExpEncode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~replaceSafe()">replaceSafe()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~searchEncode()">searchEncode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~selectorEncode()">selectorEncode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~simpleHTMLtoPlain()">simpleHTMLtoPlain()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~standardMarkups()">standardMarkups()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~stringEncode()">stringEncode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~textSignature()">textSignature ()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~trim()">trim()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~unescape()">unescape()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~unHTMLencode()">unHTMLencode()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~wrapAsError()">wrapAsError()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~wrapAsOK()">wrapAsOK()</a></li><li><a href="module-@wider_utils_proto_proto_string.html#~XMLverify()">XMLverify()</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_string_contextParse.html">@wider/utils_proto/proto_string/contextParse</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_string/contextParse_sub"><div class="member-type">Typedef</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_string_contextParse.html#~rowId">rowId</a></li><li><a href="module-@wider_utils_proto_proto_string_contextParse.html#~wider_context">wider_context</a></li></ul></div></li><li><a href="module-@wider_utils_proto_proto_string_test.html">@wider/utils_proto/proto_string/test</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_string/test_sub"></div></li></ul></div><div class="lnb-api hidden"><h3>Classes</h3><ul><li><a href="module-@wider_utils_proto_proto_string_contextParse-ContextParse.html">ContextParse</a><button type="button" class="hidden toggle-subnav btn btn-link"> <span class="glyphicon glyphicon-plus"></span></button><div class="hidden" id="module:@wider/utils_proto/proto_string/contextParse~ContextParse_sub"><div class="member-type">Methods</div><ul class="inner"><li><a href="module-@wider_utils_proto_proto_string_contextParse-ContextParse.html#toString">toString</a></li></ul></div></li></ul></div>
</nav>
<div id="resizer"></div>
<div class="main" id="main">
<section>
<article>
<pre class="prettyprint source linenums"><code>
/** *
* @module @wider/utils_proto/proto_string/contextParse
*
* @copyright Copyright (C) 1985..2021 Martin Baker. http://y-d-r.co.uk
* @author Martin W Baker
* @license ISC Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
/**
* @typedef {objectname} rowId - the name of a unique row in the dataset - this is regardless of the table in which the row lives. Also used to identify other components in the system such as resource. Format is
*
* @property {NCName} tableName - table reference name - often the same as that tag name for the element to which it relates
* RowId_ // fixed delimiter
* number // being the nth item that was created - this is not the nth item is the current set of rows as some rows may have been deleted and the remainder are not renumbered
*[.number] // zero or more numbers, one per required child depth related to instances of a child element. Numbers here restart anew for each of the parent numbers
* `</pre>
*@example
* contactrowsRowId_2345
*/
/**
* A ydr context may be considered like a url except that is provides a reference to data, normally to a specific single attribute or its containing element, or to a collection of elements. Contexts are used pervasively to link server side XSD schema and its related data to client side processing.
*
* Just like a url - this is a reference. To use this to actually access the data to which it refers requires the use of code that is authorised to access the data
*
* Contexts can also be extended with hints as to what a application or client browser might do with the reference
*
* @typedef {object} wider_context
* @property {objectname} [urn] - the unique identifier for the database zone - as used for example in `$wider.data.find(urn)` to obtain access to a dataset related to the current login. Optional when the **id** is a system wide unique row id, mandatory otherwise.
* @property {rowId | objectname} id - a YDR @see {@link rowId} or the name of the table that holds the data
* @property {objectname} [attribute] - the name of an attribute in the selected row - if omitted then the context refers to the whole row
* @property {xpath} [xpath] - if present then defines a path from the selected row to the required child element
* @property {enum} [buttons] - possible values |pane|subPane|absent| used only in the schema document to direct the way this attribute or row might be rendered on a form
* @property {enum} [selector] - possible values |table|tableWithAttributesList|tableBase| a suggestion as to which process or report might be related to accessing this context
* @property {enum} [action] - possible values |_edit|_delete|_help| at run time as hints from the client to the server as to what to do next
* @property {string} context - stays fixed as the value originally used to create this object - to be kept static.
*
* Use `.toString()` method on this object for the new string context value if anything has changed
* @property {*} target - deprecated - do not use f
*/
/**
* @param {string} context
*
* turns a context string such as appears in @data-ydr-context in HTML into an object so that names of the components are available to the application
*
* For more information on the use of this structure see the type documentation of `wider_contextParse()`
*
* ```javascript
* "userDetails:contactrowsRowId_27:RENEW:CONTACT_MEMBERSHIP".wider_contextParse()
*
* //{
* // "urn":"userDetails",
* // "id":"contactrowsRowId_27",
* // "target":"contactrowsRowId_27",
* // "attribute":"RENEW",
* // "xpath":"CONTACT_MEMBERSHIP",
* // "context":"userDetails:contactrowsRowId_27:RENEW:CONTACT_MEMBERSHIP"
* //}
* //
* ```
*/
class ContextParse {
/**
* The documentary name for error messages of this class
*/
/**
*
* @param {string} context -the string representation of a context - same structure as the result of the `.toString()` method of this class
*/
constructor(context) {
let contextArr = context.split(":"); // note must use ":" rather than /:/ for silly aged microsoft compatibility in this regexp
this.urn = contextArr[0] || "";
this.target = /* name target deprecated always use .id*/ this.id = (contextArr[1] || "").wider_unescape(); /* a row id or the name of a table */
this.attribute = contextArr[2] || "";
this.xpath = (contextArr[3] || "").wider_unescape();
this.buttons = contextArr[4];
this.selector = contextArr[5];
this.action = contextArr[6];
this.context = context;
}
get target() {
return this.id;
}
/**
* @returns {string} the string representation of this instance of the class, being a colon delimited string of **urn**, **id**, **attribute**, **xpath**.
*
* If this object has any of **button**, **selector** or **action**, then those are also colon delimited appended to the default result
*/
toString() {
let extension = ((this.buttons || this.selector || this.action) ?
(":" + (this.buttons || "") +
((this.selector || this.action) ?
":" + (this.selector || "") +
(this.action ? ":" + this.action : "") :
"")) :
"");
return this.urn + ":" + this.id.wider_escape() + ":" + this.attribute +
((this.xpath || extension) ?
":" + this.xpath.wider_escape() + extension :
"");
}
}
ContextParse.$moduleName = "@wider/utils_proto/proto_string";
ContextParse.$moduleTitle = ContextParse.$moduleName + "data reference context parser";
export default ContextParse;</code></pre>
</article>
</section>
</div>
<footer>
<img class="logo" src="http://y-d-r.co.uk/favicon.ico" style="width: 50px">
<div class="footer-text">Copyright Dr. Martin W. Baker 1985 onwards - MIT License</div>
</footer>
<script>prettyPrint();</script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/tui-doc.js"></script>
<script src="scripts/linenumber.js"></script>
<script>
var id = '_sub'.replace(/"/g, '_');
var selectedApi = document.getElementById(id); // do not use jquery selector
var $selectedApi = $(selectedApi);
$selectedApi.removeClass('hidden');
$selectedApi.parent().find('.glyphicon').removeClass('glyphicon-plus').addClass('glyphicon-minus');
showLnbApi();
</script>
</body>
</html>