UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

101 lines (82 loc) 3.53 kB
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>The source code</title> <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" /> <script type="text/javascript" src="../resources/prettify/prettify.js"></script> <style type="text/css"> .highlight { display: block; background-color: #ddd; } </style> <script type="text/javascript"> function highlight() { document.getElementById(location.hash.replace(/#/, "")).className = "highlight"; } </script> </head> <body onload="prettyPrint(); highlight();"> <pre class="prettyprint lang-js">/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ Role(&#39;Siesta.Util.Role.CanFormatStrings&#39;, { has : { serializeFormatingPlaceholders : true }, methods : { formatString: function (string, data) { if (!data) return string var match var variables = [] var isRaw = [] var regexp = /\{(\!)?((?:\w|-|_)+?)\}/g while (match = regexp.exec(string)) { isRaw.push(match[ 1 ]) variables.push(match[ 2 ]) } var result = string Joose.A.each(variables, function (variable, index) { var varIsRaw = isRaw[ index ] result = result.replace( new RegExp(&#39;\\{&#39; + (varIsRaw ? &#39;!&#39; : &#39;&#39;) + variable + &#39;\\}&#39;, &#39;g&#39;), data.hasOwnProperty(variable) ? varIsRaw || !this.serializeFormatingPlaceholders ? data[ variable ] + &#39;&#39; : Siesta.Util.Serializer.stringify(data[ variable ]) : &#39;&#39; ) }, this) return result }, // Extract normal chars, or special keys in brackets such as [TAB], [RIGHT] or [ENTER] extractKeysAndSpecialKeys : function (string) { var KeyCodes = Siesta.Test.UserAgent.KeyCodes().keys var me = this var res = [] // either: [[SPECIAL]] (meaning plain text), [SPECIAL] (meaning special char), or any character var tokens = string.match(/(\[\[(?:\w|-){1,11}\]\])|(\[(?:\w|-){1,11}\])|([\s\S])/g) || []; Joose.A.each(tokens, function (token, index) { if (token.length &gt; 1) { var isDouble = /\[\[/.test(token) var specialKey = token.substring(isDouble ? 2 : 1, token.length - (isDouble ? 2 : 1)) var normalText = KeyCodes[ specialKey.toUpperCase() ] === undefined if (normalText || isDouble) { res.push(&#39;[&#39;) if (normalText &amp;&amp; isDouble) res.push(&#39;[&#39;) res.push.apply(res, me.extractKeysAndSpecialKeys(specialKey)) res.push(&#39;]&#39;) if (normalText &amp;&amp; isDouble) res.push(&#39;]&#39;) } else { res.push(token) } } else res.push(token) }) return res } } }) </pre> </body> </html>