1 /* 2 * ctype.islpha.js - Character type is alphabetic 3 * 4 * Copyright © 2012-2015, 2018, JEDLSoft 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 // !data ctype_l 21 22 var ilib = require("./ilib.js"); 23 var CType = require("./CType.js"); 24 var IString = require("./IString.js"); 25 26 /** 27 * Return whether or not the first character is alphabetic.<p> 28 * 29 * @static 30 * @param {string|IString|number} ch character or code point to examine 31 * @return {boolean} true if the first character is alphabetic. 32 */ 33 var isAlpha = function (ch) { 34 var num; 35 switch (typeof(ch)) { 36 case 'number': 37 num = ch; 38 break; 39 case 'string': 40 num = IString.toCodePoint(ch, 0); 41 break; 42 case 'undefined': 43 return false; 44 default: 45 num = ch._toCodePoint(0); 46 break; 47 } 48 return ilib.data.ctype_l ? 49 (CType._inRange(num, 'Lu', ilib.data.ctype_l) || 50 CType._inRange(num, 'Ll', ilib.data.ctype_l) || 51 CType._inRange(num, 'Lt', ilib.data.ctype_l) || 52 CType._inRange(num, 'Lm', ilib.data.ctype_l) || 53 CType._inRange(num, 'Lo', ilib.data.ctype_l)) : 54 ((num >= 0x41 && num <= 0x5A) || (num >= 0x61 && num <= 0x7A)); 55 }; 56 57 /** 58 * @protected 59 * @param {boolean} sync 60 * @param {Object|undefined} loadParams 61 * @param {function(*)|undefined} onLoad 62 */ 63 isAlpha._init = function (sync, loadParams, onLoad) { 64 CType._load("ctype_l", sync, loadParams, onLoad); 65 }; 66 67 module.exports = isAlpha;