chore: add isFunction utils and improve isObject
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
* Create a basic component with common options
|
||||
*/
|
||||
import '../../locale';
|
||||
import { isFunction } from '..';
|
||||
import { camelize } from '../format/string';
|
||||
import { SlotsMixin } from '../../mixins/slots';
|
||||
import Vue, {
|
||||
@@ -68,7 +69,7 @@ export function createComponent(name: string) {
|
||||
return function<Props = DefaultProps, Events = {}, Slots = {}>(
|
||||
sfc: VantComponentOptions | FunctionComponent
|
||||
): TsxComponent<Props, Events, Slots> {
|
||||
if (typeof sfc === 'function') {
|
||||
if (isFunction(sfc)) {
|
||||
sfc = transformFunctionComponent(sfc);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { get } from '..';
|
||||
import { get, isFunction } from '..';
|
||||
import { camelize } from '../format/string';
|
||||
import locale from '../../locale';
|
||||
|
||||
@@ -9,7 +9,7 @@ export function createI18N(name: string) {
|
||||
const messages = locale.messages();
|
||||
const message = get(messages, prefix + path) || get(messages, path);
|
||||
|
||||
return typeof message === 'function' ? message(...args) : message;
|
||||
return isFunction(message) ? message(...args) : message;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isDef, isObj } from '.';
|
||||
import { isDef, isObject } from '.';
|
||||
import { ObjectIndex } from './types';
|
||||
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
@@ -10,11 +10,7 @@ function assignKey(to: ObjectIndex, from: ObjectIndex, key: string) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!hasOwnProperty.call(to, key) ||
|
||||
!isObj(val) ||
|
||||
typeof val === 'function'
|
||||
) {
|
||||
if (!hasOwnProperty.call(to, key) || !isObject(val)) {
|
||||
to[key] = val;
|
||||
} else {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
|
||||
+8
-5
@@ -7,13 +7,16 @@ export const isServer: boolean = Vue.prototype.$isServer;
|
||||
|
||||
export function noop() {}
|
||||
|
||||
export function isDef(value: any): boolean {
|
||||
return value !== undefined && value !== null;
|
||||
export function isDef(val: any): boolean {
|
||||
return val !== undefined && val !== null;
|
||||
}
|
||||
|
||||
export function isObj(x: any): boolean {
|
||||
const type = typeof x;
|
||||
return x !== null && (type === 'object' || type === 'function');
|
||||
export function isFunction(val: unknown): val is Function {
|
||||
return typeof val === 'function';
|
||||
}
|
||||
|
||||
export function isObject(val: any): val is Record<any, any> {
|
||||
return val !== null && typeof val === 'object';
|
||||
}
|
||||
|
||||
export function get(object: any, path: string): any {
|
||||
|
||||
Reference in New Issue
Block a user