UNPKG

cubb

Version:

cubb是一种命令行的文本标记语言, 用于输出更友好的命令行文本。

45 lines 1.71 kB
/*! http://mths.be/codepointat v0.1.0 by @mathias */ if (!String.prototype.codePointAt) { (function() { 'use strict'; // 严格模式,needed to support `apply`/`call` with `undefined`/`null` var codePointAt = function(position) { if (this == null) { throw TypeError(); } var string = String(this); var size = string.length; // 变成整数 var index = position ? Number(position) : 0; if (index != index) { // better `isNaN` index = 0; } // 边界 if (index < 0 || index >= size) { return undefined; } // 第一个编码单元 var first = string.charCodeAt(index); var second; if ( // 检查是否开始 surrogate pair first >= 0xD800 && first <= 0xDBFF && // high surrogate size > index + 1 // 下一个编码单元 ) { second = string.charCodeAt(index + 1); if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; } } return first; }; if (Object.defineProperty) { Object.defineProperty(String.prototype, 'codePointAt', { 'value': codePointAt, 'configurable': true, 'writable': true }); } else { String.prototype.codePointAt = codePointAt; } }()); }