From 78610b53c733f09c4f68c74e4bab26af94a9c570 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Fri, 11 Jan 2019 13:53:10 +0800 Subject: [PATCH] MDL-62497 javascript: fix truncate.js There was some code in the charLengthAt function which was requiring that the "this" context not be null however it was unnecessary because it never uses "this" and for some reason it was being set to null after the ES6 transpiling. --- lib/amd/build/truncate.min.js | 4 ++-- lib/amd/build/truncate.min.js.map | 2 +- lib/amd/src/truncate.js | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) rewrite lib/amd/build/truncate.min.js (93%) rewrite lib/amd/build/truncate.min.js.map (99%) diff --git a/lib/amd/build/truncate.min.js b/lib/amd/build/truncate.min.js dissimilarity index 93% index 85e6619706d..7a3cd071e6d 100644 --- a/lib/amd/build/truncate.min.js +++ b/lib/amd/build/truncate.min.js @@ -1,2 +1,2 @@ -define ("core/truncate",["jquery"],function(a){var b=/(\s*\S+|\s)$/,c=/^(\S*)/,d=/\s/,e=function(a,b){if(null==this){throw TypeError()}var c=a+"",d=c.length,e=b?+b:0;if(e!=e){e=0}if(-1>=e||e>=d){return""}e=0|e;var f=c.charCodeAt(e),g,h=e+1,i=1;if(55296<=f&&56319>=f&&d>h){g=c.charCodeAt(h);if(56320<=g&&57343>=g){i=2}}return i},f=function(a){for(var b=0,c=0;c").append(b).truncate(c).html()};a.fn.truncate=function(e){if(!isNaN(parseFloat(e)))e={length:e};var h=a.extend({},a.truncate.defaults,e);return this.each(function(){var e=a(this);if(h.noBreaks)e.find("br").replaceWith(" ");var j=h.ellipsis.length,k=e.text(),l=f(k),m=l-h.length+j;if(ll){m=l-h.length}if(0>m||!m&&!h.truncated)return;a.each(e.contents().get().reverse(),function(b,c){var d=a(c),e=d.text(),i=f(e);if(i<=m){h.truncated=!0;m-=i;d.remove();return}if(3===c.nodeType){var k=i-m;k=0<=k?g(e,k):0;a(c.splitText(k)).replaceWith(h.ellipsis);return!1}d.truncate(a.extend(h,{length:i-m+j}));return!1})})};a.truncate.defaults={stripTags:!1,words:!1,keepFirstWord:!1,noBreaks:!1,length:1/0,ellipsis:"\u2026"};return{truncate:a.truncate}}); -//# sourceMappingURL=truncate.min.js.map +define ("core/truncate",["jquery"],function(a){var b=/(\s*\S+|\s)$/,c=/^(\S*)/,d=/\s/,e=function(a,b){var c=a+"",d=c.length,e=b?+b:0;if(e!=e){e=0}if(-1>=e||e>=d){return""}e=0|e;var f=c.charCodeAt(e),g,h=e+1,i=1;if(55296<=f&&56319>=f&&d>h){g=c.charCodeAt(h);if(56320<=g&&57343>=g){i=2}}return i},f=function(a){for(var b=0,c=0;c").append(b).truncate(c).html()};a.fn.truncate=function(e){if(!isNaN(parseFloat(e)))e={length:e};var h=a.extend({},a.truncate.defaults,e);return this.each(function(){var e=a(this);if(h.noBreaks)e.find("br").replaceWith(" ");var j=h.ellipsis.length,k=e.text(),l=f(k),m=l-h.length+j;if(ll){m=l-h.length}if(0>m||!m&&!h.truncated)return;a.each(e.contents().get().reverse(),function(b,c){var d=a(c),e=d.text(),i=f(e);if(i<=m){h.truncated=!0;m-=i;d.remove();return}if(3===c.nodeType){var k=i-m;k=0<=k?g(e,k):0;a(c.splitText(k)).replaceWith(h.ellipsis);return!1}d.truncate(a.extend(h,{length:i-m+j}));return!1})})};a.truncate.defaults={stripTags:!1,words:!1,keepFirstWord:!1,noBreaks:!1,length:1/0,ellipsis:"\u2026"};return{truncate:a.truncate}}); +//# sourceMappingURL=truncate.min.js.map diff --git a/lib/amd/build/truncate.min.js.map b/lib/amd/build/truncate.min.js.map dissimilarity index 99% index 5fec813433d..d50f76644be 100644 --- a/lib/amd/build/truncate.min.js.map +++ b/lib/amd/build/truncate.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/truncate.js"],"names":["define","$","chop","start","space","charLengthAt","text","position","TypeError","string","size","length","index","cuFirst","charCodeAt","cuSecond","nextIndex","len","lengthMultiByte","count","i","getSliceLength","amount","truncate","html","options","append","fn","isNaN","parseFloat","o","extend","defaults","each","self","noBreaks","find","replaceWith","ellipsisLength","ellipsis","textLength","excess","stripTags","words","sliced","slice","replaced","replace","truncated","oneWord","match","keepFirstWord","exec","contents","get","reverse","el","$el","remove","nodeType","splitAmount","splitText"],"mappings":"AAqCAA,OAAM,iBAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,IAGzBC,CAAAA,CAAI,CAAG,cAHkB,CAMzBC,CAAK,CAAG,QANiB,CASzBC,CAAK,CAAG,IATiB,CAczBC,CAAY,CAAG,SAASC,CAAT,CAAeC,CAAf,CAAyB,CAC1C,GAAY,IAAR,MAAJ,CAAkB,CAChB,KAAMC,CAAAA,SAAS,EAChB,CAHyC,GAItCC,CAAAA,CAAM,CAAUH,CAAV,GAJgC,CAKtCI,CAAI,CAAGD,CAAM,CAACE,MALwB,CAOtCC,CAAK,CAAGL,CAAQ,EAAUA,CAAV,CAAsB,CAPA,CAQ1C,GAAIK,CAAK,EAAIA,CAAb,CAAoB,CAClBA,CAAK,CAAG,CACT,CAID,GAAa,CAAC,CAAV,EAAAA,CAAK,EAAUA,CAAK,EAAIF,CAA5B,CAAkC,CAChC,MAAO,EACR,CAEDE,CAAK,CAAW,CAAR,CAAAA,CAAR,CAlB0C,GAoBtCC,CAAAA,CAAO,CAAGJ,CAAM,CAACK,UAAP,CAAkBF,CAAlB,CApB4B,CAqBtCG,CArBsC,CAsBtCC,CAAS,CAAGJ,CAAK,CAAG,CAtBkB,CAuBtCK,CAAG,CAAG,CAvBgC,CAwB1C,GACa,KAAX,EAAAJ,CAAO,EAAyB,KAAX,EAAAA,CAArB,EACAH,CAAI,CAAGM,CAFT,CAGE,CACAD,CAAQ,CAAGN,CAAM,CAACK,UAAP,CAAkBE,CAAlB,CAAX,CACA,GAAgB,KAAZ,EAAAD,CAAQ,EAA0B,KAAZ,EAAAA,CAA1B,CAA8C,CAC5CE,CAAG,CAAG,CACP,CACF,CACD,MAAOA,CAAAA,CACR,CAhD4B,CAkDzBC,CAAe,CAAG,SAASZ,CAAT,CAA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K,GANe,CAUpBQ,aAAa,GAVO,CAapBhB,QAAQ,GAbY,CAgBpBxB,MAAM,IAhBc,CAuBpB4B,QAAQ,CAAE,QAvBU,CAAtB,CA2BE,MAAO,CACHhB,QAAQ,CAAEtB,CAAC,CAACsB,QADT,CAGV,CArLK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Description of import/upgrade into Moodle:\n * 1.) Download from https://github.com/pathable/truncate\n * 2.) Copy jquery.truncate.js into lib/amd/src/truncate.js\n * 3.) Edit truncate.js to return the $.truncate function as truncate\n * 4.) Apply Moodle changes from git commit 7172b33e241c4d42cff01f78bf8570408f43fdc2\n */\n\n/**\n * Module for text truncation.\n *\n * Implementation provided by Pathable (thanks!).\n * See: https://github.com/pathable/truncate\n *\n * @module core/truncate\n * @package core\n * @class truncate\n * @copyright 2017 Pathable\n * 2017 Mathias Bynens\n * 2017 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery'], function($) {\n\n // Matches trailing non-space characters.\n var chop = /(\\s*\\S+|\\s)$/;\n\n // Matches the first word in the string.\n var start = /^(\\S*)/;\n\n // Matches any space characters.\n var space = /\\s/;\n\n // Special thanks to Mathias Bynens for the multi-byte char\n // implementation. Much love.\n // see: https://github.com/mathiasbynens/String.prototype.at/blob/master/at.js\n var charLengthAt = function(text, position) {\n if (this == null) {\n throw TypeError();\n }\n var string = String(text);\n var size = string.length;\n // `ToInteger`\n var index = position ? Number(position) : 0;\n if (index != index) { // better `isNaN`\n index = 0;\n }\n // Account for out-of-bounds indices\n // The odd lower bound is because the ToInteger operation is\n // going to round `n` to `0` for `-1 < n <= 0`.\n if (index <= -1 || index >= size) {\n return '';\n }\n // Second half of `ToInteger`\n index = index | 0;\n // Get the first code unit and code unit value\n var cuFirst = string.charCodeAt(index);\n var cuSecond;\n var nextIndex = index + 1;\n var len = 1;\n if ( // Check if it’s the start of a surrogate pair.\n cuFirst >= 0xD800 && cuFirst <= 0xDBFF && // high surrogate\n size > nextIndex // there is a next code unit\n ) {\n cuSecond = string.charCodeAt(nextIndex);\n if (cuSecond >= 0xDC00 && cuSecond <= 0xDFFF) { // low surrogate\n len = 2;\n }\n }\n return len;\n };\n\n var lengthMultiByte = function(text) {\n var count = 0;\n\n for (var i = 0; i < text.length; i += charLengthAt(text, i)) {\n count++;\n }\n\n return count;\n };\n\n var getSliceLength = function(text, amount) {\n if (!text.length) {\n return 0;\n }\n\n var length = 0;\n var count = 0;\n\n do {\n length += charLengthAt(text, length);\n count++;\n } while (length < text.length && count < amount);\n\n return length;\n };\n\n // Return a truncated html string. Delegates to $.fn.truncate.\n $.truncate = function(html, options) {\n return $('
').append(html).truncate(options).html();\n };\n\n // Truncate the contents of an element in place.\n $.fn.truncate = function(options) {\n if (!isNaN(parseFloat(options))) options = {length: options};\n var o = $.extend({}, $.truncate.defaults, options);\n\n return this.each(function() {\n var self = $(this);\n\n if (o.noBreaks) self.find('br').replaceWith(' ');\n\n var ellipsisLength = o.ellipsis.length;\n var text = self.text();\n var textLength = lengthMultiByte(text);\n var excess = textLength - o.length + ellipsisLength;\n\n if (textLength < o.length) return;\n if (o.stripTags) self.text(text);\n\n // Chop off any partial words if appropriate.\n if (o.words && excess > 0) {\n var sliced = text.slice(0, getSliceLength(text, o.length - ellipsisLength) + 1);\n var replaced = sliced.replace(chop, '');\n var truncated = lengthMultiByte(replaced);\n var oneWord = sliced.match(space) ? false : true;\n\n if (o.keepFirstWord && truncated === 0) {\n excess = textLength - lengthMultiByte(start.exec(text)[0]) - ellipsisLength;\n } else if (oneWord && truncated === 0) {\n excess = textLength - o.length + ellipsisLength;\n } else {\n excess = textLength - truncated - 1;\n }\n }\n\n // The requested length is larger than the text. No need for ellipsis.\n if (excess > textLength) {\n excess = textLength - o.length;\n }\n\n if (excess < 0 || !excess && !o.truncated) return;\n\n // Iterate over each child node in reverse, removing excess text.\n $.each(self.contents().get().reverse(), function(i, el) {\n var $el = $(el);\n var text = $el.text();\n var length = lengthMultiByte(text);\n\n // If the text is longer than the excess, remove the node and continue.\n if (length <= excess) {\n o.truncated = true;\n excess -= length;\n $el.remove();\n return;\n }\n\n // Remove the excess text and append the ellipsis.\n if (el.nodeType === 3) {\n var splitAmount = length - excess;\n splitAmount = splitAmount >= 0 ? getSliceLength(text, splitAmount) : 0;\n $(el.splitText(splitAmount)).replaceWith(o.ellipsis);\n return false;\n }\n\n // Recursively truncate child nodes.\n $el.truncate($.extend(o, {length: length - excess + ellipsisLength}));\n return false;\n });\n });\n };\n\n $.truncate.defaults = {\n\n // Strip all html elements, leaving only plain text.\n stripTags: false,\n\n // Only truncate at word boundaries.\n words: false,\n\n // When 'words' is active, keeps the first word in the string\n // even if it's longer than a target length.\n keepFirstWord: false,\n\n // Replace instances of
with a single space.\n noBreaks: false,\n\n // The maximum length of the truncated html.\n length: Infinity,\n\n // The character to use as the ellipsis. The word joiner (U+2060) can be\n // used to prevent a hanging ellipsis, but displays incorrectly in Chrome\n // on Windows 7.\n // http://code.google.com/p/chromium/issues/detail?id=68323\n //ellipsis: '\\u2026' // '\\u2060\\u2026'\n ellipsis: '\\u2026' // '\\u2060\\u2026'\n\n };\n\n return {\n truncate: $.truncate,\n };\n});\n"],"file":"truncate.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/truncate.js"],"names":["define","$","chop","start","space","charLengthAt","text","position","string","size","length","index","cuFirst","charCodeAt","cuSecond","nextIndex","len","lengthMultiByte","count","i","getSliceLength","amount","truncate","html","options","append","fn","isNaN","parseFloat","o","extend","defaults","each","self","noBreaks","find","replaceWith","ellipsisLength","ellipsis","textLength","excess","stripTags","words","sliced","slice","replaced","replace","truncated","oneWord","match","keepFirstWord","exec","contents","get","reverse","el","$el","remove","nodeType","splitAmount","splitText"],"mappings":"AAqCAA,OAAM,iBAAC,CAAC,QAAD,CAAD,CAAa,SAASC,CAAT,CAAY,IAGzBC,CAAAA,CAAI,CAAG,cAHkB,CAMzBC,CAAK,CAAG,QANiB,CASzBC,CAAK,CAAG,IATiB,CAczBC,CAAY,CAAG,SAASC,CAAT,CAAeC,CAAf,CAAyB,IACtCC,CAAAA,CAAM,CAAUF,CAAV,GADgC,CAEtCG,CAAI,CAAGD,CAAM,CAACE,MAFwB,CAItCC,CAAK,CAAGJ,CAAQ,EAAUA,CAAV,CAAsB,CAJA,CAK1C,GAAII,CAAK,EAAIA,CAAb,CAAoB,CAClBA,CAAK,CAAG,CACT,CAID,GAAa,CAAC,CAAV,EAAAA,CAAK,EAAUA,CAAK,EAAIF,CAA5B,CAAkC,CAChC,MAAO,EACR,CAEDE,CAAK,CAAW,CAAR,CAAAA,CAAR,CAf0C,GAiBtCC,CAAAA,CAAO,CAAGJ,CAAM,CAACK,UAAP,CAAkBF,CAAlB,CAjB4B,CAkBtCG,CAlBsC,CAmBtCC,CAAS,CAAGJ,CAAK,CAAG,CAnBkB,CAoBtCK,CAAG,CAAG,CApBgC,CAqB1C,GACa,KAAX,EAAAJ,CAAO,EAAyB,KAAX,EAAAA,CAArB,EACAH,CAAI,CAAGM,CAFT,CAGE,CACAD,CAAQ,CAAGN,CAAM,CAACK,UAAP,CAAkBE,CAAlB,CAAX,CACA,GAAgB,KAAZ,EAAAD,CAAQ,EAA0B,KAAZ,EAAAA,CAA1B,CAA8C,CAC5CE,CAAG,CAAG,CACP,CACF,CACD,MAAOA,CAAAA,CACR,CA7C4B,CA+CzBC,CAAe,CAAG,SAASX,CAAT,CAAe,CAGnC,OAFIY,CAAAA,CAAK,CAAG,CAEZ,CAASC,CAAC,CAAG,CAAb,CAAg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AuBpB4B,QAAQ,CAAE,QAvBU,CAAtB,CA2BE,MAAO,CACHhB,QAAQ,CAAErB,CAAC,CAACqB,QADT,CAGV,CAlLK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Description of import/upgrade into Moodle:\n * 1.) Download from https://github.com/pathable/truncate\n * 2.) Copy jquery.truncate.js into lib/amd/src/truncate.js\n * 3.) Edit truncate.js to return the $.truncate function as truncate\n * 4.) Apply Moodle changes from git commit 7172b33e241c4d42cff01f78bf8570408f43fdc2\n */\n\n/**\n * Module for text truncation.\n *\n * Implementation provided by Pathable (thanks!).\n * See: https://github.com/pathable/truncate\n *\n * @module core/truncate\n * @package core\n * @class truncate\n * @copyright 2017 Pathable\n * 2017 Mathias Bynens\n * 2017 Ryan Wyllie \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery'], function($) {\n\n // Matches trailing non-space characters.\n var chop = /(\\s*\\S+|\\s)$/;\n\n // Matches the first word in the string.\n var start = /^(\\S*)/;\n\n // Matches any space characters.\n var space = /\\s/;\n\n // Special thanks to Mathias Bynens for the multi-byte char\n // implementation. Much love.\n // see: https://github.com/mathiasbynens/String.prototype.at/blob/master/at.js\n var charLengthAt = function(text, position) {\n var string = String(text);\n var size = string.length;\n // `ToInteger`\n var index = position ? Number(position) : 0;\n if (index != index) { // better `isNaN`\n index = 0;\n }\n // Account for out-of-bounds indices\n // The odd lower bound is because the ToInteger operation is\n // going to round `n` to `0` for `-1 < n <= 0`.\n if (index <= -1 || index >= size) {\n return '';\n }\n // Second half of `ToInteger`\n index = index | 0;\n // Get the first code unit and code unit value\n var cuFirst = string.charCodeAt(index);\n var cuSecond;\n var nextIndex = index + 1;\n var len = 1;\n if ( // Check if it’s the start of a surrogate pair.\n cuFirst >= 0xD800 && cuFirst <= 0xDBFF && // high surrogate\n size > nextIndex // there is a next code unit\n ) {\n cuSecond = string.charCodeAt(nextIndex);\n if (cuSecond >= 0xDC00 && cuSecond <= 0xDFFF) { // low surrogate\n len = 2;\n }\n }\n return len;\n };\n\n var lengthMultiByte = function(text) {\n var count = 0;\n\n for (var i = 0; i < text.length; i += charLengthAt(text, i)) {\n count++;\n }\n\n return count;\n };\n\n var getSliceLength = function(text, amount) {\n if (!text.length) {\n return 0;\n }\n\n var length = 0;\n var count = 0;\n\n do {\n length += charLengthAt(text, length);\n count++;\n } while (length < text.length && count < amount);\n\n return length;\n };\n\n // Return a truncated html string. Delegates to $.fn.truncate.\n $.truncate = function(html, options) {\n return $('
').append(html).truncate(options).html();\n };\n\n // Truncate the contents of an element in place.\n $.fn.truncate = function(options) {\n if (!isNaN(parseFloat(options))) options = {length: options};\n var o = $.extend({}, $.truncate.defaults, options);\n\n return this.each(function() {\n var self = $(this);\n\n if (o.noBreaks) self.find('br').replaceWith(' ');\n\n var ellipsisLength = o.ellipsis.length;\n var text = self.text();\n var textLength = lengthMultiByte(text);\n var excess = textLength - o.length + ellipsisLength;\n\n if (textLength < o.length) return;\n if (o.stripTags) self.text(text);\n\n // Chop off any partial words if appropriate.\n if (o.words && excess > 0) {\n var sliced = text.slice(0, getSliceLength(text, o.length - ellipsisLength) + 1);\n var replaced = sliced.replace(chop, '');\n var truncated = lengthMultiByte(replaced);\n var oneWord = sliced.match(space) ? false : true;\n\n if (o.keepFirstWord && truncated === 0) {\n excess = textLength - lengthMultiByte(start.exec(text)[0]) - ellipsisLength;\n } else if (oneWord && truncated === 0) {\n excess = textLength - o.length + ellipsisLength;\n } else {\n excess = textLength - truncated - 1;\n }\n }\n\n // The requested length is larger than the text. No need for ellipsis.\n if (excess > textLength) {\n excess = textLength - o.length;\n }\n\n if (excess < 0 || !excess && !o.truncated) return;\n\n // Iterate over each child node in reverse, removing excess text.\n $.each(self.contents().get().reverse(), function(i, el) {\n var $el = $(el);\n var text = $el.text();\n var length = lengthMultiByte(text);\n\n // If the text is longer than the excess, remove the node and continue.\n if (length <= excess) {\n o.truncated = true;\n excess -= length;\n $el.remove();\n return;\n }\n\n // Remove the excess text and append the ellipsis.\n if (el.nodeType === 3) {\n var splitAmount = length - excess;\n splitAmount = splitAmount >= 0 ? getSliceLength(text, splitAmount) : 0;\n $(el.splitText(splitAmount)).replaceWith(o.ellipsis);\n return false;\n }\n\n // Recursively truncate child nodes.\n $el.truncate($.extend(o, {length: length - excess + ellipsisLength}));\n return false;\n });\n });\n };\n\n $.truncate.defaults = {\n\n // Strip all html elements, leaving only plain text.\n stripTags: false,\n\n // Only truncate at word boundaries.\n words: false,\n\n // When 'words' is active, keeps the first word in the string\n // even if it's longer than a target length.\n keepFirstWord: false,\n\n // Replace instances of
with a single space.\n noBreaks: false,\n\n // The maximum length of the truncated html.\n length: Infinity,\n\n // The character to use as the ellipsis. The word joiner (U+2060) can be\n // used to prevent a hanging ellipsis, but displays incorrectly in Chrome\n // on Windows 7.\n // http://code.google.com/p/chromium/issues/detail?id=68323\n //ellipsis: '\\u2026' // '\\u2060\\u2026'\n ellipsis: '\\u2026' // '\\u2060\\u2026'\n\n };\n\n return {\n truncate: $.truncate,\n };\n});\n"],"file":"truncate.min.js"} \ No newline at end of file diff --git a/lib/amd/src/truncate.js b/lib/amd/src/truncate.js index e43d21b35b3..75a0c5c38b9 100644 --- a/lib/amd/src/truncate.js +++ b/lib/amd/src/truncate.js @@ -50,9 +50,6 @@ define(['jquery'], function($) { // implementation. Much love. // see: https://github.com/mathiasbynens/String.prototype.at/blob/master/at.js var charLengthAt = function(text, position) { - if (this == null) { - throw TypeError(); - } var string = String(text); var size = string.length; // `ToInteger` -- 2.11.4.GIT