1 /*
  2  * isAlnum.js - Character type is alphanumeric
  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 var IString = require("./IString.js");
 21 var isAlpha = require("./isAlpha.js");
 22 var isDigit = require("./isDigit.js");
 23 
 24 /**
 25  * Return whether or not the first character is alphabetic or numeric.<p>
 26  *
 27  * @static
 28  * @param {string|IString|number} ch character or code point to examine
 29  * @return {boolean} true if the first character is alphabetic or numeric
 30  */
 31 var isAlnum = function (ch) {
 32     var num;
 33     switch (typeof(ch)) {
 34         case 'number':
 35             num = ch;
 36             break;
 37         case 'string':
 38             num = IString.toCodePoint(ch, 0);
 39             break;
 40         case 'undefined':
 41             return false;
 42         default:
 43             num = ch._toCodePoint(0);
 44             break;
 45     }
 46     return isAlpha(num) || isDigit(num);
 47 };
 48 
 49 /**
 50  * @protected
 51  * @param {boolean} sync
 52  * @param {Object|undefined} loadParams
 53  * @param {function(*)|undefined} onLoad
 54  */
 55 isAlnum._init = function (sync, loadParams, onLoad) {
 56     isAlpha._init(sync, loadParams, function () {
 57         isDigit._init(sync, loadParams, onLoad);
 58     });
 59 };
 60 
 61 module.exports = isAlnum;
 62