新增Insist断言
This commit is contained in:
Submodule demo/egret_demo updated: 4d55df721a...ce43caa51b
Submodule demo/laya_demo updated: 53efc1f443...f684e5a702
Submodule engine_support/egret updated: 4f4208f8b6...1e65815949
Submodule extensions/behaviourTree-ai updated: 052527601d...53bce65be7
Submodule extensions/ecs-star updated: bed93ef0e0...56e1b19fb0
31
source/bin/framework.d.ts
vendored
31
source/bin/framework.d.ts
vendored
@@ -1,3 +1,14 @@
|
||||
declare module es {
|
||||
class Insist {
|
||||
static fail(message?: string, ...args: any[]): void;
|
||||
static isTrue(condition: boolean, message?: string, ...args: any[]): void;
|
||||
static isFalse(condition: boolean, message?: string, ...args: any[]): void;
|
||||
static isNull(obj: any, message?: string, ...args: any[]): void;
|
||||
static isNotNull(obj: any, message?: string, ...args: any[]): void;
|
||||
static areEqual(first: any, second: any, message: string, ...args: any[]): void;
|
||||
static areNotEqual(first: any, second: any, message: string, ...args: any[]): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
/**
|
||||
* 执行顺序
|
||||
@@ -1418,19 +1429,6 @@ declare class StringUtils {
|
||||
/**
|
||||
* 给数字字符前面添 "0"
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* trace( StringFormat.zfill('1') );
|
||||
* // 01
|
||||
*
|
||||
* trace( StringFormat.zfill('16', 5) );
|
||||
* // 00016
|
||||
*
|
||||
* trace( StringFormat.zfill('-3', 3) );
|
||||
* // -03
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @param str 要进行处理的字符串
|
||||
* @param width 处理后字符串的长度,
|
||||
* 如果str.length >= width,将不做任何处理直接返回原始的str。
|
||||
@@ -1448,13 +1446,16 @@ declare class StringUtils {
|
||||
* 截断某段字符串
|
||||
* @param str 目标字符串
|
||||
* @param start 需要截断的起始索引
|
||||
* @param len 截断长度
|
||||
* @param en 截断长度
|
||||
* @param order 顺序,true从字符串头部开始计算,false从字符串尾巴开始结算。
|
||||
* @return 截断后的字符串
|
||||
*/
|
||||
static cutOff(str: string, start: number, len: number, order?: boolean): string;
|
||||
/**{0} 字符替换 */
|
||||
/**
|
||||
* {0} 字符替换
|
||||
*/
|
||||
static strReplace(str: string, rStr: string[]): string;
|
||||
static format(str: string, ...args: any[]): string;
|
||||
}
|
||||
declare module es {
|
||||
/** 提供帧定时信息 */
|
||||
|
||||
@@ -75,6 +75,98 @@ var __spread = (this && this.__spread) || function () {
|
||||
return ar;
|
||||
};
|
||||
var es;
|
||||
(function (es) {
|
||||
var Insist = /** @class */ (function () {
|
||||
function Insist() {
|
||||
}
|
||||
Insist.fail = function (message) {
|
||||
if (message === void 0) { message = null; }
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
if (message == null) {
|
||||
console.assert(false);
|
||||
}
|
||||
else {
|
||||
console.assert(false, StringUtils.format(message, args));
|
||||
}
|
||||
};
|
||||
Insist.isTrue = function (condition, message) {
|
||||
if (message === void 0) { message = null; }
|
||||
var args = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
args[_i - 2] = arguments[_i];
|
||||
}
|
||||
if (!condition) {
|
||||
if (message == null) {
|
||||
this.fail();
|
||||
}
|
||||
else {
|
||||
this.fail(message, args);
|
||||
}
|
||||
}
|
||||
};
|
||||
Insist.isFalse = function (condition, message) {
|
||||
if (message === void 0) { message = null; }
|
||||
var args = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
args[_i - 2] = arguments[_i];
|
||||
}
|
||||
if (message == null) {
|
||||
this.isTrue(!condition);
|
||||
}
|
||||
else {
|
||||
this.isTrue(!condition, message, args);
|
||||
}
|
||||
};
|
||||
Insist.isNull = function (obj, message) {
|
||||
if (message === void 0) { message = null; }
|
||||
var args = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
args[_i - 2] = arguments[_i];
|
||||
}
|
||||
if (message == null) {
|
||||
this.isTrue(obj == null);
|
||||
}
|
||||
else {
|
||||
this.isTrue(obj == null, message, args);
|
||||
}
|
||||
};
|
||||
Insist.isNotNull = function (obj, message) {
|
||||
if (message === void 0) { message = null; }
|
||||
var args = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
args[_i - 2] = arguments[_i];
|
||||
}
|
||||
if (message == null) {
|
||||
this.isTrue(obj != null);
|
||||
}
|
||||
else {
|
||||
this.isTrue(obj != null, message, args);
|
||||
}
|
||||
};
|
||||
Insist.areEqual = function (first, second, message) {
|
||||
var args = [];
|
||||
for (var _i = 3; _i < arguments.length; _i++) {
|
||||
args[_i - 3] = arguments[_i];
|
||||
}
|
||||
if (first != second)
|
||||
this.fail(message, args);
|
||||
};
|
||||
Insist.areNotEqual = function (first, second, message) {
|
||||
var args = [];
|
||||
for (var _i = 3; _i < arguments.length; _i++) {
|
||||
args[_i - 3] = arguments[_i];
|
||||
}
|
||||
if (first == second)
|
||||
this.fail(message, args);
|
||||
};
|
||||
return Insist;
|
||||
}());
|
||||
es.Insist = Insist;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
/**
|
||||
* 执行顺序
|
||||
@@ -3624,19 +3716,6 @@ var StringUtils = /** @class */ (function () {
|
||||
/**
|
||||
* 给数字字符前面添 "0"
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* trace( StringFormat.zfill('1') );
|
||||
* // 01
|
||||
*
|
||||
* trace( StringFormat.zfill('16', 5) );
|
||||
* // 00016
|
||||
*
|
||||
* trace( StringFormat.zfill('-3', 3) );
|
||||
* // -03
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @param str 要进行处理的字符串
|
||||
* @param width 处理后字符串的长度,
|
||||
* 如果str.length >= width,将不做任何处理直接返回原始的str。
|
||||
@@ -3682,7 +3761,7 @@ var StringUtils = /** @class */ (function () {
|
||||
* 截断某段字符串
|
||||
* @param str 目标字符串
|
||||
* @param start 需要截断的起始索引
|
||||
* @param len 截断长度
|
||||
* @param en 截断长度
|
||||
* @param order 顺序,true从字符串头部开始计算,false从字符串尾巴开始结算。
|
||||
* @return 截断后的字符串
|
||||
*/
|
||||
@@ -3706,7 +3785,9 @@ var StringUtils = /** @class */ (function () {
|
||||
}
|
||||
return newStr;
|
||||
};
|
||||
/**{0} 字符替换 */
|
||||
/**
|
||||
* {0} 字符替换
|
||||
*/
|
||||
StringUtils.strReplace = function (str, rStr) {
|
||||
var i = 0, len = rStr.length;
|
||||
for (; i < len; i++) {
|
||||
@@ -3717,6 +3798,17 @@ var StringUtils = /** @class */ (function () {
|
||||
}
|
||||
return str;
|
||||
};
|
||||
StringUtils.format = function (str) {
|
||||
var args = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
args[_i - 1] = arguments[_i];
|
||||
}
|
||||
for (var i = 0; i < args.length - 1; i++) {
|
||||
var reg = new RegExp("\\{" + i + "\\}", "gm");
|
||||
str = str.replace(reg, args[i + 1]);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
/**
|
||||
* 特殊符号字符串
|
||||
*/
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
56
source/src/Debug/Insist.ts
Normal file
56
source/src/Debug/Insist.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
module es {
|
||||
export class Insist {
|
||||
public static fail(message: string = null, ...args: any[]) {
|
||||
if (message == null) {
|
||||
console.assert(false);
|
||||
} else {
|
||||
console.assert(false, StringUtils.format(message, args));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static isTrue(condition: boolean, message: string = null, ...args: any[]) {
|
||||
if (!condition) {
|
||||
if (message == null) {
|
||||
this.fail();
|
||||
} else {
|
||||
this.fail(message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static isFalse(condition: boolean, message: string = null, ...args: any[]) {
|
||||
if (message == null) {
|
||||
this.isTrue(!condition);
|
||||
} else {
|
||||
this.isTrue(!condition, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
public static isNull(obj, message: string = null, ...args: any[]) {
|
||||
if (message == null) {
|
||||
this.isTrue(obj == null);
|
||||
} else {
|
||||
this.isTrue(obj == null, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
public static isNotNull(obj, message: string = null, ...args: any[]) {
|
||||
if (message == null) {
|
||||
this.isTrue(obj != null);
|
||||
} else {
|
||||
this.isTrue(obj != null, message, args);
|
||||
}
|
||||
}
|
||||
|
||||
public static areEqual(first, second, message: string, ...args: any[]) {
|
||||
if (first != second)
|
||||
this.fail(message, args);
|
||||
}
|
||||
|
||||
public static areNotEqual(first, second, message: string, ...args: any[]) {
|
||||
if (first == second)
|
||||
this.fail(message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,19 +131,6 @@ class StringUtils {
|
||||
/**
|
||||
* 给数字字符前面添 "0"
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* trace( StringFormat.zfill('1') );
|
||||
* // 01
|
||||
*
|
||||
* trace( StringFormat.zfill('16', 5) );
|
||||
* // 00016
|
||||
*
|
||||
* trace( StringFormat.zfill('-3', 3) );
|
||||
* // -03
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @param str 要进行处理的字符串
|
||||
* @param width 处理后字符串的长度,
|
||||
* 如果str.length >= width,将不做任何处理直接返回原始的str。
|
||||
@@ -196,7 +183,7 @@ class StringUtils {
|
||||
* 截断某段字符串
|
||||
* @param str 目标字符串
|
||||
* @param start 需要截断的起始索引
|
||||
* @param len 截断长度
|
||||
* @param en 截断长度
|
||||
* @param order 顺序,true从字符串头部开始计算,false从字符串尾巴开始结算。
|
||||
* @return 截断后的字符串
|
||||
*/
|
||||
@@ -219,7 +206,9 @@ class StringUtils {
|
||||
return newStr;
|
||||
}
|
||||
|
||||
/**{0} 字符替换 */
|
||||
/**
|
||||
* {0} 字符替换
|
||||
*/
|
||||
public static strReplace(str: string, rStr: string[]): string {
|
||||
let i: number = 0, len: number = rStr.length;
|
||||
for (; i < len; i++) {
|
||||
@@ -230,4 +219,13 @@ class StringUtils {
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
public static format(str: string, ...args: any[]) {
|
||||
for (let i = 0; i < args.length - 1; i++) {
|
||||
let reg = new RegExp("\\{" + i + "\\}", "gm");
|
||||
str = str.replace(reg, args[i + 1]);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user