@msay2/tspoet
Version:
TSPoet is a mean to create TypeScript source files.
128 lines • 3.88 kB
JavaScript
;
/**
* @ Author: Yoann Meclot. MSay2
* @ Created on: 2021-06-14 17:49:33
* @ Modified on: 2021-06-14 18:04:24
*/
/**
* Copyright (c) 2020-2021 MSay2 (Yoann Meclot) - @msay2/tspoet
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.UCharacter = exports.UString = exports.ArrayUtil = exports.Preconditions = void 0;
const Exceptions_js_1 = require("./Exceptions.js");
class Utils {
static checkNotNull(reference, message) {
if (reference == null)
throw new Exceptions_js_1.TSPoetException(message);
else
return reference;
}
}
class Preconditions {
static checkNotNull(referent, subject, type) {
return Utils.checkNotNull(referent, `Unable to add a undefined/null ${subject}. Please provide a valid ${type}.`);
}
}
exports.Preconditions = Preconditions;
class ArrayUtil {
static equals(subject, target) {
if (subject == target)
return true;
if (subject.length != target.length)
return false;
for (let i = 0; i < subject.length; i++) {
if (subject[i] != target[i])
return false;
}
return true;
}
}
exports.ArrayUtil = ArrayUtil;
/**
* The UString class is a utiliy for String argument
*
* @class UString
* @version 1.4
* @since 1.0
*/
class UString {
/**
* Check if the value is a String type
*
* @param value value to check
* @returns return true if the value is a String type
* @type {boolean}
* @since 1.0
*/
static isEmpty(value) {
return value == undefined || value == null || value.trim().length == 0;
}
/**
* Check if the argument contain the specified value
*
* @param arg the argument to verify
* @param value the value to check
* @returns return true is the argument contain the specified value
* @type {boolean}
* @since 1.4
*/
static contains(arg, value) {
return arg.indexOf(value) >= 0;
}
static toString(value) {
return "" + value;
}
/**
* Remove the last char of your value String
*
* @param value value to change
* @returns return the value changed
* @type {string}
* @since 1.2
*/
static removeLastChar(value) {
let result = null;
if ((value != null) && (value.length > 0))
result = value.substring(0, value.length - 1);
return result;
}
}
exports.UString = UString;
class UCharacter {
static getChar(c) {
return c.charCodeAt(0);
}
static toString(value) {
return String.fromCharCode(value);
}
static toLowerCase(value) {
return this.toString(value).toLowerCase().charCodeAt(0);
}
static toUpperCase(value) {
return this.toString(value).toUpperCase().charCodeAt(0);
}
static getByte(value) {
let s = "_" + value;
let b = 0;
for (let i = 1; i < s.length; i++) {
let char = s.charCodeAt(i);
b = ((b << 5) - b) + char;
b |= 0;
}
return b;
}
}
exports.UCharacter = UCharacter;
//# sourceMappingURL=Utils.js.map