提交 5fe166f3 编写于 作者: fxy060608's avatar fxy060608

chore: typeof x === 'string' => isString

上级 b91abffa
import { isString } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
export const API_PREVIEW_IMAGE = 'previewImage'
......@@ -7,14 +9,14 @@ export const PreviewImageOptions: ApiOptions<API_TYPE_PREVIEW_IMAGE> = {
formatArgs: {
urls(urls, params) {
params.urls = urls.map((url) =>
typeof url === 'string' && url ? getRealPath(url) : ''
isString(url) && url ? getRealPath(url) : ''
)
},
current(current, params) {
if (typeof current === 'number') {
params.current =
current > 0 && current < params.urls.length ? current : 0
} else if (typeof current === 'string' && current) {
} else if (isString(current) && current) {
params.current = getRealPath(current)
}
},
......
import { isString } from '@vue/shared'
import { elemInArray, HTTP_METHODS } from '../../helpers/protocol'
export const API_CONNECT_SOCKET = 'connectSocket'
export type API_TYPE_CONNECT_SOCKET = typeof uni.connectSocket
......@@ -13,7 +14,7 @@ export const ConnectSocketOptions: ApiOptions<API_TYPE_CONNECT_SOCKET> = {
) as any
},
protocols(protocols, params) {
if (typeof protocols === 'string') {
if (isString(protocols)) {
params.protocols = [protocols]
}
},
......
import { isString } from '@vue/shared'
export function encodeQueryString(url: string) {
if (typeof url !== 'string') {
if (!isString(url)) {
return url
}
const index = url.indexOf('?')
......
import { isArray, isFunction, isPlainObject, remove } from '@vue/shared'
import {
isArray,
isFunction,
isPlainObject,
isString,
remove,
} from '@vue/shared'
import {
HOOKS,
......@@ -74,7 +80,7 @@ function dedupeHooks(hooks: Function[]) {
export const addInterceptor = defineSyncApi(
API_ADD_INTERCEPTOR,
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(
scopedInterceptors[method] || (scopedInterceptors[method] = {}),
interceptor
......@@ -89,7 +95,7 @@ export const addInterceptor = defineSyncApi(
export const removeInterceptor = defineSyncApi(
API_REMOVE_INTERCEPTOR,
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor)
} else {
......
......@@ -1452,7 +1452,7 @@ function rpx2px(str, replace = false) {
if (replace) {
return rpx2pxWithReplace(str);
}
if (typeof str === 'string') {
if (isString(str)) {
const res = parseInt(str) || 0;
if (hasRpx(str)) {
return uni.upx2px(res);
......@@ -9249,7 +9249,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -9257,7 +9257,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......@@ -11707,14 +11707,14 @@ const API_PREVIEW_IMAGE = 'previewImage';
const PreviewImageOptions = {
formatArgs: {
urls(urls, params) {
params.urls = urls.map((url) => typeof url === 'string' && url ? getRealPath(url) : '');
params.urls = urls.map((url) => isString(url) && url ? getRealPath(url) : '');
},
current(current, params) {
if (typeof current === 'number') {
params.current =
current > 0 && current < params.urls.length ? current : 0;
}
else if (typeof current === 'string' && current) {
else if (isString(current) && current) {
params.current = getRealPath(current);
}
},
......@@ -11968,7 +11968,7 @@ const ConnectSocketOptions = {
params.method = elemInArray((value || '').toUpperCase(), HTTP_METHODS);
},
protocols(protocols, params) {
if (typeof protocols === 'string') {
if (isString(protocols)) {
params.protocols = [protocols];
}
},
......@@ -11996,7 +11996,7 @@ const CloseSocketProtocol = {
};
function encodeQueryString(url) {
if (typeof url !== 'string') {
if (!isString(url)) {
return url;
}
const index = url.indexOf('?');
......@@ -12748,7 +12748,7 @@ const STORAGE_KEYS = 'uni-storage-keys';
function parseValue(value) {
const types = ['object', 'string', 'number', 'boolean', 'undefined'];
try {
const object = typeof value === 'string' ? JSON.parse(value) : value;
const object = isString(value) ? JSON.parse(value) : value;
const type = object.type;
if (types.indexOf(type) >= 0) {
const keys = Object.keys(object);
......@@ -12826,7 +12826,7 @@ function parseGetStorage(type, value) {
else if (type) {
// 兼容App端历史格式
data = object;
if (typeof object === 'string') {
if (isString(object)) {
object = JSON.parse(object);
const objectType = typeof object;
if (objectType === 'number' && type === 'date') {
......@@ -12847,7 +12847,7 @@ const getStorageSync = defineSyncApi(API_GET_STORAGE_SYNC, (key, t) => {
const value = plus.storage.getItem(key);
const typeOrigin = plus.storage.getItem(key + STORAGE_DATA_TYPE) || '';
const type = typeOrigin.toLowerCase();
if (typeof value !== 'string') {
if (!isString(value)) {
return '';
}
return parseGetStorage(type, value);
......@@ -13358,7 +13358,7 @@ function weexGetSystemInfoSync() {
return;
const { getSystemInfoSync } = weex.requireModule('plus');
systemInfo = getSystemInfoSync();
if (typeof systemInfo === 'string') {
if (isString(systemInfo)) {
try {
systemInfo = JSON.parse(systemInfo);
}
......@@ -14573,7 +14573,7 @@ const cookiesParse = (header) => {
return cookiesArr;
};
function formatResponse(res, args) {
if (typeof res.data === 'string' && res.data.charCodeAt(0) === 65279) {
if (isString(res.data) && res.data.charCodeAt(0) === 65279) {
res.data = res.data.slice(1);
}
res.statusCode = parseInt(String(res.statusCode), 10);
......@@ -14583,7 +14583,7 @@ function formatResponse(res, args) {
if (isArray(value)) {
ret[key] = value.join(',');
}
else if (typeof value === 'string') {
else if (isString(value)) {
ret[key] = value;
}
return ret;
......@@ -14638,7 +14638,7 @@ const request = defineTaskApi(API_REQUEST, (args, { resolve, reject }) => {
// TODO 需要重构
if (method !== 'GET' &&
header[name].indexOf('application/x-www-form-urlencoded') === 0 &&
typeof data !== 'string' &&
!isString(data) &&
!(data instanceof ArrayBuffer)) {
const bodyArray = [];
for (const key in data) {
......@@ -14680,7 +14680,7 @@ const request = defineTaskApi(API_REQUEST, (args, { resolve, reject }) => {
withArrayBuffer = true;
}
else {
options.body = typeof data === 'string' ? data : JSON.stringify(data);
options.body = isString(data) ? data : JSON.stringify(data);
}
}
const callback = ({ ok, status, data, headers, errorMsg, }) => {
......@@ -16735,7 +16735,7 @@ const TYPES = {
const parseParams = (args) => {
args.type = args.type || 0;
let { provider, type, title, summary: content, href, imageUrl, mediaUrl: media, scene, miniProgram, openCustomerServiceChat, corpid, customerUrl: url, } = args;
if (typeof imageUrl === 'string' && imageUrl) {
if (isString(imageUrl) && imageUrl) {
imageUrl = getRealPath(imageUrl);
}
const shareType = TYPES[type];
......@@ -16784,7 +16784,7 @@ const sendShareMsg = function (service, params, resolve, reject, method = 'share
const share = defineAsyncApi(API_SHREA, (params, { resolve, reject }) => {
const parsedParams = parseParams(params);
const errorCallback = warpPlusErrorCallback(reject);
if (typeof parsedParams === 'string') {
if (isString(parsedParams)) {
return reject(parsedParams);
}
plus.share.getServices((services) => {
......@@ -16804,7 +16804,7 @@ const share = defineAsyncApi(API_SHREA, (params, { resolve, reject }) => {
}, ShareProtocols, SahreOptions);
const shareWithSystem = defineAsyncApi(API_SHARE_WITH_SYSTEM, ({ type, imageUrl, summary, href }, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject);
if (typeof imageUrl === 'string' && imageUrl) {
if (isString(imageUrl) && imageUrl) {
imageUrl = getRealPath(imageUrl);
}
plus.share.sendWithSystem({
......
import { defineAsyncApi, defineSyncApi, getLocale } from '@dcloudio/uni-api'
import deviceId from '../../../helpers/uuid'
import { extend } from '@vue/shared'
import { extend, isString } from '@vue/shared'
import { getWindowInfo } from './getWindowInfo'
import { sortObject } from '@dcloudio/uni-shared'
......@@ -11,7 +11,7 @@ function weexGetSystemInfoSync() {
if (!_initSystemInfo) return
const { getSystemInfoSync } = weex.requireModule('plus')
systemInfo = getSystemInfoSync()
if (typeof systemInfo === 'string') {
if (isString(systemInfo)) {
try {
systemInfo = JSON.parse(systemInfo)
} catch (error) {}
......
import { hasOwn, isArray, isPlainObject } from '@vue/shared'
import { hasOwn, isArray, isPlainObject, isString } from '@vue/shared'
import {
API_REQUEST,
API_TYPE_REQUEST,
......@@ -53,7 +53,7 @@ const cookiesParse = (header: Record<string, string>) => {
}
function formatResponse(res: RequestTaskState, args: UniApp.RequestOptions) {
if (typeof res.data === 'string' && res.data.charCodeAt(0) === 65279) {
if (isString(res.data) && res.data.charCodeAt(0) === 65279) {
res.data = res.data.slice(1)
}
......@@ -64,7 +64,7 @@ function formatResponse(res: RequestTaskState, args: UniApp.RequestOptions) {
const value = res.header[key]
if (isArray(value)) {
;(ret as any)[key] = value.join(',')
} else if (typeof value === 'string') {
} else if (isString(value)) {
;(ret as any)[key] = value
}
return ret
......@@ -145,7 +145,7 @@ export const request = defineTaskApi<API_TYPE_REQUEST>(
if (
method !== 'GET' &&
header[name].indexOf('application/x-www-form-urlencoded') === 0 &&
typeof data !== 'string' &&
!isString(data) &&
!(data instanceof ArrayBuffer)
) {
const bodyArray = []
......@@ -191,7 +191,7 @@ export const request = defineTaskApi<API_TYPE_REQUEST>(
if (toString.call(data) === '[object ArrayBuffer]') {
withArrayBuffer = true
} else {
options.body = typeof data === 'string' ? data : JSON.stringify(data)
options.body = isString(data) ? data : JSON.stringify(data)
}
}
const callback: FetchCallback = ({
......
import { isString } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
import { warpPlusErrorCallback } from '../../../helpers/plus'
import {
......@@ -58,7 +59,7 @@ const parseParams = (args: UniApp.ShareOptions) => {
customerUrl: url,
} = args
if (typeof imageUrl === 'string' && imageUrl) {
if (isString(imageUrl) && imageUrl) {
imageUrl = getRealPath(imageUrl)
}
......@@ -123,7 +124,7 @@ export const share = defineAsyncApi<API_TYPE_SHARE>(
const parsedParams = parseParams(params)
const errorCallback = warpPlusErrorCallback(reject)
if (typeof parsedParams === 'string') {
if (isString(parsedParams)) {
return reject(parsedParams)
}
......@@ -152,7 +153,7 @@ export const shareWithSystem = defineAsyncApi<API_TYPE_SHARE_WITH_SYSTEM>(
({ type, imageUrl, summary, href }, { resolve, reject }) => {
const errorCallback = warpPlusErrorCallback(reject)
if (typeof imageUrl === 'string' && imageUrl) {
if (isString(imageUrl) && imageUrl) {
imageUrl = getRealPath(imageUrl)
}
plus.share.sendWithSystem(
......
import { isString } from '@vue/shared'
import {
defineSyncApi,
defineAsyncApi,
......@@ -28,7 +29,7 @@ const STORAGE_KEYS = 'uni-storage-keys'
function parseValue(value: any) {
const types = ['object', 'string', 'number', 'boolean', 'undefined']
try {
const object = typeof value === 'string' ? JSON.parse(value) : value
const object = isString(value) ? JSON.parse(value) : value
const type = object.type
if (types.indexOf(type) >= 0) {
const keys = Object.keys(object)
......@@ -116,7 +117,7 @@ function parseGetStorage(type: string, value: string) {
} else if (type) {
// 兼容App端历史格式
data = object
if (typeof object === 'string') {
if (isString(object)) {
object = JSON.parse(object)
const objectType = typeof object
if (objectType === 'number' && type === 'date') {
......@@ -140,7 +141,7 @@ export const getStorageSync = <API_TYPE_GET_STORAGE_SYNC>defineSyncApi(
const value = plus.storage.getItem(key)
const typeOrigin = plus.storage.getItem(key + STORAGE_DATA_TYPE) || ''
const type = typeOrigin.toLowerCase()
if (typeof value !== 'string') {
if (!isString(value)) {
return ''
}
return parseGetStorage(type, value)
......
......@@ -4,6 +4,7 @@ import {
isStaticExp,
NodeTypes,
} from '@vue/compiler-core'
import { isString } from '@vue/shared'
const tags = ['u-input', 'u-textarea']
export const transformModel: DirectiveTransform = (dir, node, context) => {
const result = baseTransform(dir, node, context)
......@@ -22,7 +23,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
key.content = 'onInput'
// 替换 $event 为 $event.detail.value
value.children = value.children.map((child) => {
if (typeof child === 'string') {
if (isString(child)) {
return child.replace(/=\s\$event/g, `= $event.detail.value`)
}
return child
......
......@@ -210,7 +210,7 @@ export function getMac() {
if (
// Node < v18
typeof item.family === 'string' &&
isString(item.family) &&
(item.family === 'IPv4' || item.family === 'IPv6')
) {
mac = item.mac
......
......@@ -4,6 +4,7 @@ import colors from 'picocolors'
import type { RollupError } from 'rollup'
import type { LogErrorOptions } from 'vite'
import { NodeTypes } from '@vue/compiler-core'
import { isString } from '@vue/shared'
import { normalizePath } from '../utils'
import { Formatter } from '../logs/format'
......@@ -63,9 +64,7 @@ const REMOVED_MSGS = [
]
export const removeInfoFormatter: Formatter = {
test(msg) {
return !!REMOVED_MSGS.find((m) =>
typeof m === 'string' ? msg.includes(m) : m(msg)
)
return !!REMOVED_MSGS.find((m) => (isString(m) ? msg.includes(m) : m(msg)))
},
format() {
return ''
......
import { once } from '@dcloudio/uni-shared'
import { isString } from '@vue/shared'
import { isInHBuilderX, runByHBuilderX } from '../hbx/env'
import { moduleAliasFormatter } from '../hbx/alias'
......@@ -62,7 +63,7 @@ const REMOVED_NVUE_MSGS = [
export const removeNVueInfoFormatter: Formatter = {
test(msg) {
return !!REMOVED_NVUE_MSGS.find((m) =>
typeof m === 'string' ? msg.includes(m) : m(msg)
isString(m) ? msg.includes(m) : m(msg)
)
},
format() {
......
......@@ -13,7 +13,7 @@ import {
import { AcornNode } from 'rollup'
import { walk } from 'estree-walker'
import { extend, isArray } from '@vue/shared'
import { extend, isArray, isString } from '@vue/shared'
import MagicString from 'magic-string'
import {
......@@ -133,7 +133,7 @@ export function uniViteInjectPlugin(
}
}
if (mod && !imports.has(name) && !scope.contains(name)) {
if (typeof mod === 'string') mod = [mod, 'default']
if (isString(mod)) mod = [mod, 'default']
if (mod[0] === id) return false
const hash = `${keypath}:${mod[0]}:${mod[1]}`
// 当 API 被覆盖定义后,不再摇树
......
......@@ -9,7 +9,7 @@ import { Plugin } from '../plugin'
import { ResolvedConfig } from '../config'
import { cleanUrl, normalizePath } from '../utils'
import { withSourcemap } from '../../../../vite/utils/utils'
import { isFunction } from '@vue/shared'
import { isFunction, isString } from '@vue/shared'
export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g
......@@ -197,10 +197,10 @@ export function assetFileNamesToFileName(
source: content,
type: 'asset',
})
if (typeof assetFileNames !== 'string') {
if (!isString(assetFileNames)) {
throw new TypeError('assetFileNames must return a string')
}
} else if (typeof assetFileNames !== 'string') {
} else if (!isString(assetFileNames)) {
throw new TypeError('assetFileNames must be a string or a function')
}
......
......@@ -40,7 +40,7 @@ import { transform, formatMessages } from 'esbuild'
import { preCss, preNVueCss } from '../../../../preprocess'
import { PAGES_JSON_JS } from '../../../../constants'
import { emptyCssComments } from '../cleanString'
import { isArray, isFunction } from '@vue/shared'
import { isArray, isFunction, isString } from '@vue/shared'
// const debug = createDebugger('vite:css')
export interface CSSOptions {
......@@ -711,8 +711,7 @@ async function resolvePostcssConfig(
plugins: inlineOptions.plugins || [],
}
} else {
const searchPath =
typeof inlineOptions === 'string' ? inlineOptions : config.root
const searchPath = isString(inlineOptions) ? inlineOptions : config.root
try {
// @ts-ignore
result = await postcssrc({}, searchPath)
......@@ -1152,8 +1151,7 @@ async function rebaseUrls(
if (url.startsWith('/')) return url
// match alias, no need to rewrite
for (const { find } of alias) {
const matches =
typeof find === 'string' ? url.startsWith(find) : find.test(url)
const matches = isString(find) ? url.startsWith(find) : find.test(url)
if (matches) {
return url
}
......@@ -1397,7 +1395,7 @@ async function getSource(
if (isFunction(additionalData)) {
const newContent = await additionalData(source, filename)
if (typeof newContent === 'string') {
if (isString(newContent)) {
return { content: newContent }
}
return newContent
......
import { createElementVNode, defineComponent, createVNode, mergeProps, getCurrentInstance, provide, watch, onUnmounted, shallowRef, reactive, watchEffect, ref, inject, onBeforeUnmount, computed, Text as Text$1, isVNode, Fragment, onMounted, resolveComponent, parseClassList } from "vue";
import { extend, hasOwn, isFunction, isPlainObject, isArray } from "@vue/shared";
import { extend, hasOwn, isFunction, isPlainObject, isArray, isString } from "@vue/shared";
import { cacheStringFunction, PRIMARY_COLOR } from "@dcloudio/uni-shared";
const OPEN_TYPES = [
"navigate",
......@@ -2342,7 +2342,7 @@ function useState(props2) {
const dom = weex.requireModule("dom");
const isAndroid$1 = weex.config.env.platform.toLowerCase() === "android";
function getStyle(val) {
return extend({}, typeof val === "string" ? parseStyleText(val) : val);
return extend({}, isString(val) ? parseStyleText(val) : val);
}
var PickerViewColumn = defineComponent({
name: "PickerViewColumn",
......@@ -4090,7 +4090,7 @@ function useSwiperListeners(state, props2, swiperItems, trigger) {
}
};
const onChange = (event) => {
if (typeof event.detail.source === "string") {
if (isString(event.detail.source)) {
state.currentChangeSource = event.detail.source;
}
state.currentSync = event.detail.index;
......@@ -4395,7 +4395,7 @@ var RichText = defineComponent({
const instance = getCurrentInstance();
return () => {
let nodes = props2.nodes;
if (typeof nodes === "string") {
if (isString(nodes)) {
nodes = parseHtml(nodes);
}
return createVNode(resolveComponent("u-rich-text"), {
......
import { getCurrentInstance, inject, onBeforeUnmount } from 'vue'
import { isString } from '@vue/shared'
import { UniFormCtx, uniFormKey } from '../vue/form'
interface ValueState {
......@@ -24,11 +25,11 @@ export function useFormField(
const proxy = instance.proxy
return [
(proxy as any)[nameKey],
typeof value === 'string' ? (proxy as any)[value] : value.value,
isString(value) ? (proxy as any)[value] : value.value,
]
},
reset() {
if (typeof value === 'string') {
if (isString(value)) {
;(instance.proxy as any)[value] = ''
} else {
value.value = ''
......
......@@ -9,7 +9,7 @@ import {
getCurrentInstance,
onMounted,
} from 'vue'
import { extend } from '@vue/shared'
import { extend, isString } from '@vue/shared'
import { Props, GetPickerViewColumn } from '../picker-view'
import { parseStyleText, getComponentSize } from '../helpers'
......@@ -24,7 +24,7 @@ type ScrollOptions = {
const dom = weex.requireModule('dom')
const isAndroid = weex.config.env.platform.toLowerCase() === 'android'
function getStyle(val: string) {
return extend({}, typeof val === 'string' ? parseStyleText(val) : val)
return extend({}, isString(val) ? parseStyleText(val) : val)
}
export default defineComponent({
......
......@@ -6,7 +6,7 @@ import {
// @ts-ignore
parseClassList,
} from 'vue'
import { isArray } from '@vue/shared'
import { isArray, isString } from '@vue/shared'
import { props, parseHtml } from '../../components/rich-text'
import { parseStyleText } from '../helpers'
......@@ -21,7 +21,7 @@ export default defineComponent({
return () => {
let nodes = props.nodes
if (typeof nodes === 'string') {
if (isString(nodes)) {
nodes = parseHtml(nodes)
}
......
......@@ -8,6 +8,7 @@ import {
ExtractPropTypes,
VNode,
} from 'vue'
import { isString } from '@vue/shared'
import {
useCustomEvent,
EmitEvent,
......@@ -181,7 +182,7 @@ function useSwiperListeners(
}
const onChange = (event: any) => {
if (typeof event.detail.source === 'string') {
if (isString(event.detail.source)) {
state.currentChangeSource = event.detail.source
}
state.currentSync = event.detail.index
......
import { extend } from '@vue/shared'
import { extend, isString } from '@vue/shared'
import { onMounted, Ref, watch } from 'vue'
import QuillClass, {
QuillOptionsStatic,
......@@ -236,7 +236,7 @@ export function useQuill(
}
if (delta.ops) {
delta.ops = delta.ops
.filter(({ insert }) => typeof insert === 'string')
.filter(({ insert }) => isString(insert))
.map(({ insert }) => ({ insert }))
}
return delta
......@@ -371,7 +371,7 @@ export function useQuill(
const { delta, html } = options
if (typeof delta === 'object') {
quill.setContents(delta, 'silent')
} else if (typeof html === 'string') {
} else if (isString(html)) {
quill.setContents(html2delta(html), 'silent')
} else {
errMsg = 'contents is missing'
......
import { isString } from '@vue/shared'
const scripts: Record<string, Function[]> = {}
interface WindowExt extends Window {
......@@ -9,10 +11,9 @@ export default function loadScript(
src: string,
callback: () => void
) {
const globalObject =
typeof globalName === 'string'
? (window as WindowExt)[globalName]
: globalName
const globalObject = isString(globalName)
? (window as WindowExt)[globalName]
: globalName
if (globalObject) {
callback()
return
......
import { ref, watch, getCurrentInstance, h, VNode } from 'vue'
import { isString } from '@vue/shared'
import {
defineBuiltInComponent,
useCustomEvent,
......@@ -35,7 +36,7 @@ export default /*#__PURE__*/ defineBuiltInComponent({
function renderVNode() {
let nodeList = props.nodes
if (typeof nodeList === 'string') {
if (isString(nodeList)) {
nodeList = parseHtml(props.nodes)
}
_vnode.value = nodeList2VNode(scopeId, triggerItemClick, nodeList as [])
......
import { hasOwn, extend, isPlainObject, isArray } from '@vue/shared'
import { hasOwn, extend, isPlainObject, isArray, isString } from '@vue/shared'
import { getRealPath } from '@dcloudio/uni-platform'
import { createTextVNode, h, VNode } from 'vue'
......@@ -166,11 +166,7 @@ export const nodeList2VNode = /*#__PURE__*/ (
nodeList2VNode(scopeId, triggerItemClick, node.children)
)
}
if (
node.type === 'text' &&
typeof node.text === 'string' &&
node.text !== ''
)
if (node.type === 'text' && isString(node.text) && node.text !== '')
return createTextVNode(decodeEntities(node.text || ''))
})
}
import { isString } from '@vue/shared'
export function PolySymbol(name: string) {
return Symbol(__DEV__ ? '[uni-app]: ' + name : name)
}
......@@ -16,7 +17,7 @@ export function rpx2px(str: string | number, replace = false) {
if (__NODE_JS__) {
return parseInt(str + '')
}
if (typeof str === 'string') {
if (isString(str)) {
const res = parseInt(str) || 0
if (hasRpx(str)) {
return uni.upx2px(res)
......
......@@ -2,6 +2,7 @@ import { ComponentInternalInstance, ComponentPublicInstance } from 'vue'
import {
isFunction,
isPlainObject,
isString,
parseStringStyle,
stringifyStyle,
} from '@vue/shared'
......@@ -112,7 +113,7 @@ export class ComponentDescriptor {
if (!this.$el || !style) {
return this
}
if (typeof style === 'string') {
if (isString(style)) {
style = parseStringStyle(style)
}
if (isPlainObject(style)) {
......
......@@ -11,7 +11,7 @@ import {
isExternalUrl,
} from '@dcloudio/uni-cli-shared'
import { OutputOptions } from 'rollup'
import { isFunction } from '@vue/shared'
import { isFunction, isString } from '@vue/shared'
function isCombineBuiltInCss(config: ResolvedConfig) {
return config.command === 'build' && config.build.cssCodeSplit
......@@ -133,10 +133,10 @@ export function assetFileNamesToFileName(
source: content,
type: 'asset',
})
if (typeof assetFileNames !== 'string') {
if (!isString(assetFileNames)) {
throw new TypeError('assetFileNames must return a string')
}
} else if (typeof assetFileNames !== 'string') {
} else if (!isString(assetFileNames)) {
throw new TypeError('assetFileNames must be a string or a function')
}
......
......@@ -44,7 +44,7 @@ function serializeDefine(define: Record<string, any>): string {
for (const key in define) {
const val = define[key]
res += `${JSON.stringify(key)}: ${
typeof val === 'string' ? `(${val})` : JSON.stringify(val)
isString(val) ? `(${val})` : JSON.stringify(val)
}, `
}
return res + `}`
......
......@@ -2812,11 +2812,11 @@ function useFormField(nameKey, value) {
const proxy = instance.proxy;
return [
proxy[nameKey],
typeof value === "string" ? proxy[value] : value.value
shared.isString(value) ? proxy[value] : value.value
];
},
reset() {
if (typeof value === "string") {
if (shared.isString(value)) {
instance.proxy[value] = "";
} else {
value.value = "";
......@@ -5082,7 +5082,7 @@ const nodeList2VNode = (scopeId, triggerItemClick, nodeList) => {
nodeProps = shared.extend(nodeProps, processClickEvent(node, triggerItemClick), node.attrs);
return vue.h(node.name, nodeProps, nodeList2VNode(scopeId, triggerItemClick, node.children));
}
if (node.type === "text" && typeof node.text === "string" && node.text !== "")
if (node.type === "text" && shared.isString(node.text) && node.text !== "")
return vue.createTextVNode(decodeEntities(node.text || ""));
});
};
......@@ -5204,7 +5204,7 @@ var index$p = /* @__PURE__ */ defineBuiltInComponent({
}
function renderVNode() {
let nodeList = props2.nodes;
if (typeof nodeList === "string") {
if (shared.isString(nodeList)) {
nodeList = parseHtml(props2.nodes);
}
_vnode.value = nodeList2VNode(scopeId, triggerItemClick, nodeList);
......@@ -9797,7 +9797,7 @@ const request = /* @__PURE__ */ defineTaskApi(API_REQUEST, ({
let body = null;
const contentType = normalizeContentType(header);
if (method !== "GET") {
if (typeof data === "string" || data instanceof ArrayBuffer) {
if (shared.isString(data) || data instanceof ArrayBuffer) {
body = data;
} else {
if (contentType === "json") {
......@@ -9911,7 +9911,7 @@ const STORAGE_KEYS = "uni-storage-keys";
function parseValue(value) {
const types = ["object", "string", "number", "boolean", "undefined"];
try {
const object = typeof value === "string" ? JSON.parse(value) : value;
const object = shared.isString(value) ? JSON.parse(value) : value;
const type = object.type;
if (types.indexOf(type) >= 0) {
const keys = Object.keys(object);
......@@ -9947,7 +9947,7 @@ const setStorage = /* @__PURE__ */ defineAsyncApi(API_SET_STORAGE, ({ key, data
}, SetStorageProtocol);
function getStorageOrigin(key) {
const value = localStorage && localStorage.getItem(key);
if (typeof value !== "string") {
if (!shared.isString(value)) {
throw new Error("data not found");
}
let data = value;
......
......@@ -766,7 +766,7 @@ function rpx2px(str, replace = false) {
if (replace) {
return rpx2pxWithReplace(str);
}
if (typeof str === "string") {
if (isString(str)) {
const res = parseInt(str) || 0;
if (hasRpx(str)) {
return uni.upx2px(res);
......@@ -1101,7 +1101,7 @@ class ComponentDescriptor {
if (!this.$el || !style) {
return this;
}
if (typeof style === "string") {
if (isString(style)) {
style = parseStringStyle(style);
}
if (isPlainObject(style)) {
......@@ -2911,14 +2911,14 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = /* @__PURE__ */ defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === "string" && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
} else if (isPlainObject(method)) {
mergeInterceptorHook(globalInterceptors, method);
}
}, AddInterceptorProtocol);
const removeInterceptor = /* @__PURE__ */ defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === "string") {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
} else {
......@@ -4937,12 +4937,12 @@ const API_PREVIEW_IMAGE = "previewImage";
const PreviewImageOptions = {
formatArgs: {
urls(urls, params) {
params.urls = urls.map((url) => typeof url === "string" && url ? getRealPath(url) : "");
params.urls = urls.map((url) => isString(url) && url ? getRealPath(url) : "");
},
current(current, params) {
if (typeof current === "number") {
params.current = current > 0 && current < params.urls.length ? current : 0;
} else if (typeof current === "string" && current) {
} else if (isString(current) && current) {
params.current = getRealPath(current);
}
}
......@@ -5105,7 +5105,7 @@ const ConnectSocketOptions = {
params.method = elemInArray((value || "").toUpperCase(), HTTP_METHODS);
},
protocols(protocols, params) {
if (typeof protocols === "string") {
if (isString(protocols)) {
params.protocols = [protocols];
}
}
......@@ -5132,7 +5132,7 @@ const CloseSocketProtocol = {
reason: String
};
function encodeQueryString(url) {
if (typeof url !== "string") {
if (!isString(url)) {
return url;
}
const index2 = url.indexOf("?");
......@@ -7342,7 +7342,7 @@ function makeMap(str) {
}
const scripts = {};
function loadScript(globalName, src, callback) {
const globalObject = typeof globalName === "string" ? window[globalName] : globalName;
const globalObject = isString(globalName) ? window[globalName] : globalName;
if (globalObject) {
callback();
return;
......@@ -7776,7 +7776,7 @@ function useQuill(props2, rootRef, trigger) {
return delta;
}
if (delta.ops) {
delta.ops = delta.ops.filter(({ insert }) => typeof insert === "string").map(({ insert }) => ({ insert }));
delta.ops = delta.ops.filter(({ insert }) => isString(insert)).map(({ insert }) => ({ insert }));
}
return delta;
});
......@@ -7891,7 +7891,7 @@ function useQuill(props2, rootRef, trigger) {
const { delta, html } = options;
if (typeof delta === "object") {
quill.setContents(delta, "silent");
} else if (typeof html === "string") {
} else if (isString(html)) {
quill.setContents(html2delta(html), "silent");
} else {
errMsg = "contents is missing";
......@@ -8385,11 +8385,11 @@ function useFormField(nameKey, value) {
const proxy = instance2.proxy;
return [
proxy[nameKey],
typeof value === "string" ? proxy[value] : value.value
isString(value) ? proxy[value] : value.value
];
},
reset() {
if (typeof value === "string") {
if (isString(value)) {
instance2.proxy[value] = "";
} else {
value.value = "";
......@@ -11789,7 +11789,7 @@ const nodeList2VNode = (scopeId, triggerItemClick, nodeList) => {
nodeProps = extend(nodeProps, processClickEvent(node, triggerItemClick), node.attrs);
return h(node.name, nodeProps, nodeList2VNode(scopeId, triggerItemClick, node.children));
}
if (node.type === "text" && typeof node.text === "string" && node.text !== "")
if (node.type === "text" && isString(node.text) && node.text !== "")
return createTextVNode(decodeEntities(node.text || ""));
});
};
......@@ -11911,7 +11911,7 @@ var index$m = /* @__PURE__ */ defineBuiltInComponent({
}
function renderVNode() {
let nodeList = props2.nodes;
if (typeof nodeList === "string") {
if (isString(nodeList)) {
nodeList = parseHtml(props2.nodes);
}
_vnode.value = nodeList2VNode(scopeId, triggerItemClick, nodeList);
......@@ -16981,7 +16981,7 @@ const STORAGE_KEYS = "uni-storage-keys";
function parseValue(value) {
const types = ["object", "string", "number", "boolean", "undefined"];
try {
const object = typeof value === "string" ? JSON.parse(value) : value;
const object = isString(value) ? JSON.parse(value) : value;
const type = object.type;
if (types.indexOf(type) >= 0) {
const keys = Object.keys(object);
......@@ -17017,7 +17017,7 @@ const setStorage = /* @__PURE__ */ defineAsyncApi(API_SET_STORAGE, ({ key, data
}, SetStorageProtocol);
function getStorageOrigin(key) {
const value = localStorage && localStorage.getItem(key);
if (typeof value !== "string") {
if (!isString(value)) {
throw new Error("data not found");
}
let data = value;
......@@ -17661,7 +17661,7 @@ const request = /* @__PURE__ */ defineTaskApi(API_REQUEST, ({
let body = null;
const contentType = normalizeContentType(header);
if (method !== "GET") {
if (typeof data === "string" || data instanceof ArrayBuffer) {
if (isString(data) || data instanceof ArrayBuffer) {
body = data;
} else {
if (contentType === "json") {
......@@ -18048,7 +18048,7 @@ ${e2};at socketTask.on${capitalize(name)} callback function
try {
const code = options.code || 1e3;
const reason = options.reason;
if (typeof reason === "string") {
if (isString(reason)) {
ws.close(code, reason);
} else {
ws.close(code);
......
import { hasOwn } from '@vue/shared'
import { hasOwn, isString } from '@vue/shared'
import {
API_REQUEST,
API_TYPE_REQUEST,
......@@ -27,7 +27,7 @@ export const request = defineTaskApi<API_TYPE_REQUEST>(
// 根据请求类型处理数据
const contentType = normalizeContentType(header)
if (method !== 'GET') {
if (typeof data === 'string' || data instanceof ArrayBuffer) {
if (isString(data) || data instanceof ArrayBuffer) {
body = data
} else {
if (contentType === 'json') {
......
import { extend, capitalize, isFunction } from '@vue/shared'
import { extend, capitalize, isFunction, isString } from '@vue/shared'
import {
defineTaskApi,
defineAsyncApi,
......@@ -133,7 +133,7 @@ class SocketTask implements UniApp.SocketTask {
try {
const code = options.code || 1000
const reason = options.reason
if (typeof reason === 'string') {
if (isString(reason)) {
ws.close(code, reason)
} else {
ws.close(code)
......
import { isString } from '@vue/shared'
import {
defineSyncApi,
defineAsyncApi,
......@@ -25,7 +27,7 @@ const STORAGE_KEYS = 'uni-storage-keys'
function parseValue(value: any) {
const types = ['object', 'string', 'number', 'boolean', 'undefined']
try {
const object = typeof value === 'string' ? JSON.parse(value) : value
const object = isString(value) ? JSON.parse(value) : value
const type = object.type
if (types.indexOf(type) >= 0) {
const keys = Object.keys(object)
......@@ -80,7 +82,7 @@ export const setStorage = <API_TYPE_SET_STORAGE>defineAsyncApi(
function getStorageOrigin(key: string): any {
const value = localStorage && localStorage.getItem(key)
if (typeof value !== 'string') {
if (!isString(value)) {
throw new Error('data not found')
}
let data: any = value
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......@@ -1036,7 +1036,7 @@ const getProvider = initGetProvider({
});
function requestPayment(params) {
let parseError = false;
if (typeof params.orderInfo === 'string') {
if (isString(params.orderInfo)) {
try {
params.orderInfo = JSON.parse(params.orderInfo);
}
......
import { isString } from '@vue/shared'
import { initGetProvider } from '@dcloudio/uni-mp-core'
export const getProvider = initGetProvider({
......@@ -9,7 +10,7 @@ export const getProvider = initGetProvider({
export function requestPayment(params: UniApp.RequestPaymentOptions) {
let parseError = false
if (typeof params.orderInfo === 'string') {
if (isString(params.orderInfo)) {
try {
params.orderInfo = JSON.parse(params.orderInfo)
} catch (e) {
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -424,7 +424,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -432,7 +432,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -460,7 +460,7 @@ function dedupeHooks(hooks) {
return res;
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
if (isString(method) && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
}
else if (isPlainObject(method)) {
......@@ -468,7 +468,7 @@ const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor)
}
}, AddInterceptorProtocol);
const removeInterceptor = defineSyncApi(API_REMOVE_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string') {
if (isString(method)) {
if (isPlainObject(interceptor)) {
removeInterceptorHook(scopedInterceptors[method], interceptor);
}
......
......@@ -373,7 +373,7 @@ function formatDateTime({ date = new Date(), mode = 'date' }) {
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
if (shared.isString(data)) {
data = {
errMsg: data,
};
......
import { isHTMLTag, isSVGTag, hyphenate, camelize, isFunction, isString, isPlainObject, extend, isArray, toTypeString, toRawType, capitalize } from '@vue/shared';
import { isHTMLTag, isSVGTag, hyphenate, camelize, isString, isFunction, isPlainObject, extend, isArray, toTypeString, toRawType, capitalize } from '@vue/shared';
const BUILT_IN_TAG_NAMES = [
'ad',
......@@ -369,7 +369,7 @@ function formatDateTime({ date = new Date(), mode = 'date' }) {
}
function callOptions(options, data) {
options = options || {};
if (typeof data === 'string') {
if (isString(data)) {
data = {
errMsg: data,
};
......
......@@ -95,7 +95,7 @@ export function callOptions(
data: { [key: string]: any; errMsg: string } | string
): void {
options = options || {}
if (typeof data === 'string') {
if (isString(data)) {
data = {
errMsg: data,
}
......
import { Plugin, ResolvedConfig } from 'vite'
import { extend } from '@vue/shared'
import { extend, isString } from '@vue/shared'
import {
checkUpdate,
isWindows,
......@@ -31,7 +31,7 @@ export function createConfigResolved(options: VitePluginUniResolvedOptions) {
// TODO 等 https://github.com/vitejs/vite/issues/3331 修复后,可以移除下列代码
// 2.8.0 已修复,但为了兼容旧版本,先不移除
const item = config.resolve.alias.find((item) =>
typeof item.find !== 'string' ? item.find.test('@/') : false
!isString(item.find) ? item.find.test('@/') : false
)
if (item) {
item.customResolver = customResolver
......
import path from 'path'
import debug from 'debug'
import { extend } from '@vue/shared'
import { extend, isString } from '@vue/shared'
import { Plugin, ResolvedConfig } from 'vite'
import { FilterPattern } from '@rollup/pluginutils'
......@@ -89,7 +89,7 @@ function addPlugin(
index: string | number,
type: 'pre' | 'post' = 'post'
) {
if (typeof index === 'string') {
if (isString(index)) {
index = plugins.findIndex((plugin) => (plugin as Plugin).name === index)
}
return plugins.splice(index + (type === 'pre' ? 0 : 1), 0, plugin)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册