How to use toRawType method in Playwright Internal

Best JavaScript code snippet using playwright-internal

easy-axios.js

Source:easy-axios.js Github

copy

Full Screen

1import axios from 'axios'2import merge from 'lodash/merge'3import { validator } from './validator/validator.js'4import { claim } from './validator/claim.js'5import { toRawType, dataToFormData } from './utils/utils.js'6import { statusMsg } from './constant/statusMsg.js'7import OperationCache from './cache/OperationCache.js'89// EasyAxios 默认的 axios 配置10const defaultAxiosConfig = {11 timeout: 10000,12 responseType: 'json',13 headers: {14 'Content-Type': 'application/json;charset=utf-8',15 'X-Requested-With': 'XMLHttpRequest'16 },17}1819// 如果需要兼容旧的逻辑20export const primevalAxios = axios2122export default class EasyAxios {23 constructor(options = {}, axiosConfig = {}) {24 // 验证 options 属性是否合法25 const result = validator(options, claim)26 if (result.illegal) throw new Error(result.errorMsg)2728 // 请求数29 this.requestCount = 0 3031 // 正在发送中的请求32 this.PendingRequestMap = new Map()3334 // 是否开启提示35 this.isOpenTips = toRawType.isBoolean(options.easyAxiosConfig.isOpenTips) ? options.easyAxiosConfig.isOpenTips : false36 37 // 是否开启取消重复请求38 this.isOpenCancelDuplicateRequest = toRawType.isBoolean(options.easyAxiosConfig.isOpenCancelDuplicateRequest) ? options.easyAxiosConfig.isOpenCancelDuplicateRequest : false39 40 // 是否开启缓存41 this.isOpenRequestCache = toRawType.isBoolean(options.easyAxiosConfig.isOpenRequestCache) ? options.easyAxiosConfig.isOpenRequestCache : false42 43 // 缓存时间44 this.cacheEffectiveTime = toRawType.isNumber(options.easyAxiosConfig.cacheEffectiveTime) && options.easyAxiosConfig.cacheEffectiveTime > 1000 * 60 * 5 ? options.easyAxiosConfig.cacheEffectiveTime : 045 46 // 最大重连次数47 this.maxReconnectionTimes = toRawType.isNumber(options.easyAxiosConfig.maxReconnectionTimes) ? parseInt(options.easyAxiosConfig.maxReconnectionTimes) : 048 49 // 状态码及操作函数的对象50 this.statusHandlers = toRawType.isObject(options.easyAxiosConfig.statusHandlers) ? options.easyAxiosConfig.statusHandlers : {}5152 // 发送前和响应后的处理53 this.beforeRequestHook = toRawType.isFunction(options.beforeRequestHook) ? options.beforeRequestHook : () => {}54 this.afterResponseHook = toRawType.isFunction(options.afterResponseHook) ? options.afterResponseHook : () => {}55 56 // 提示信息处理方法57 this.tipsFunction = toRawType.isFunction(options.tipsFunction) ? options.tipsFunction : () => {}58 59 // loading 相关60 this.startLoading = toRawType.isFunction(options.startLoading) ? options.startLoading : () => {}61 this.endLoading = toRawType.isFunction(options.endLoading) ? options.endLoading : () => {}6263 // 获取 response.data 对象里的相关属性(数据、信息码、信息)64 this.getDataFormResult = toRawType.isFunction(options.getDataFormResult) ? options.getDataFormResult : () => null65 this.getStatusFormResult = toRawType.isFunction(options.getStatusFormResult) ? options.getStatusFormResult : () => null66 this.getMassageFormResult = toRawType.isFunction(options.getMassageFormResult) ? options.getMassageFormResult : () => null6768 // 请求是否成功的验证器69 this.validateResultStatus = toRawType.isFunction(options.validateResultStatus) ? options.validateResultStatus : (status) => status >= 200 && status < 3007071 // 合并 axios 配置72 this.config = merge(defaultAxiosConfig, axiosConfig)7374 // 创建 axios75 this.createAxios()7677 // 加载拦截器78 this.interceptors()79 }8081 // 创建82 createAxios() {83 this.easyAxios = axios.create(this.config)84 }8586 // 拦截器87 interceptors() {88 // 请求拦截器89 this.easyAxios.interceptors.request.use(90 config => {91 // 请求数自增92 this.requestCount++9394 // 调用加载动画方法95 this.startLoading()9697 // 赋值某一接口是否禁用 hook、tips、cache 的配置98 const { easyAxiosConfig: { disableHooks, disableTips, disableCache } = {} } = config99100 // 是否开启请求缓存101 if (this.isOpenRequestCache && !disableCache) {102 // 获取缓存103 const cacheData = EasyAxios.getDataCache(config.method, config.url, config[['get','delete'].includes(config.method.toLocaleLowerCase()) ? 'params' : 'data'])104 if (cacheData) { // 是否存在105 return Promise.reject({isOpenRequestCache: true, data: cacheData})106 }107 }108109 // 是否调用 beforeRequestHook110 if (!(disableHooks === true || (disableHooks && disableHooks.request))) {111 try {112 this.beforeRequestHook(config)113 }114 catch (error) {115 // 调用提示方法116 (this.isOpenTips && !disableTips) && this.tipsFunction(`beforeRequestHook 内部出现错误:${error.message},请检查`)117 }118 }119120 // 移除 PendingRequest121 this.removePendingRequest(config)122123 // 添加最新的 PendingRequest124 this.addPendingRequest(config)125126 return config127 },128 error => {129 // 请求发送失败130 (--this.requestCount === 0) && this.endLoading()131132 return Promise.reject(error)133 }134 )135136 // 响应拦截器137 this.easyAxios.interceptors.response.use(138 response => {139 // 去掉加载动画140 (--this.requestCount === 0) && this.endLoading()141142 // 移除 PendingRequest143 this.removePendingRequest(response.config)144145 // 赋值某一接口是否禁用 hook、tips、cache 的配置146 const { config: { easyAxiosConfig: { disableHooks, disableTips, disableCache } = {} } } = response147148 // 是否调用 afterResponseHook149 if (!(disableHooks === true || (disableHooks && disableHooks.response))) {150 try {151 this.afterResponseHook(response, false)152 }153 catch (error) {154 const message = `afterResponseHook 内部出现错误:${error.message},请检查`155 156 // 调用提示方法157 (this.isOpenTips && !disableTips) && this.tipsFunction(message)158159 return Promise.reject(message)160 }161 }162163 // 返回响应对象164 return new Promise((resolve, reject) => {165 if (!response || !response.data) resolve(null)166167 const resultData = response.data168 const status = this.getStatusFormResult(resultData) || response.status169170 if (!this.validateResultStatus(status)) {171 const message = this.getMassageFormResult(resultData) || statusMsg[status]172 173 // 调用提示方法174 (this.isOpenTips && !disableTips) && this.tipsFunction(message)175176 const statusHandler = this.statusHandlers[status]177178 toRawType.isFunction(statusHandler) && statusHandler()179180 reject(message)181 }182183 // 获取服务端返回数据184 const data = this.getDataFormResult(resultData)185186 // 设置缓存相关187 this.isOpenRequestCache 188 && !disableCache 189 && EasyAxios.setDataCache(response.config.method, response.config.url, response.config[['get','delete'].includes(response.config.method.toLocaleLowerCase()) ? 'params' : 'data'], data)190 191 resolve(data)192 })193 },194 error => {195 // 去掉加载动画196 (--this.requestCount === 0) && this.endLoading()197198 // 是否取消重复请求199 if (axios.isCancel(error)) return Promise.reject(null)200201 // 从缓存中来的,返回获取到的缓存202 if (toRawType.isBoolean(error.isOpenRequestCache) && error.isOpenRequestCache) return Promise.resolve(error.data)203204 // 移除 PendingRequest205 this.removePendingRequest(error.config)206207 // 赋值某一接口是否禁用 hook、tips、cache 的配置208 const { config: { easyAxiosConfig: { disableHooks, disableTips } = {} } } = error209 210 // 是否调用 afterResponseHook211 if (!(disableHooks === true || (disableHooks && disableHooks.response))) {212 try {213 this.afterResponseHook(error, true)214 } 215 catch (error) {216 const message = `afterResponseHook 内部出现错误:${error.message},请检查`217218 (this.isOpenTips && !disableTips) && this.tipsFunction(message)219220 return Promise.reject(message)221 }222 }223224 if (error.response // 仅对超时(无响应)请求进行重试225 || !error.config 226 || this.maxReconnectionTimes < 1 // 重连次数小于 1 ,则不需要重连227 || (error.config.times && error.config.times >= this.maxReconnectionTimes)228 ) {229230 let message = '连接失败'231232 if (error.response) { // 服务端响应233 const { status } = error.response234 235 message = statusMsg[status] || error.message236 237 const statusHandler = this.statusHandlers[status]238 239 toRawType.isFunction(statusHandler) && statusHandler()240241 } else if (error.request) {242 message = error.message243 } else {244 message = error.message245 }246 247 // 调用提示方法248 (this.isOpenTips && !disableTips) && this.tipsFunction(message)249 250 // 向上抛出异常251 return Promise.reject(message)252 }253254 // 屏蔽重试请求的baseURL项255 error.config.baseURL = null256257 // 设定已重试次数258 error.config.times = (error.config.times || 0) + 1259260 // 重新发起请求261 return this.easyAxios(error.config)262 },263 )264 }265266 // 通用267 REQUEST(method, url, param = {}, config = {}) {268 return new Promise((resolve, reject) => {269 this.easyAxios({270 method: method,271 url: url,272 [['get','delete'].includes(method.toLocaleLowerCase()) ? 'params' : 'data']: param,273 ...config274 })275 .then(response => resolve(response))276 .catch(error => error && reject(error)) // error 为 null 时为取消掉的重复请求返回的错误,不用提示277 })278 }279 280 // GET281 GET(url, param = {}, config = {}) {282 return this.REQUEST('get', url, param, config)283 }284 285 // POST286 POST(url, param = {}, config = {}) {287 return this.REQUEST('post', url, param, config)288 }289 290 // PUT291 PUT(url, param = {}, config = {}) {292 return this.REQUEST('put', url, param, config)293 }294 295 // DELETE296 DELETE(url, param = {}, config = {}) {297 return this.REQUEST('delete', url, param, config)298 }299 300 // FORMDATA301 FORMDATA(url, params, config = {}) {302 return this.REQUEST('post', url, dataToFormData(params), merge({303 headers: {304 'content-type': 'multipart/form-data;charset=UTF-8',305 },306 }, config))307 }308309 // 添加正在请求的310 addPendingRequest(config) {311 if (!this.isOpenCancelDuplicateRequest) return312313 // 赋值某一接口是否禁用取消重复请求和设置 requestKey 的配置314 const { easyAxiosConfig: { disableCancelDuplicate, requestKey } = {} } = config315316 if (!disableCancelDuplicate) {317318 const cncelDuplicateKey = toRawType.isUndefined(requestKey) ? [config.method, config.url, JSON.stringify(config.params), JSON.stringify(config.data)].join('&') : requestKey 319320 config.cancelToken = config.cancelToken || new axios.CancelToken(cancel => {321 if (cncelDuplicateKey && !this.PendingRequestMap.has(cncelDuplicateKey)) {322 this.PendingRequestMap.set(cncelDuplicateKey, cancel)323 }324 })325 }326 }327328 // 移除正在请求的329 removePendingRequest(config) {330 if (!this.isOpenCancelDuplicateRequest) return331 332 // 赋值某一接口是否禁用取消重复请求和设置 requestKey 的配置333 const { easyAxiosConfig: { disableCancelDuplicate, requestKey } = {} } = config334335 if (!disableCancelDuplicate) {336 337 const cncelDuplicateKey = toRawType.isUndefined(requestKey) ? [config.method, config.url, JSON.stringify(config.params), JSON.stringify(config.data)].join('&') : requestKey 338339 if (cncelDuplicateKey && this.PendingRequestMap.has(cncelDuplicateKey)) {340 const cancel = this.PendingRequestMap.get(cncelDuplicateKey)341 cancel(cncelDuplicateKey)342 this.PendingRequestMap.delete(cncelDuplicateKey)343 }344 }345 }346347 // 路由切换,清除所有 PendingRequest ,在路由跳转前调用348 clearPendingRequest() {349 for (const [cncelDuplicateKey, cancel] of this.PendingRequestMap) cancel(cncelDuplicateKey)350 this.PendingRequestMap.clear()351 }352353 // 根据url和params对象获取缓存354 static getDataCache(method, url, params) {355 // 生成 key356 const key = `${method}-${url}:${JSON.stringify(params)}`357 // 获得请求对象358 return OperationCache.get(key)359 }360361 // 根据url和params对象设置缓存362 static setDataCache(method, url, params, data) {363 // 生成 key364 const key = `${method}-${url}:${JSON.stringify(params)}`365 // 设置366 OperationCache.set(key, data, this.cacheEffectiveTime)367 } ...

Full Screen

Full Screen

obj.js

Source:obj.js Github

copy

Full Screen

...3*/4const _toString = Object.prototype.toString;56function isObject(src) {7 return toRawType(src) === "Object";8}910// 区分基本数据类型和应用数据类型11function isObjectType(src) {12 return src instanceof Object;13}1415// code from vue16function toRawType(value) {17 return _toString.call(value).slice(8, -1);18}1920function repeat(value, count, joinFlag) {21 const temp = []22 let i = 023 while(i < count) {24 temp.push(value)25 i ++26 }27 return joinFlag? temp.join(joinFlag): temp28}2930function keyStr2Arr(keyStr) {31 const arr = keyStr.split('.')32 const temp = arr.map(ele => {33 const matchArr = ele.match(/\[\d+\]/g)34 if(matchArr) {35 const okey = ele.substr(0, ele.indexOf(matchArr[0]))36 if(okey) return [okey].concat(matchArr.map(ma => parseInt(ma.slice(1, -1))))37 return matchArr.map(ma => parseInt(ma.slice(1, -1)))38 } else {39 return ele40 }41 })42 return temp.reduce((a, b) => {43 return a.concat(b)44 }, [])45}4647// 根据keyarr生成一个引用对象48function composeObject(keyarr, value, next) {49 let temp 50 const key = keyarr[next]51 if(typeof key === 'number') {52 if(next === keyarr.length - 1) {53 temp = [ ...repeat(undefined, key) , value]54 } else {55 temp = [...repeat(undefined, key), composeObject( keyarr, value, next + 1)]56 }57 } else if(typeof key === 'string') {58 if(next === keyarr.length - 1) {59 temp = {60 [key]: value61 }62 } else {63 temp = {64 [key]: composeObject( keyarr, value, next + 1)65 }66 }67 }68 return temp 69}7071// key/vlaue深穿,72function deepPierceByKey(origin, keystr, value) {73 const keys = keyStr2Arr(keystr)74 let temp = origin75 try {76 keys.forEach((ele, index) => {77 if(index === keys.length - 1) {78 temp[ele] = value79 } else {80 temp = temp[ele]81 }82 })83 } catch(err) {84 throw Error('key path is not correct')85 }86 return origin87}8889// console.log(toRawType(null))9091// 深拷 ,如果是数组咋办,时间咋办,null咋办, 方法Function咋办, 其他引用对象咋办92function deepClone(origin) {93 let resdata;94 const rowType = toRawType(origin);95 const _isObjectType = isObjectType(origin);96 if (_isObjectType) {97 if (rowType === "Object") {98 const keys = Object.keys(origin);99 resdata = new Object();100 for (let i = 0; i < keys.length; i++) {101 resdata[keys[i]] = deepClone(origin[keys[i]]);102 }103 } else if (rowType === "Array") {104 resdata = origin.map((ele) => {105 return deepClone(ele);106 });107 } else if (rowType === "Date") {108 resdata = new Date(origin.getTime());109 } else if (rowType === "Function") {110 // 拖鞋111 resdata = origin;112 } else {113 // 其他引用对象拖鞋114 resdata = origin;115 }116 } else {117 // 基本数据类型直接赋值118 resdata = origin;119 }120 return resdata;121}122123// 深assign, 拷贝对象方法,对象数组与null,Date 等引用对象124 function deepAssign(origin, src, isIncludeArray = false) {125 const clone = deepClone(origin);126 if(toRawType(src) === 'Object') {127 return deepPierce(clone, src, isIncludeArray);128 } else if (toRawType(src) === 'Array') {129 let temp = clone130 src.forEach(ele => {131 temp = deepPierce(temp, ele, isIncludeArray)132 })133 return temp134 } else {135 return origin136 }137}138139140// isPierceArrayObj 表示是否刺穿数组内的引用对象,利用原引用对象,不开辟新对象,测试通过141function deepPierce(origin, src, isPierceArrayObj = false) {142 if (isObject(origin)) {143 const ori_keys = Object.keys(origin);144 if (isObject(src)) {145 const src_keys = Object.keys(src);146 const len = src_keys.length;147 for (let i = 0; i < len; i++) {148 if (ori_keys.indexOf(src_keys[i]) > -1) {149 if (isObject(origin[src_keys[i]])) {150 deepPierce(origin[src_keys[i]], src[src_keys[i]], isPierceArrayObj);151 } else if(isPierceArrayObj && toRawType(origin[src_keys[i]]) === 'Array' && toRawType(src[src_keys[i]]) === 'Array') {152 origin[src_keys[i]] = deepPierce(origin[src_keys[i]], src[src_keys[i]], isPierceArrayObj);153 } 154 else {155 origin[src_keys[i]] = src[src_keys[i]];156 }157 } else {158 origin[src_keys[i]] = src[src_keys[i]];159 }160 }161 } else {162 origin = src;163 }164 } else if(toRawType(origin) === 'Array' && toRawType(src) === 'Array') {165 if(isPierceArrayObj) {166 const originLen = origin.length167 const srcLen = src.length168 if(originLen >= srcLen) {169 origin = origin.map((ele, index) => {170 if(isObject(src[index])){171 if(isObject(ele)) {172 return deepPierce(ele, src[index], isPierceArrayObj);173 } else {174 return src[index]175 }176 } else if(src[index] !== undefined && src[index] !== null) {177 return src[index]178 } else {179 return ele180 }181 })182 } else {183 origin = origin.map((ele, index) => {184 const isObjOri = isObject(ele)185 const isObjSrc = isObject(src[index])186 if(isObjSrc) {187 if(isObjOri) {188 return deepPierce(ele, src[index], isPierceArrayObj);189 } else {190 return src[index]191 }192 } else if(src[index] !== undefined && src[index] !== null) {193 return src[index]194 } else {195 return ele196 }197 }).concat(src.slice(originLen))198 }199 } else {200 origin = src;201 }202 } else {203 origin = src204 }205 return origin;206}207208export const clone = deepClone209export const assign = deepAssign210export const compose = composeObject211export const pierce = deepPierceByKey212213214// return;215216// // 先试试asign方法, 这是对象拷贝方法,217// // 问题很多,218// function objAsign(obj1, obj2) {219// return Object.assign({}, obj1, obj2);220// }221222223224// // test225// // 测试克隆方法, 引用对象地址判断,顺便判断基本数据类型226// function objectTest(origin) {227// const clone = deepClone(origin);228// deepTest(origin, clone);229// }230231// function testStringifyParse(origin) {232// const clone = JSON.parse(JSON.stringify(origin));233// deepTest(origin, clone);234// }235236// function repeat(str, count) {237// if (!count || toRawType(count) !== "Number") return str;238// let temp = "";239// let i = 0;240// while (i < count) {241// temp += str;242// i++;243// }244// return temp;245// }246// // 测试深克隆247// function deepTest(origin, clone, step = 0) {248// const _rowTypeOrigin = toRawType(origin);249// const _rowTypeClone = toRawType(clone);250// const _isObjectTypeOrigin = isObjectType(origin);251// const _isObjectTypeClone = isObjectType(clone);252// if (_isObjectTypeOrigin && _isObjectTypeClone) {253// if (origin === clone) {254// console.log(origin, clone, "object: origin = clone, 引用地址没变");255// return;256// }257// if (_rowTypeOrigin === "Array" && _rowTypeClone === "Array") {258// const len = origin.length;259// for (let i = 0; i < len; i++) {260// deepTest(origin[i], clone[i]);261// }262// return;263// } else if (_rowTypeOrigin === "Array" && _rowTypeClone !== "Array") { ...

Full Screen

Full Screen

inspect.spec.js

Source:inspect.spec.js Github

copy

Full Screen

...29 expect(toType(undefined)).toEqual('undefined')30 expect(toType(null)).toEqual('object')31 })32 it('toRawType', async () => {33 expect(toRawType(123)).toEqual('Number')34 expect(toRawType('123')).toEqual('String')35 expect(toRawType(true)).toEqual('Boolean')36 expect(toRawType({})).toEqual('Object')37 expect(toRawType([])).toEqual('Array')38 expect(toRawType(/abc/)).toEqual('RegExp')39 expect(toRawType(() => {})).toEqual('Function')40 expect(toRawType(Date)).toEqual('Function')41 expect(toRawType(new Date())).toEqual('Date')42 expect(toRawType(undefined)).toEqual('Undefined')43 expect(toRawType(null)).toEqual('Null')44 })45 it('toRawTypeLC', async () => {46 expect(toRawTypeLC(123)).toEqual('number')47 expect(toRawTypeLC('123')).toEqual('string')48 expect(toRawTypeLC(true)).toEqual('boolean')49 expect(toRawTypeLC({})).toEqual('object')50 expect(toRawTypeLC([])).toEqual('array')51 expect(toRawTypeLC(/abc/)).toEqual('regexp')52 expect(toRawTypeLC(() => {})).toEqual('function')53 expect(toRawTypeLC(Date)).toEqual('function')54 expect(toRawTypeLC(new Date())).toEqual('date')55 expect(toRawTypeLC(undefined)).toEqual('undefined')56 expect(toRawTypeLC(null)).toEqual('null')57 })...

Full Screen

Full Screen

inspect.js

Source:inspect.js Github

copy

Full Screen

...10var toType = function toType(val) {11 return _typeof(val);12};13exports.toType = toType;14var toRawType = function toRawType(val) {15 return Object.prototype.toString.call(val).slice(8, -1);16};17exports.toRawType = toRawType;18var toRawTypeLC = function toRawTypeLC(val) {19 return toRawType(val).toLowerCase();20};21exports.toRawTypeLC = toRawTypeLC;22var isUndefined = function isUndefined(val) {23 return val === undefined;24};25exports.isUndefined = isUndefined;26var isNull = function isNull(val) {27 return val === null;28};29exports.isNull = isNull;30var isFunction = function isFunction(val) {31 return toType(val) === 'function';32};33exports.isFunction = isFunction;34var isBoolean = function isBoolean(val) {35 return toType(val) === 'boolean';36};37exports.isBoolean = isBoolean;38var isString = function isString(val) {39 return toType(val) === 'string';40};41exports.isString = isString;42var isNumber = function isNumber(val) {43 return toType(val) === 'number';44};45exports.isNumber = isNumber;46var isPrimitive = function isPrimitive(val) {47 return isBoolean(val) || isString(val) || isNumber(val);48};49exports.isPrimitive = isPrimitive;50var isDate = function isDate(val) {51 return val instanceof Date;52};53exports.isDate = isDate;54var isRegExp = function isRegExp(val) {55 return toRawType(val) === 'RegExp';56};57exports.isRegExp = isRegExp;58var isPromise = function isPromise(val) {59 return !isUndefined(val) && !isNull(val) && isFunction(val.then) && isFunction(val.catch);60}; // Extra convenience named re-exports...

Full Screen

Full Screen

is.js

Source:is.js Github

copy

Full Screen

1// 判断数据类型函数2function toRawType(value) {3 return Object.prototype.toString.call(value).slice(8, -1)4}5/** 字符串 类型6 * @param {string} str7 * @returns {Boolean}8 */9export function _isString(str) {10 if (typeof str === 'string' || str instanceof String) {11 return true12 }13 return false14}15/** null 类型16 * @param {null} arg17 * @returns {Boolean}18 */19export function _isNull(arg) {20 return toRawType(arg) === 'Null'21}22/** undefined 类型23 * @param {undefined} arg24 * @returns {Boolean}25 */26export function _isUndefined(arg) {27 return arg === void 028}29/** boolean 类型30 * @param {boolean} arg31 * @returns {Boolean}32 */33export function _isBoolean(arg) {34 return toRawType(arg) === 'Boolean'35}36/** function 类型37 * @param {function} arg38 * @returns {Boolean}39 */40export function _isFunction(arg) {41 return toRawType(arg) === 'Function'42}43/** array 类型44 * @param {Array} arg45 * @returns {Boolean}46 */47export function _isArray(arg) {48 if (typeof Array.isArray === 'undefined') return toRawType(arg) === 'Array'49 return Array.isArray(arg)50}51/** object 类型52 * @param { object } arg53 * @returns {Boolean}54 */55export function _isObject(arg) {56 return toRawType(arg) === 'Object'57}58/** regExp 类型59 * @param { regExp } arg60 * @returns {Boolean}61 */62export function _isRegExp(arg) {63 return toRawType(arg) === 'RegExp'64}65/** symbol 类型66 * @param { symbol } arg67 * @returns {Boolean}68 */69export function _isSymbol(arg) {70 return toRawType(arg) === 'Symbol'71}72/** date 类型73 * @param { date } arg74 * @returns {Boolean}75 */76export function _isDate(arg) {77 return toRawType(arg) === 'Date'78}79/** 空对象 {},[],null,及其它非对象数据80 * @param { obj } arg81 * @returns {Boolean}82 */83export function _isEmptyObject(arg) {84 for (const name in arg) {85 return false86 }87 return true...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

...13 'Boolean',14 'Function',15 'RegExp'16 ].forEach((t) => {17 toRawType['is' + t] = (o) => toRawType(o) === t.toLocaleLowerCase()18 })19})()202122// 合并对象,两个对象相同属性名的值将添加在一起23export const merge = (...objs) =>24 [...objs].reduce(25 (acc, obj) =>26 Object.keys(obj).reduce((a, k) => {27 acc[k] = acc.hasOwnProperty(k) ? [].concat(acc[k]).concat(obj[k]) : obj[k]28 return acc29 }, {}30 ), {}31 ) ...

Full Screen

Full Screen

lang.js

Source:lang.js Github

copy

Full Screen

2export function hasOwn(obj, key) {3 return hasOwnProperty.call(obj, key)4}5const _toString = Object.prototype.toString6export function toRawType(value) {7 return _toString.call(value).slice(8, -1)8}9export function isObject(value) {10 return value && typeof value === 'object'11}12export function isArray(value) {13 return toRawType(value) === 'Array'14}15export function isPlainObject(value) {16 return toRawType(value) === 'Object'17}18export function isFunction(value) {19 return toRawType(value) === 'Function'20}21export function isEmptyObject(value) {22 if (isPlainObject(value)) {23 return Object.keys(value).length === 024 }25 return false...

Full Screen

Full Screen

specific-obj-type.js

Source:specific-obj-type.js Github

copy

Full Screen

1function toRawType(value) {2 let _toString = Object.prototype.toString;3 let str = _toString.call(value);4 return str.slice(8, -1);5}6console.log(toRawType(null));7// "Null"8console.log(toRawType(/sdfsd/));9//"RegExp"10console.log(toRawType([]));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toRawType } = require('@playwright/test/lib/utils/utils');2console.log(toRawType({}));3console.log(toRawType([]));4console.log(toRawType(new Map()));5console.log(toRawType(new Set()));6console.log(toRawType(new Date()));7console.log(toRawType(new Error()));8Playwright is [BSD-2 licensed](

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toRawType } = require('@playwright/test/lib/utils/utils');2const { toRawType } = require('@playwright/test/lib/utils/utils');3const { toRawType } = require('@playwright/test/lib/utils/utils');4const { toRawType } = require('@playwright/test/lib/utils/utils');5const { toRawType } = require('@playwright/test/lib/utils/utils');6const { toRawType } = require('@playwright/test/lib/utils/utils');7const { toRawType } = require('@playwright/test/lib/utils/utils');8const { toRawType } = require('@playwright/test/lib/utils/utils');9const { toRawType } = require('@playwright/test/lib/utils/utils');10const { toRawType } = require('@playwright/test/lib/utils/utils');11const { toRawType } = require('@playwright/test/lib/utils/utils');12const { toRawType } = require('@playwright/test/lib/utils/utils');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toRawType } = require('playwright/lib/utils/utils');2const assert = require('assert');3const { test, expect } = require('@playwright/test');4test('toRawType', async ({ page }) => {5 assert.equal(toRawType([]), 'Array');6 assert.equal(toRawType({}), 'Object');7 assert.equal(toRawType(new Map()), 'Map');8 assert.equal(toRawType(new Set()), 'Set');9 assert.equal(toRawType(new WeakMap()), 'WeakMap');10 assert.equal(toRawType(new WeakSet()), 'WeakSet');11 assert.equal(toRawType(new Int8Array()), 'Int8Array');12 assert.equal(toRawType(new Uint8Array()), 'Uint8Array');13 assert.equal(toRawType(new Uint8ClampedArray()), 'Uint8ClampedArray');14 assert.equal(toRawType(new Int16Array()), 'Int16Array');15 assert.equal(toRawType(new Uint16Array()), 'Uint16Array');16 assert.equal(toRawType(new Int32Array()), 'Int32Array');17 assert.equal(toRawType(new Uint32Array()), 'Uint32Array');18 assert.equal(toRawType(new Float32Array()), 'Float32Array');19 assert.equal(toRawType(new Float64Array()), 'Float64Array');20 assert.equal(toRawType(new ArrayBuffer()), 'ArrayBuffer');21 assert.equal(toRawType(new DataView(new ArrayBuffer())), 'DataView');22 assert.equal(toRawType(new Error()), 'Error');23 assert.equal(toRawType(new RegExp()), 'RegExp');24 assert.equal(toRawType(new Promise(() => {})), 'Promise');25 assert.equal(toRawType(async () => {}), 'AsyncFunction');26 assert.equal(toRawType(() => {}), 'Function');27 assert.equal(toRawType(function () {}), 'Function');28 assert.equal(toRawType(function* () {}), 'GeneratorFunction');29 assert.equal(toRawType(new Date()), 'Date');30 assert.equal(toRawType(new String()), 'String');31 assert.equal(toRawType(new Number()), 'Number');32 assert.equal(toRawType(new Boolean()), 'Boolean');33 assert.equal(toRawType(Symbol('')), 'Symbol');34 assert.equal(toRawType(new ArrayBuffer()), 'ArrayBuffer');35 assert.equal(toRawType(new SharedArrayBuffer()), 'SharedArrayBuffer');36 assert.equal(toRawType(new Blob()), 'Blob');37 assert.equal(toRaw

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toRawType } = require('playwright-core/lib/server/common/utils');2console.log(toRawType({}))3console.log(toRawType([]))4console.log(toRawType(1))5console.log(toRawType('a'))6console.log(toRawType(true))7console.log(toRawType(new Date()))8console.log(toRawType(new Error()))9console.log(toRawType(new Map()))10console.log(toRawType(new Set()))11console.log(toRawType(new RegExp()))12console.log(toRawType(new WeakMap()))13console.log(toRawType(new WeakSet()))14console.log(toRawType(Symbol('a')))15console.log(toRawType(function(){}))16console.log(toRawType(null))17console.log(toRawType(undefined))18const { toRawType } = require('playwright-core/lib/server/common/utils');19console.log(toRawType({}))20console.log(toRawType([]))21console.log(toRawType(1))22console.log(toRawType('a'))23console.log(toRawType(true))24console.log(toRawType(new Date()))25console.log(toRawType(new Error()))26console.log(toRawType(new Map()))27console.log(toRawType(new Set()))28console.log(toRawType(new RegExp()))29console.log(toRawType(new WeakMap()))30console.log(toRawType(new WeakSet()))31console.log(toRawType(Symbol('a')))32console.log(toRawType(function(){}))33console.log(toRawType(null))34console.log(toRawType(undefined))35const { toRawType } = require('playwright-core/lib/server/common/utils');36console.log(toRawType({}))37console.log(toRawType([]))38console.log(to

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toRawType } = require('@playwright/test/lib/utils/utils');2describe('test', () => {3 it('test', async () => {4 console.log(toRawType('test'));5 });6});

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toRawType } = require('playwright/lib/utils/utils');2const object = { a: 'b' };3console.log(toRawType(object));4const { toRawType } = require('playwright/lib/utils/utils');5const object = { a: 'b' };6console.log(toRawType(object));7toRawType(value)8const { toRawType } = require('playwright/lib/utils/utils');9const object = { a: 'b' };10console.log(toRawType(object));11const { toRawType } = require('playwright/lib/utils/utils');12const object = { a: 'b' };13console.log(toRawType(object));14const { toRawType } = require('playwright/lib/utils/utils');15const object = { a: 'b' };16console.log(toRawType(object));

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful