1 /*
  2  * isDigit.js - Character type is digit
  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 ctype_n
 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 a digit character in the
 28  * Latin script.<p>
 29  *
 30  * @static
 31  * @param {string|IString|number} ch character or code point to examine
 32  * @return {boolean} true if the first character is a digit character in the
 33  * Latin script.
 34  */
 35 var isDigit = function (ch) {
 36     var num;
 37     switch (typeof(ch)) {
 38         case 'number':
 39             num = ch;
 40             break;
 41         case 'string':
 42             num = IString.toCodePoint(ch, 0);
 43             break;
 44         case 'undefined':
 45             return false;
 46         default:
 47             num = ch._toCodePoint(0);
 48             break;
 49     }
 50     return ilib.data.ctype ? CType._inRange(num, 'Nd', ilib.data.ctype_n) : (num >= 0x30 && num <= 0x39);
 51 };
 52 
 53 /**
 54  * @protected
 55  * @param {boolean} sync
 56  * @param {Object|undefined} loadParams
 57  * @param {function(*)|undefined} onLoad
 58  */
 59 isDigit._init = function (sync, loadParams, onLoad) {
 60     CType._load("ctype_n", sync, loadParams, onLoad);
 61 };
 62 
 63 module.exports = isDigit;
 64