1 /* 2 * isScript.js - Character type is script 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 scriptToRange 21 22 var ilib = require("./ilib.js"); 23 24 var CType = require("./CType.js"); 25 var IString = require("./IString.js"); 26 27 /** 28 * Return whether or not the first character in the given string is 29 * in the given script. The script is given as the 4-letter ISO 30 * 15924 script code.<p> 31 * 32 * @static 33 * @param {string|IString|number} ch character or code point to examine 34 * @param {string} script the 4-letter ISO 15924 to query against 35 * @return {boolean} true if the first character is in the given script, and 36 * false otherwise 37 */ 38 var isScript = function (ch, script) { 39 var num; 40 switch (typeof(ch)) { 41 case 'number': 42 num = ch; 43 break; 44 case 'string': 45 num = IString.toCodePoint(ch, 0); 46 break; 47 case 'undefined': 48 return false; 49 default: 50 num = ch._toCodePoint(0); 51 break; 52 } 53 54 return CType._inRange(num, script, ilib.data.scriptToRange); 55 }; 56 57 /** 58 * @protected 59 * @param {boolean} sync 60 * @param {Object|undefined} loadParams 61 * @param {function(*)|undefined} onLoad 62 */ 63 isScript._init = function (sync, loadParams, onLoad) { 64 CType._load("scriptToRange", sync, loadParams, onLoad); 65 }; 66 67 module.exports = isScript;