Best JavaScript code snippet using wpt
assert.ts
Source:assert.ts
1/** @module */2import ErrorHelper from '@pefish/js-error'3import BigNumber from "bignumber.js";4function lte(me, val) {5 AssertUtil.canCast(me, 'bignumber')6 val = val.toString()7 const num1 = new BigNumber(me)8 const result = num1.comparedTo(val)9 return result === -1 || result === 010}11function lt (me, val) {12 AssertUtil.canCast(me, 'bignumber')13 val = val.toString()14 const num1 = new BigNumber(me)15 return num1.comparedTo(val) === -116}17function gte (me, val) {18 AssertUtil.canCast(me, 'bignumber')19 val = val.toString()20 const num1 = new BigNumber(me)21 const result = num1.comparedTo(val)22 return result === 1 || result === 023}24function gt (me, val) {25 AssertUtil.canCast(me, 'bignumber')26 val = val.toString()27 const num1 = new BigNumber(me)28 return num1.comparedTo(val) === 129}30/**31 * æè¨ç±»32 */33export default class AssertUtil {34 /**35 * ä¸è½ä¸ºç©ºï¼å
æ¬nullãundefinedã''ï¼36 * @param value {any} æ£æµå¯¹è±¡37 * @param key {string} 表示æ£æµå¯¹è±¡çkey38 * @param throw_ {boolean} æ¯å¦æé39 * @returns {boolean}40 */41 static notEmpty (value, key = null, throw_ = true) {42 if ('' === value || null === value || undefined === value) {43 if (throw_ === true) {44 throw new ErrorHelper(`notEmpty -> value: ${value}, key: ${key}`, 0)45 } else {46 return false47 }48 }49 return true50 }51 static _isIllegal (value) {52 let result = false53 if (JSON.stringify(value).includes('$')) {54 result = true55 }56 return result57 }58 /**59 * è³å°æä¸ä¸ªå¤§ååæ¯60 * @param value {any} æ£æµå¯¹è±¡61 * @param key {string} 表示æ£æµå¯¹è±¡çkey62 * @param throw_ {boolean} æ¯å¦æé63 * @returns {boolean}64 */65 static oneUpperAtLeast (value, key = null, throw_ = true) {66 if (!/[A-Z]/.test(value)) {67 if (throw_ === true) {68 throw new ErrorHelper(`oneUpperAtLeast -> value: ${value}, key: ${key}`, 0)69 } else {70 return false71 }72 }73 return true74 }75 /**76 * ä¸è½æç©ºæ ¼77 * @param value {any} æ£æµå¯¹è±¡78 * @param key {string} 表示æ£æµå¯¹è±¡çkey79 * @param throw_ {boolean} æ¯å¦æé80 * @returns {boolean}81 */82 static noSpace (value, key = null, throw_ = true) {83 if ((/\s/.test(value))) {84 if (throw_ === true) {85 throw new ErrorHelper(`noSpace -> value: ${value}, key: ${key}`, 0)86 } else {87 return false88 }89 }90 return true91 }92 /**93 * è³å°ä¸ä¸ªæ°å94 * @param value {any} æ£æµå¯¹è±¡95 * @param key {string} 表示æ£æµå¯¹è±¡çkey96 * @param throw_ {boolean} æ¯å¦æé97 * @returns {boolean}98 */99 static oneNumberAtLeast (value, key = null, throw_ = true) {100 if (!/[0-9]/.test(value)) {101 if (throw_ === true) {102 throw new ErrorHelper(`oneNumberAtLeast -> value: ${value}, key: ${key}`, 0)103 } else {104 return false105 }106 }107 return true108 }109 /**110 * è³å°ä¸ä¸ªæ ç¹ç¬¦å·111 * @param value {any} æ£æµå¯¹è±¡112 * @param key {string} 表示æ£æµå¯¹è±¡çkey113 * @param throw_ {boolean} æ¯å¦æé114 * @returns {boolean}115 */116 static oneSymbolAtLeast (value, key = null, throw_ = true) {117 if (!/[$&+,:;=?@#|'<>.^*()%!-]/.test(value)) {118 if (throw_ === true) {119 throw new ErrorHelper(`oneSymbolAtLeast -> value: ${value}, key: ${key}`, 0)120 } else {121 return false122 }123 }124 return true125 }126 static _isType (value, typeName) {127 if (typeof typeName === 'function') {128 return value instanceof typeName129 }130 let result = false131 switch (typeName) {132 case 'boolean':133 result = (typeof value === typeName)134 break135 case 'string':136 result = (typeof value === 'string')137 break138 case 'number':139 result = (typeof value === 'number') && !isNaN(Number(value))140 break141 case 'integer':142 result = (typeof value === 'number') && Number.isInteger(Number(value))143 break144 case 'object':145 if (value instanceof Object) {146 result = true147 } else {148 result = false149 }150 break151 case 'array':152 result = value instanceof Array153 break154 }155 return result156 }157 /**158 * è½å¤å¼ºè½¬159 * @param value {any} æ£æµå¯¹è±¡160 * @param expectValue {string} ææå¼161 * @param key {string} 表示æ£æµå¯¹è±¡çkey162 * @param throw_ {boolean} æ¯å¦æé163 * @returns {boolean}164 */165 static canCast (value, expectValue, key = null, throw_ = true) {166 let result = false167 switch (expectValue) {168 case 'number':169 result = !isNaN(Number(value))170 break171 case 'integer':172 result = !isNaN(Number(value)) && Number.isInteger(Number(value))173 break174 case 'bignumber':175 try {176 const BigNumber = require('bignumber.js')177 const _ = new BigNumber(value)178 result = true179 } catch (err) {180 result = false181 }182 break183 }184 if (result === false) {185 if (throw_ === true) {186 throw new ErrorHelper(`canCast -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)187 } else {188 return false189 }190 }191 return true192 }193 /**194 * å¤æç±»å195 * @param value {any} æ£æµå¯¹è±¡196 * @param expectValue {string} ææå¼197 * @param key {string} 表示æ£æµå¯¹è±¡çkey198 * @param throw_ {boolean} æ¯å¦æé199 * @returns {boolean}200 */201 static isType (value, expectValue, key = null, throw_ = true) {202 let result = false203 if (expectValue instanceof Array) {204 result = expectValue.some((type_) => {205 if (this._isIllegal(value)) {206 return false207 }208 return AssertUtil._isType(value, type_)209 })210 } else {211 result = AssertUtil._isType(value, expectValue)212 }213 if (result === false) {214 if (throw_ === true) {215 throw new ErrorHelper(`isType -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)216 } else {217 return false218 }219 }220 return true221 }222 /**223 * æ£æµæ³¨å
¥224 * @param value {any} æ£æµå¯¹è±¡225 * @param key {string} 表示æ£æµå¯¹è±¡çkey226 * @param throw_ {boolean} æ¯å¦æé227 * @returns {boolean}228 */229 static noInject (value, key = null, throw_ = true) {230 ['=', '{', '}', ',', ';', '|', '>', '<', '/', '"', '[', ']', '+', '\\'].forEach((symbol) => {231 if (value && value.toString().includes(symbol)) {232 if (throw_ === true) {233 throw new ErrorHelper(`noInject -> value: ${value}, key: ${key}`, 0)234 } else {235 return false236 }237 }238 })239 return true240 }241 /**242 * 大äºæå®å¼243 * @param value {any} æ£æµå¯¹è±¡244 * @param expectValue {number} ææå¼245 * @param key {string} 表示æ£æµå¯¹è±¡çkey246 * @param throw_ {boolean} æ¯å¦æé247 * @returns {boolean}248 */249 static gt (value, expectValue, key = null, throw_ = true) {250 if (typeof value === 'number' || !isNaN(Number(value))) {251 if (lte(value.toString(), expectValue)) {252 if (throw_ === true) {253 throw new ErrorHelper(`gt -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)254 } else {255 return false256 }257 }258 } else {259 if (throw_ === true) {260 throw new ErrorHelper(`gt -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)261 } else {262 return false263 }264 }265 return true266 }267 /**268 * 大äºæçäºæå®å¼269 * @param value {any} æ£æµå¯¹è±¡270 * @param expectValue {number} ææå¼271 * @param key {string} 表示æ£æµå¯¹è±¡çkey272 * @param throw_ {boolean} æ¯å¦æé273 * @returns {boolean}274 */275 static gte (value, expectValue, key = null, throw_ = true) {276 if (typeof value === 'number' || !isNaN(Number(value))) {277 if (lt(value.toString(), expectValue)) {278 if (throw_ === true) {279 throw new ErrorHelper(`gte -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)280 } else {281 return false282 }283 }284 } else {285 if (throw_ === true) {286 throw new ErrorHelper(`gte -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)287 } else {288 return false289 }290 }291 return true292 }293 /**294 * å°äºæå®å¼295 * @param value {any} æ£æµå¯¹è±¡296 * @param expectValue {number} ææå¼297 * @param key {string} 表示æ£æµå¯¹è±¡çkey298 * @param throw_ {boolean} æ¯å¦æé299 * @returns {boolean}300 */301 static lt (value, expectValue, key = null, throw_ = true) {302 if (typeof value === 'number' || !isNaN(Number(value))) {303 if (gte(value.toString(), expectValue)) {304 if (throw_ === true) {305 throw new ErrorHelper(`lt -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)306 } else {307 return false308 }309 }310 } else {311 if (throw_ === true) {312 throw new ErrorHelper(`lt -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)313 } else {314 return false315 }316 }317 return true318 }319 /**320 * å°äºæçäºæå®å¼321 * @param value {any} æ£æµå¯¹è±¡322 * @param expectValue {number} ææå¼323 * @param key {string} 表示æ£æµå¯¹è±¡çkey324 * @param throw_ {boolean} æ¯å¦æé325 * @returns {boolean}326 */327 static lte (value, expectValue, key = null, throw_ = true) {328 if (typeof value === 'number' || !isNaN(Number(value))) {329 if (gt(value.toString(), expectValue)) {330 if (throw_ === true) {331 throw new ErrorHelper(`lte -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)332 } else {333 return false334 }335 }336 } else {337 if (throw_ === true) {338 throw new ErrorHelper(`lte -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)339 } else {340 return false341 }342 }343 return true344 }345 /**346 * é¿åº¦å°äºæå®å¼347 * @param value {any} æ£æµå¯¹è±¡348 * @param expectValue {number} ææå¼349 * @param key {string} 表示æ£æµå¯¹è±¡çkey350 * @param throw_ {boolean} æ¯å¦æé351 * @returns {boolean}352 */353 static lengthLt (value, expectValue, key = null, throw_ = true) {354 if (value.toString().length >= expectValue) {355 if (throw_ === true) {356 throw new ErrorHelper(`lengthLt -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)357 } else {358 return false359 }360 }361 return true362 }363 /**364 * é¿åº¦å°äºæçäºæå®å¼365 * @param value {any} æ£æµå¯¹è±¡366 * @param expectValue {number} ææå¼367 * @param key {string} 表示æ£æµå¯¹è±¡çkey368 * @param throw_ {boolean} æ¯å¦æé369 * @returns {boolean}370 */371 static lengthLte (value, expectValue, key = null, throw_ = true) {372 if (value.toString().length > expectValue) {373 if (throw_ === true) {374 throw new ErrorHelper(`lengthLte -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)375 } else {376 return false377 }378 }379 return true380 }381 /**382 * é¿åº¦å¤§äºæå®å¼383 * @param value {any} æ£æµå¯¹è±¡384 * @param expectValue {number} ææå¼385 * @param key {string} 表示æ£æµå¯¹è±¡çkey386 * @param throw_ {boolean} æ¯å¦æé387 * @returns {boolean}388 */389 static lengthGt (value, expectValue, key = null, throw_ = true) {390 if (value.toString().length <= expectValue) {391 if (throw_ === true) {392 throw new ErrorHelper(`lengthGt -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)393 } else {394 return false395 }396 }397 return true398 }399 /**400 * é¿åº¦å¤§äºæçäºæå®å¼401 * @param value {any} æ£æµå¯¹è±¡402 * @param expectValue {number} ææå¼403 * @param key {string} 表示æ£æµå¯¹è±¡çkey404 * @param throw_ {boolean} æ¯å¦æé405 * @returns {boolean}406 */407 static lengthGte (value, expectValue, key = null, throw_ = true) {408 if (value.toString().length < expectValue) {409 if (throw_ === true) {410 throw new ErrorHelper(`lengthGte -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)411 } else {412 return false413 }414 }415 return true416 }417 /**418 * æ¯å¦ä»¥æå®å符串å¼å¤´419 * @param value {any} æ£æµå¯¹è±¡420 * @param expectValue {string} ææå¼421 * @param key {string} 表示æ£æµå¯¹è±¡çkey422 * @param throw_ {boolean} æ¯å¦æé423 * @returns {boolean}424 */425 static startsWith (value, expectValue, key = null, throw_ = true) {426 if (!value.toString().startsWith(expectValue)) {427 if (throw_ === true) {428 throw new ErrorHelper(`startsWith -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)429 } else {430 return false431 }432 }433 return true434 }435 /**436 * é¿åº¦çäºæå®å¼437 * @param value {any} æ£æµå¯¹è±¡438 * @param expectValue {number} ææå¼439 * @param key {string} 表示æ£æµå¯¹è±¡çkey440 * @param throw_ {boolean} æ¯å¦æé441 * @returns {boolean}442 */443 static lengthEq (value, expectValue, key = null, throw_ = true) {444 if (expectValue instanceof Array) {445 if (!expectValue.includes(value.toString().length)) {446 if (throw_ === true) {447 throw new ErrorHelper(`lengthEq -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)448 } else {449 return false450 }451 }452 } else {453 if (value.toString().length !== expectValue) {454 if (throw_ === true) {455 throw new ErrorHelper(`lengthEq -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)456 } else {457 return false458 }459 }460 }461 return true462 }463 /**464 * å
ç´ åå¨äºæå®æ°ç»ä¸465 * @param value {any} æ£æµå¯¹è±¡466 * @param expectValue {array} ææå¼467 * @param key {string} 表示æ£æµå¯¹è±¡çkey468 * @param throw_ {boolean} æ¯å¦æé469 * @returns {boolean}470 */471 static in (value, expectValue, key = null, throw_ = true) {472 if (!expectValue.includes(value)) {473 if (throw_ === true) {474 throw new ErrorHelper(`in -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)475 } else {476 return false477 }478 }479 return true480 }481 /**482 * 强çäº483 * @param value {any} æ£æµå¯¹è±¡484 * @param expectValue {any} ææå¼485 * @param key {string} 表示æ£æµå¯¹è±¡çkey486 * @param throw_ {boolean} æ¯å¦æé487 * @returns {boolean}488 */489 static is (value, expectValue, key = null, throw_ = true) {490 if (value !== expectValue) {491 if (throw_ === true) {492 throw new ErrorHelper(`is -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)493 } else {494 return false495 }496 }497 return true498 }499 /**500 * æ¯å¦æ¯æèªå®ä¹ç±»åï¼å¦emailãmobile501 * @param value {any} æ£æµå¯¹è±¡502 * @param expectValue {string} ææå¼503 * @param key {string} 表示æ£æµå¯¹è±¡çkey504 * @param throw_ {boolean} æ¯å¦æé505 * @returns {boolean}506 */507 static isCustomType(value, expectValue, key = null, throw_ = true) {508 const regexList = {509 email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,510 mobile: /^1[34578]\d{9}$/,511 }512 let result513 if (expectValue instanceof Array) {514 result = expectValue.map(regex => regexList[regex]).some(regex => regex.test(value))515 } else {516 result = regexList[expectValue].test(value)517 }518 if (result === false) {519 if (throw_ === true) {520 throw new ErrorHelper(`isCustomType -> value: ${value}, expectValue: ${expectValue}, key: ${key}`, 0)521 } else {522 return false523 }524 }525 return true526 }...
assert.d.ts
Source:assert.d.ts
1/**2 * æè¨ç±»3 */4export default class AssertUtil {5 /**6 * ä¸è½ä¸ºç©ºï¼å
æ¬nullãundefinedã''ï¼7 * @param value {any} æ£æµå¯¹è±¡8 * @param key {string} 表示æ£æµå¯¹è±¡çkey9 * @param throw_ {boolean} æ¯å¦æé10 * @returns {boolean}11 */12 static notEmpty(value: any, key?: any, throw_?: boolean): boolean;13 static _isIllegal(value: any): boolean;14 /**15 * è³å°æä¸ä¸ªå¤§ååæ¯16 * @param value {any} æ£æµå¯¹è±¡17 * @param key {string} 表示æ£æµå¯¹è±¡çkey18 * @param throw_ {boolean} æ¯å¦æé19 * @returns {boolean}20 */21 static oneUpperAtLeast(value: any, key?: any, throw_?: boolean): boolean;22 /**23 * ä¸è½æç©ºæ ¼24 * @param value {any} æ£æµå¯¹è±¡25 * @param key {string} 表示æ£æµå¯¹è±¡çkey26 * @param throw_ {boolean} æ¯å¦æé27 * @returns {boolean}28 */29 static noSpace(value: any, key?: any, throw_?: boolean): boolean;30 /**31 * è³å°ä¸ä¸ªæ°å32 * @param value {any} æ£æµå¯¹è±¡33 * @param key {string} 表示æ£æµå¯¹è±¡çkey34 * @param throw_ {boolean} æ¯å¦æé35 * @returns {boolean}36 */37 static oneNumberAtLeast(value: any, key?: any, throw_?: boolean): boolean;38 /**39 * è³å°ä¸ä¸ªæ ç¹ç¬¦å·40 * @param value {any} æ£æµå¯¹è±¡41 * @param key {string} 表示æ£æµå¯¹è±¡çkey42 * @param throw_ {boolean} æ¯å¦æé43 * @returns {boolean}44 */45 static oneSymbolAtLeast(value: any, key?: any, throw_?: boolean): boolean;46 static _isType(value: any, typeName: any): boolean;47 /**48 * è½å¤å¼ºè½¬49 * @param value {any} æ£æµå¯¹è±¡50 * @param expectValue {string} ææå¼51 * @param key {string} 表示æ£æµå¯¹è±¡çkey52 * @param throw_ {boolean} æ¯å¦æé53 * @returns {boolean}54 */55 static canCast(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;56 /**57 * å¤æç±»å58 * @param value {any} æ£æµå¯¹è±¡59 * @param expectValue {string} ææå¼60 * @param key {string} 表示æ£æµå¯¹è±¡çkey61 * @param throw_ {boolean} æ¯å¦æé62 * @returns {boolean}63 */64 static isType(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;65 /**66 * æ£æµæ³¨å
¥67 * @param value {any} æ£æµå¯¹è±¡68 * @param key {string} 表示æ£æµå¯¹è±¡çkey69 * @param throw_ {boolean} æ¯å¦æé70 * @returns {boolean}71 */72 static noInject(value: any, key?: any, throw_?: boolean): boolean;73 /**74 * 大äºæå®å¼75 * @param value {any} æ£æµå¯¹è±¡76 * @param expectValue {number} ææå¼77 * @param key {string} 表示æ£æµå¯¹è±¡çkey78 * @param throw_ {boolean} æ¯å¦æé79 * @returns {boolean}80 */81 static gt(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;82 /**83 * 大äºæçäºæå®å¼84 * @param value {any} æ£æµå¯¹è±¡85 * @param expectValue {number} ææå¼86 * @param key {string} 表示æ£æµå¯¹è±¡çkey87 * @param throw_ {boolean} æ¯å¦æé88 * @returns {boolean}89 */90 static gte(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;91 /**92 * å°äºæå®å¼93 * @param value {any} æ£æµå¯¹è±¡94 * @param expectValue {number} ææå¼95 * @param key {string} 表示æ£æµå¯¹è±¡çkey96 * @param throw_ {boolean} æ¯å¦æé97 * @returns {boolean}98 */99 static lt(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;100 /**101 * å°äºæçäºæå®å¼102 * @param value {any} æ£æµå¯¹è±¡103 * @param expectValue {number} ææå¼104 * @param key {string} 表示æ£æµå¯¹è±¡çkey105 * @param throw_ {boolean} æ¯å¦æé106 * @returns {boolean}107 */108 static lte(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;109 /**110 * é¿åº¦å°äºæå®å¼111 * @param value {any} æ£æµå¯¹è±¡112 * @param expectValue {number} ææå¼113 * @param key {string} 表示æ£æµå¯¹è±¡çkey114 * @param throw_ {boolean} æ¯å¦æé115 * @returns {boolean}116 */117 static lengthLt(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;118 /**119 * é¿åº¦å°äºæçäºæå®å¼120 * @param value {any} æ£æµå¯¹è±¡121 * @param expectValue {number} ææå¼122 * @param key {string} 表示æ£æµå¯¹è±¡çkey123 * @param throw_ {boolean} æ¯å¦æé124 * @returns {boolean}125 */126 static lengthLte(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;127 /**128 * é¿åº¦å¤§äºæå®å¼129 * @param value {any} æ£æµå¯¹è±¡130 * @param expectValue {number} ææå¼131 * @param key {string} 表示æ£æµå¯¹è±¡çkey132 * @param throw_ {boolean} æ¯å¦æé133 * @returns {boolean}134 */135 static lengthGt(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;136 /**137 * é¿åº¦å¤§äºæçäºæå®å¼138 * @param value {any} æ£æµå¯¹è±¡139 * @param expectValue {number} ææå¼140 * @param key {string} 表示æ£æµå¯¹è±¡çkey141 * @param throw_ {boolean} æ¯å¦æé142 * @returns {boolean}143 */144 static lengthGte(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;145 /**146 * æ¯å¦ä»¥æå®å符串å¼å¤´147 * @param value {any} æ£æµå¯¹è±¡148 * @param expectValue {string} ææå¼149 * @param key {string} 表示æ£æµå¯¹è±¡çkey150 * @param throw_ {boolean} æ¯å¦æé151 * @returns {boolean}152 */153 static startsWith(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;154 /**155 * é¿åº¦çäºæå®å¼156 * @param value {any} æ£æµå¯¹è±¡157 * @param expectValue {number} ææå¼158 * @param key {string} 表示æ£æµå¯¹è±¡çkey159 * @param throw_ {boolean} æ¯å¦æé160 * @returns {boolean}161 */162 static lengthEq(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;163 /**164 * å
ç´ åå¨äºæå®æ°ç»ä¸165 * @param value {any} æ£æµå¯¹è±¡166 * @param expectValue {array} ææå¼167 * @param key {string} 表示æ£æµå¯¹è±¡çkey168 * @param throw_ {boolean} æ¯å¦æé169 * @returns {boolean}170 */171 static in(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;172 /**173 * 强çäº174 * @param value {any} æ£æµå¯¹è±¡175 * @param expectValue {any} ææå¼176 * @param key {string} 表示æ£æµå¯¹è±¡çkey177 * @param throw_ {boolean} æ¯å¦æé178 * @returns {boolean}179 */180 static is(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;181 /**182 * æ¯å¦æ¯æèªå®ä¹ç±»åï¼å¦emailãmobile183 * @param value {any} æ£æµå¯¹è±¡184 * @param expectValue {string} ææå¼185 * @param key {string} 表示æ£æµå¯¹è±¡çkey186 * @param throw_ {boolean} æ¯å¦æé187 * @returns {boolean}188 */189 static isCustomType(value: any, expectValue: any, key?: any, throw_?: boolean): boolean;...
error.spec.ts
Source:error.spec.ts
1import { assertError, throw_ } from "./error";2import { Maybe } from "./maybe";3test("throw_ should throw error message", () => {4 expect(() => {5 throw_("error");6 }).toThrow("error");7});8test("undefined should be asserted to an error", () => {9 let error: Maybe<Error>;10 try {11 throw_(undefined);12 } catch (err) {13 error = assertError(err);14 }15 console.log(error);16 expect(error).toBeDefined();17 expect(error?.message).toEqual("non-error of type undefined has been thrown");18});19test("string should be asserted to an error", () => {20 let error: Maybe<Error>;21 try {22 throw_("Some error");23 } catch (err) {24 error = assertError(err);25 }26 expect(error).toBeDefined();27 expect(error?.message).toEqual("Some error");28});29test("object should be asserted to an error", () => {30 let error: Maybe<Error>;31 try {32 throw_({ message: "Some error" });33 } catch (err) {34 error = assertError(err);35 }36 expect(error).toBeDefined();37 expect(error?.message).toEqual('{"message":"Some error"}');...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) throw err;4 console.log('Test status: ' + data.statusText);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if (err) throw err;9 console.log('Test status: ' + data.statusText);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if (err) throw err;14 console.log('Test status: ' + data.statusText);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18 if (err) throw err;19 console.log('Test status: ' + data.statusText);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if (err) throw err;24 console.log('Test status: ' + data.statusText);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28 if (err) throw err;29 console.log('Test status: ' + data.statusText);30});31var wpt = require('webpagetest');
Using AI Code Generation
1var wpt = require('wpt');2wpt.throw_('Error message');3var wpt = require('wpt');4wpt.throw_(new Error('Error message'));5var wpt = require('wpt');6wpt.throw_(new TypeError('Error message'));7var wpt = require('wpt');8wpt.throw_(new RangeError('Error message'));9var wpt = require('wpt');10wpt.throw_(new ReferenceError('Error message'));11var wpt = require('wpt');12wpt.throw_(new SyntaxError('Error message'));13var wpt = require('wpt');14wpt.throw_(new URIError('Error message'));15var wpt = require('wpt');16wpt.throw_(new EvalError('Error message'));17var wpt = require('wpt');18wpt.throw_(new RangeError('Error message'));19var wpt = require('wpt');20wpt.throw_(new RangeError('Error message'));
Using AI Code Generation
1var wptools = require('wptools');2var wp = wptools('Barack Obama');3wp.throw_(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wp = wptools('Barack Obama');8wp.throw_(function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wp = wptools('Barack Obama');13wp.throw_(function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wp = wptools('Barack Obama');18wp.throw_(function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wp = wptools('Barack Obama');23wp.throw_(function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wp = wptools('Barack Obama');28wp.throw_(function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wp = wptools('Barack Obama');33wp.throw_(function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wp = wptools('Barack Obama');38wp.throw_(function(err, data) {39 console.log(data);40});41var wptools = require('wptools');42var wp = wptools('Barack Obama');43wp.throw_(function(err, data) {44 console.log(data);45});
Using AI Code Generation
1throw_("Test Failed");2assert_equals(1, 0);3assert_true(1 == 0);4assert_false(1 == 1);5assert_greater_than(1, 2);6assert_greater_than_equal(1, 2);7assert_less_than(1, 2);8assert_less_than_equal(1, 2);9assert_approx_equals(1, 2, 3);10assert_not_equals(1, 1);11assert_not_approx_equals(1, 2, 3);12assert_throws("Test Failed");13assert_array_equals([1, 2], [1, 2]);14assert_object_equals({ a: 1 }, { a: 1 });15assert_regexp_match("Test Failed", /Test Failed/);16assert_string_match("Test Failed", "Test Failed");17assert_class_string("Test Failed", "Test Failed");18assert_own_property({ a: 1 }, "a");19assert_inherits({ a: 1 }, "a");20assert_readonly({ a: 1 }, "a");21assert_unreached("Test Failed");22assert_true(1 == 0);23assert_false(1 == 1);24assert_greater_than(1, 2);
Using AI Code Generation
1var wpt = require('webpage');2var page = wpt.create();3 console.log(status);4 page.evaluate(function () {5 throw new Error('test error');6 });7});8var express = require('express');9var app = express();10app.use(function(err, req, res, next) {11 console.error(err.stack);12 res.status(500).send('Something broke!');13});14app.get('/', function (req, res) {15 res.send('Hello World!');16});17app.listen(3000, function () {18 console.log('Example app listening on port 3000!');19});20import webkit2png21 webkit2png.main(['--width=1024', '--height=768', '--fullsize', '--delay=2', '--output=/some/path/'+url+'.png', url])22import webkit2png23 webkit2png.main(['--width=1024', '--height=768', '--fullsize', '--delay=2', '--output=/some/path/'+url+'.png', url])24import webkit2png25 webkit2png.main(['--width=1024', '--height=768', '--fullsize', '--delay=2', '--output=/some/path/'+url+'.png', url])
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!