@formily/shared
Advanced tools
Comparing version 2.0.0-beta.2 to 2.0.0-beta.3
@@ -13,23 +13,23 @@ declare type EachArrayIterator<T> = (currentValue: T, key: number) => void | boolean; | ||
export declare function each<T>(val: T[], iterator: EachArrayIterator<T>, revert?: boolean): void; | ||
export declare function each<T extends {}, TValue>(val: T, iterator: EachObjectIterator<TValue>, revert?: boolean): void; | ||
export declare function map<T>(val: string, iterator: MapStringIterator<T>, revert?: boolean): any; | ||
export declare function map<TItem, TResult>(val: TItem[], iterator: MapArrayIterator<TItem, TResult>, revert?: boolean): any; | ||
export declare function map<T extends {}, TResult>(val: T, iterator: MapObjectIterator<T[keyof T], TResult>, revert?: boolean): any; | ||
export declare function each<T extends {}, TValue extends T[keyof T]>(val: T, iterator: EachObjectIterator<TValue>, revert?: boolean): void; | ||
export declare function map<T>(val: string, iterator: MapStringIterator<T>, revert?: boolean): T[]; | ||
export declare function map<TItem, TResult>(val: TItem[], iterator: MapArrayIterator<TItem, TResult>, revert?: boolean): TResult[]; | ||
export declare function map<T extends {}, TResult>(val: T, iterator: MapObjectIterator<T[keyof T], TResult>, revert?: boolean): Record<keyof T, TResult>; | ||
export declare function reduce<T, U>(val: T[], iterator: MemoArrayIterator<T, U>, accumulator?: U, revert?: boolean): U; | ||
export declare function reduce<T>(val: string, iterator: MemoStringIterator<T>, accumulator?: T, revert?: boolean): T; | ||
export declare function reduce<T extends {}, TValue, TResult = any>(val: T, iterator: MemoObjectIterator<TValue, TResult>, accumulator?: TResult, revert?: boolean): TResult; | ||
export declare function reduce<T extends {}, TValue extends T[keyof T], TResult = any>(val: T, iterator: MemoObjectIterator<TValue, TResult>, accumulator?: TResult, revert?: boolean): TResult; | ||
export declare function every<T extends string>(val: T, iterator: EachStringIterator, revert?: boolean): boolean; | ||
export declare function every<T>(val: T[], iterator: EachArrayIterator<T>, revert?: boolean): boolean; | ||
export declare function every<T extends {}, TValue>(val: T, iterator: EachObjectIterator, revert?: boolean): boolean; | ||
export declare function every<T extends {}, TValue extends T[keyof T]>(val: T, iterator: EachObjectIterator, revert?: boolean): boolean; | ||
export declare function some<T extends string>(val: T, iterator: EachStringIterator, revert?: boolean): boolean; | ||
export declare function some<T>(val: T[], iterator: EachArrayIterator<T>, revert?: boolean): boolean; | ||
export declare function some<T extends {}, TValue>(val: T, iterator: EachObjectIterator, revert?: boolean): boolean; | ||
export declare function some<T extends {}, TValue extends T[keyof T]>(val: T, iterator: EachObjectIterator, revert?: boolean): boolean; | ||
export declare function findIndex<T extends string>(val: T, iterator: EachStringIterator, revert?: boolean): number; | ||
export declare function findIndex<T>(val: T[], iterator: EachArrayIterator<T>, revert?: boolean): number; | ||
export declare function findIndex<T extends {}, TValue>(val: T, iterator: EachObjectIterator, revert?: boolean): keyof T; | ||
export declare function findIndex<T extends {}, TValue extends T[keyof T]>(val: T, iterator: EachObjectIterator, revert?: boolean): keyof T; | ||
export declare function find<T extends string>(val: T, iterator: EachStringIterator, revert?: boolean): any; | ||
export declare function find<T>(val: T[], iterator: EachArrayIterator<T>, revert?: boolean): T; | ||
export declare function find<T extends {}, TValue>(val: T, iterator: EachObjectIterator, revert?: boolean): T[keyof T]; | ||
export declare function find<T extends {}, TValue extends T[keyof T]>(val: T, iterator: EachObjectIterator, revert?: boolean): T[keyof T]; | ||
export declare function includes<T extends string>(val: T, searchElement: string, revert?: boolean): boolean; | ||
export declare function includes<T>(val: T[], searchElement: T, revert?: boolean): boolean; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.includes = exports.find = exports.findIndex = exports.some = exports.every = exports.reduce = exports.map = exports.each = exports.toArr = void 0; | ||
var types_1 = require("./types"); | ||
exports.toArr = function (val) { return (types_1.isArr(val) ? val : val ? [val] : []); }; | ||
var toArr = function (val) { return (types_1.isArr(val) ? val : val ? [val] : []); }; | ||
exports.toArr = toArr; | ||
function each(val, iterator, revert) { | ||
@@ -6,0 +8,0 @@ if (types_1.isArr(val) || types_1.isStr(val)) { |
@@ -1,4 +0,6 @@ | ||
import camelCase from 'camel-case'; | ||
import lowercase from 'lower-case'; | ||
import uppercase from 'upper-case'; | ||
export { camelCase, lowercase, uppercase }; | ||
import { camelCase } from 'camel-case'; | ||
import { pascalCase } from 'pascal-case'; | ||
import { lowerCase } from 'lower-case'; | ||
import { upperCase } from 'upper-case'; | ||
import { paramCase } from 'param-case'; | ||
export { lowerCase, upperCase, camelCase, pascalCase, paramCase }; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var camel_case_1 = __importDefault(require("camel-case")); | ||
exports.camelCase = camel_case_1.default; | ||
var lower_case_1 = __importDefault(require("lower-case")); | ||
exports.lowercase = lower_case_1.default; | ||
var upper_case_1 = __importDefault(require("upper-case")); | ||
exports.uppercase = upper_case_1.default; | ||
exports.paramCase = exports.pascalCase = exports.camelCase = exports.upperCase = exports.lowerCase = void 0; | ||
var camel_case_1 = require("camel-case"); | ||
Object.defineProperty(exports, "camelCase", { enumerable: true, get: function () { return camel_case_1.camelCase; } }); | ||
var pascal_case_1 = require("pascal-case"); | ||
Object.defineProperty(exports, "pascalCase", { enumerable: true, get: function () { return pascal_case_1.pascalCase; } }); | ||
var lower_case_1 = require("lower-case"); | ||
Object.defineProperty(exports, "lowerCase", { enumerable: true, get: function () { return lower_case_1.lowerCase; } }); | ||
var upper_case_1 = require("upper-case"); | ||
Object.defineProperty(exports, "upperCase", { enumerable: true, get: function () { return upper_case_1.upperCase; } }); | ||
var param_case_1 = require("param-case"); | ||
Object.defineProperty(exports, "paramCase", { enumerable: true, get: function () { return param_case_1.paramCase; } }); |
@@ -1,4 +0,2 @@ | ||
declare type Filter = (value: any, key: string) => boolean; | ||
export declare const shallowClone: (values: any) => any; | ||
export declare const clone: (values: any, filter?: Filter) => any; | ||
export {}; | ||
export declare const clone: (values: any) => any; |
110
lib/clone.js
@@ -14,95 +14,60 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clone = exports.shallowClone = void 0; | ||
var types_1 = require("./types"); | ||
var instanceof_1 = require("./instanceof"); | ||
var big_data_1 = require("./big-data"); | ||
var NATIVE_KEYS = [ | ||
['Map', function (map) { return new Map(map); }], | ||
['WeakMap', function (map) { return new WeakMap(map); }], | ||
['WeakSet', function (set) { return new WeakSet(set); }], | ||
['Set', function (set) { return new Set(set); }], | ||
['Date', function (date) { return new Date(date); }], | ||
'FileList', | ||
'File', | ||
'URL', | ||
'RegExp', | ||
[ | ||
'Promise', | ||
function (promise) { | ||
return new Promise(function (resolve, reject) { return promise.then(resolve, reject); }); | ||
var shallowClone = function (values) { | ||
if (Array.isArray(values)) { | ||
return values.slice(0); | ||
} | ||
else if (types_1.isPlainObj(values)) { | ||
if ('$$typeof' in values && '_owner' in values) { | ||
return values; | ||
} | ||
] | ||
]; | ||
var isNativeObject = function (values) { | ||
for (var i = 0; i < NATIVE_KEYS.length; i++) { | ||
var item = NATIVE_KEYS[i]; | ||
if (Array.isArray(item) && item[0]) { | ||
if (instanceof_1.instOf(values, item[0])) { | ||
return item[1] ? item[1] : item[0]; | ||
} | ||
if (values['_isAMomentObject']) { | ||
return values; | ||
} | ||
else { | ||
if (instanceof_1.instOf(values, item)) { | ||
return item; | ||
} | ||
if (values['_isJSONSchemaObject']) { | ||
return values; | ||
} | ||
if (types_1.isFn(values['toJS'])) { | ||
return values; | ||
} | ||
if (types_1.isFn(values['toJSON'])) { | ||
return values; | ||
} | ||
return __assign({}, values); | ||
} | ||
}; | ||
exports.shallowClone = function (values) { | ||
var nativeClone; | ||
if (Array.isArray(values)) { | ||
return values.slice(0); | ||
else if (typeof values === 'object') { | ||
return new values.constructor(values); | ||
} | ||
else if (isNativeObject(values)) { | ||
nativeClone = isNativeObject(values); | ||
return types_1.isFn(nativeClone) ? nativeClone(values) : values; | ||
} | ||
else if (typeof values === 'object' && !!values) { | ||
return __assign({}, values); | ||
} | ||
return values; | ||
}; | ||
exports.clone = function (values, filter) { | ||
var nativeClone; | ||
exports.shallowClone = shallowClone; | ||
var clone = function (values) { | ||
if (Array.isArray(values)) { | ||
return values.map(function (item) { return exports.clone(item, filter); }); | ||
var res_1 = []; | ||
values.forEach(function (item) { | ||
res_1.push(exports.clone(item)); | ||
}); | ||
return res_1; | ||
} | ||
else if (isNativeObject(values)) { | ||
nativeClone = isNativeObject(values); | ||
return types_1.isFn(nativeClone) ? nativeClone(values) : values; | ||
} | ||
else if (typeof values === 'object' && !!values) { | ||
else if (types_1.isPlainObj(values)) { | ||
if ('$$typeof' in values && '_owner' in values) { | ||
return values; | ||
} | ||
if (values._isAMomentObject) { | ||
if (values['_isAMomentObject']) { | ||
return values; | ||
} | ||
if (values._isJSONSchemaObject) { | ||
if (values['_isJSONSchemaObject']) { | ||
return values; | ||
} | ||
if (big_data_1.BigData.isBigData(values)) { | ||
return big_data_1.BigData.clone(values); | ||
if (types_1.isFn(values['toJS'])) { | ||
return values['toJS'](); | ||
} | ||
if (types_1.isFn(values.toJS)) { | ||
return values; | ||
if (types_1.isFn(values['toJSON'])) { | ||
return values['toJSON'](); | ||
} | ||
if (types_1.isFn(values.toJSON)) { | ||
return values; | ||
} | ||
if (Object.getOwnPropertySymbols(values || {}).length) { | ||
return values; | ||
} | ||
var res = {}; | ||
for (var key in values) { | ||
if (Object.hasOwnProperty.call(values, key)) { | ||
if (types_1.isFn(filter)) { | ||
if (filter(values[key], key)) { | ||
res[key] = exports.clone(values[key], filter); | ||
} | ||
else { | ||
res[key] = values[key]; | ||
} | ||
} | ||
else { | ||
res[key] = exports.clone(values[key], filter); | ||
} | ||
res[key] = exports.clone(values[key]); | ||
} | ||
@@ -116,1 +81,2 @@ } | ||
}; | ||
exports.clone = clone; |
@@ -1,6 +0,1 @@ | ||
declare type Filter = (comparies: { | ||
a: any; | ||
b: any; | ||
}, key: string) => boolean; | ||
export declare const isEqual: (a: any, b: any, filter?: Filter) => any; | ||
export {}; | ||
export declare const isEqual: (a: any, b: any) => any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEqual = void 0; | ||
var types_1 = require("./types"); | ||
var instanceof_1 = require("./instanceof"); | ||
var big_data_1 = require("./big-data"); | ||
var isArray = types_1.isArr; | ||
var keyList = Object.keys; | ||
var hasProp = Object.prototype.hasOwnProperty; | ||
function equal(a, b, filter) { | ||
function equal(a, b) { | ||
if (a === b) { | ||
@@ -14,10 +14,2 @@ return true; | ||
if (a && b && typeof a === 'object' && typeof b === 'object') { | ||
var bigDataA = big_data_1.BigData.isBigData(a); | ||
var bigDataB = big_data_1.BigData.isBigData(b); | ||
if (bigDataA !== bigDataB) { | ||
return false; | ||
} | ||
if (bigDataA && bigDataB) { | ||
return big_data_1.BigData.compare(a, b); | ||
} | ||
var arrA = isArray(a); | ||
@@ -34,3 +26,3 @@ var arrB = isArray(b); | ||
for (i = length_1; i-- !== 0;) { | ||
if (!equal(a[i], b[i], filter)) { | ||
if (!equal(a[i], b[i])) { | ||
return false; | ||
@@ -64,8 +56,2 @@ } | ||
} | ||
var schemaA = a && a.toJSON; | ||
var schemaB = b && b.toJSON; | ||
if (schemaA !== schemaB) | ||
return false; | ||
if (schemaA && schemaB) | ||
return equal(a.toJSON(), b.toJSON(), filter); | ||
var regexpA = instanceof_1.instOf(a, 'RegExp'); | ||
@@ -81,5 +67,14 @@ var regexpB = instanceof_1.instOf(b, 'RegExp'); | ||
var urlB = instanceof_1.instOf(b, 'URL'); | ||
if (urlA !== urlB) { | ||
return false; | ||
} | ||
if (urlA && urlB) { | ||
return a.href === b.href; | ||
} | ||
var schemaA = a && a.toJSON; | ||
var schemaB = b && b.toJSON; | ||
if (schemaA !== schemaB) | ||
return false; | ||
if (schemaA && schemaB) | ||
return equal(a.toJSON(), b.toJSON()); | ||
var keys = keyList(a); | ||
@@ -101,14 +96,5 @@ length_1 = keys.length; | ||
else { | ||
if (types_1.isFn(filter)) { | ||
if (filter({ a: a[key], b: b[key] }, key)) { | ||
if (!equal(a[key], b[key], filter)) { | ||
return false; | ||
} | ||
} | ||
if (!equal(a[key], b[key])) { | ||
return false; | ||
} | ||
else { | ||
if (!equal(a[key], b[key], filter)) { | ||
return false; | ||
} | ||
} | ||
} | ||
@@ -118,10 +104,7 @@ } | ||
} | ||
if (a && b && typeof a === 'function' && typeof b === 'function') { | ||
return a.toString() === b.toString(); | ||
} | ||
return a !== a && b !== b; | ||
} | ||
exports.isEqual = function exportedEqual(a, b, filter) { | ||
var isEqual = function exportedEqual(a, b) { | ||
try { | ||
return equal(a, b, filter); | ||
return equal(a, b); | ||
} | ||
@@ -137,1 +120,2 @@ catch (error) { | ||
}; | ||
exports.isEqual = isEqual; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaults = void 0; | ||
var array_1 = require("./array"); | ||
var isEmpty_1 = require("./isEmpty"); | ||
var types_1 = require("./types"); | ||
var big_data_1 = require("./big-data"); | ||
var isUnNormalObject = function (value) { | ||
if ((value === null || value === void 0 ? void 0 : value._owner) || (value === null || value === void 0 ? void 0 : value.$$typeof)) { | ||
if ((value === null || value === void 0 ? void 0 : value._owner) && (value === null || value === void 0 ? void 0 : value.$$typeof)) { | ||
return true; | ||
@@ -18,19 +18,16 @@ } | ||
}; | ||
var isPlainValue = function (val) { | ||
var isEnumableObject = function (val) { | ||
if (isUnNormalObject(val)) { | ||
return false; | ||
} | ||
if (big_data_1.BigData.isBigData(val)) { | ||
return false; | ||
} | ||
return types_1.isPlainObj(val) || types_1.isArr(val); | ||
return typeof val === 'object'; | ||
}; | ||
exports.defaults = function (defaults_, targets) { | ||
var defaults = function (defaults_, targets) { | ||
if (types_1.getType(defaults_) !== types_1.getType(targets) || | ||
!isPlainValue(defaults_) || | ||
!isPlainValue(targets)) { | ||
return isEmpty_1.isValid(targets) ? targets : defaults_; | ||
!isEnumableObject(defaults_) || | ||
!isEnumableObject(targets)) { | ||
return !isEmpty_1.isEmpty(targets) ? targets : defaults_; | ||
} | ||
else { | ||
var results_1 = types_1.isPlainObj(defaults_) ? {} : []; | ||
var results_1 = types_1.isArr(defaults_) ? [] : {}; | ||
array_1.each(targets, function (value, key) { | ||
@@ -47,1 +44,2 @@ results_1[key] = exports.defaults(defaults_[key], value); | ||
}; | ||
exports.defaults = defaults; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deprecate = void 0; | ||
var types_1 = require("./types"); | ||
@@ -4,0 +5,0 @@ var caches = {}; |
@@ -1,1 +0,1 @@ | ||
export declare const globalThisPolyfill: any; | ||
export declare const globalThisPolyfill: Window; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.globalThisPolyfill = void 0; | ||
function globalSelf() { | ||
@@ -4,0 +5,0 @@ try { |
@@ -14,6 +14,4 @@ export * from './array'; | ||
export * from './instanceof'; | ||
export * from './scheduler'; | ||
export * from './defaults'; | ||
export * from './log'; | ||
export * from './big-data'; | ||
export * from './uid'; |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./array")); | ||
__export(require("./compare")); | ||
__export(require("./types")); | ||
__export(require("./clone")); | ||
__export(require("./isEmpty")); | ||
__export(require("./case")); | ||
__export(require("./string")); | ||
__export(require("./global")); | ||
__export(require("./path")); | ||
__export(require("./deprecate")); | ||
__export(require("./subscribable")); | ||
__export(require("./merge")); | ||
__export(require("./instanceof")); | ||
__export(require("./scheduler")); | ||
__export(require("./defaults")); | ||
__export(require("./log")); | ||
__export(require("./big-data")); | ||
__export(require("./uid")); | ||
__exportStar(require("./array"), exports); | ||
__exportStar(require("./compare"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./clone"), exports); | ||
__exportStar(require("./isEmpty"), exports); | ||
__exportStar(require("./case"), exports); | ||
__exportStar(require("./string"), exports); | ||
__exportStar(require("./global"), exports); | ||
__exportStar(require("./path"), exports); | ||
__exportStar(require("./deprecate"), exports); | ||
__exportStar(require("./subscribable"), exports); | ||
__exportStar(require("./merge"), exports); | ||
__exportStar(require("./instanceof"), exports); | ||
__exportStar(require("./defaults"), exports); | ||
__exportStar(require("./log"), exports); | ||
__exportStar(require("./uid"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.instOf = void 0; | ||
var global_1 = require("./global"); | ||
var types_1 = require("./types"); | ||
exports.instOf = function (value, cls) { | ||
var instOf = function (value, cls) { | ||
if (types_1.isFn(cls)) | ||
@@ -14,1 +15,2 @@ return value instanceof cls; | ||
}; | ||
exports.instOf = instOf; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isEmpty = exports.isValid = void 0; | ||
var instanceof_1 = require("./instanceof"); | ||
var has = Object.prototype.hasOwnProperty; | ||
var toString = Object.prototype.toString; | ||
exports.isValid = function (val) { return val !== undefined && val !== null; }; | ||
var isValid = function (val) { return val !== undefined && val !== null; }; | ||
exports.isValid = isValid; | ||
function isEmpty(val) { | ||
@@ -8,0 +10,0 @@ if (val == null) { |
@@ -1,28 +0,1 @@ | ||
declare enum CONSOLE_METHODS { | ||
DEBUG = "debug", | ||
ERROR = "error", | ||
INFO = "info", | ||
LOG = "log", | ||
WARN = "warn", | ||
DIR = "dir", | ||
DIRXML = "dirxml", | ||
TABLE = "table", | ||
TRACE = "trace", | ||
GROUP = "group", | ||
GROUPCOLLAPSED = "groupCollapsed", | ||
GROUPEND = "groupEnd", | ||
CLEAR = "clear", | ||
COUNT = "count", | ||
COUNTRESET = "countReset", | ||
ASSERT = "assert", | ||
PROFILE = "profile", | ||
PROFILEEND = "profileEnd", | ||
TIME = "time", | ||
TIMELOG = "timeLog", | ||
TIMEEND = "timeEnd", | ||
TIMESTAMP = "timeStamp", | ||
CONTEXT = "context", | ||
MEMORY = "memory", | ||
TIPS = "tips" | ||
} | ||
declare type ILogData<C, T> = { | ||
@@ -35,8 +8,3 @@ content: C; | ||
private keyword; | ||
private defaultMethods; | ||
private disabled; | ||
private methods; | ||
constructor(keyword: string, methods: CONSOLE_METHODS[]); | ||
private initConsole; | ||
private wrap; | ||
constructor(keyword: string); | ||
private getKeyWordStyle; | ||
@@ -48,6 +16,4 @@ private callConsole; | ||
info<C, T>(content: C): ILogData<C, T>; | ||
close(): void; | ||
open(): void; | ||
} | ||
export declare const log: Log; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var TYPE_STRING; | ||
(function (TYPE_STRING) { | ||
TYPE_STRING["UNDEFINED"] = "undefined"; | ||
})(TYPE_STRING || (TYPE_STRING = {})); | ||
exports.log = void 0; | ||
var CONSOLE_METHODS; | ||
@@ -36,31 +33,6 @@ (function (CONSOLE_METHODS) { | ||
var Log = (function () { | ||
function Log(keyword, methods) { | ||
function Log(keyword) { | ||
this.keyword = 'APP'; | ||
this.defaultMethods = [ | ||
CONSOLE_METHODS.LOG, | ||
CONSOLE_METHODS.ERROR, | ||
CONSOLE_METHODS.WARN | ||
]; | ||
this.disabled = true; | ||
this.methods = []; | ||
this.keyword = keyword; | ||
this.methods = methods; | ||
this.initConsole(); | ||
} | ||
Log.prototype.initConsole = function () { | ||
var _this = this; | ||
var hasConsole = typeof console === TYPE_STRING.UNDEFINED; | ||
this.disabled = hasConsole; | ||
this.methods.forEach(function (name) { | ||
if (_this.defaultMethods.indexOf(name) > -1) | ||
return; | ||
_this[name] = _this.wrap(name); | ||
}); | ||
}; | ||
Log.prototype.wrap = function (name) { | ||
var _this = this; | ||
return function (content) { | ||
_this.callConsole(name, content); | ||
}; | ||
}; | ||
Log.prototype.getKeyWordStyle = function (name) { | ||
@@ -71,9 +43,2 @@ return "[ " + this.keyword + " " + name + " ]: "; | ||
var logData = { content: content, keyword: this.keyword }; | ||
if (this.disabled) { | ||
logData.content = void 0; | ||
if (tips) { | ||
logData.tips = void 0; | ||
} | ||
return logData; | ||
} | ||
var Console = console; | ||
@@ -100,10 +65,4 @@ var keyword = this.getKeyWordStyle(name); | ||
}; | ||
Log.prototype.close = function () { | ||
this.disabled = true; | ||
}; | ||
Log.prototype.open = function () { | ||
this.initConsole(); | ||
}; | ||
return Log; | ||
}()); | ||
exports.log = new Log('Formily', []); | ||
exports.log = new Log('Formily'); |
@@ -9,12 +9,4 @@ interface Options { | ||
declare function deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: Options): T; | ||
declare namespace deepmerge { | ||
var all: typeof deepmergeAll; | ||
} | ||
declare function deepmerge<T1, T2>(x: Partial<T1>, y: Partial<T2>, options?: Options): T1 & T2; | ||
declare namespace deepmerge { | ||
var all: typeof deepmergeAll; | ||
} | ||
declare function deepmergeAll(objects: object[], options?: Options): object; | ||
declare function deepmergeAll<T>(objects: Partial<T>[], options?: Options): T; | ||
export declare const merge: typeof deepmerge; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var big_data_1 = require("./big-data"); | ||
exports.merge = void 0; | ||
var isEmpty_1 = require("./isEmpty"); | ||
function defaultIsMergeableObject(value) { | ||
@@ -26,8 +27,3 @@ return isNonNullObject(value) && !isSpecial(value); | ||
if (options.clone !== false && options.isMergeableObject(value)) { | ||
if (big_data_1.BigData.isBigData(value)) { | ||
return big_data_1.BigData.clone(value); | ||
} | ||
else { | ||
return deepmerge(emptyTarget(value), value, options); | ||
} | ||
return deepmerge(emptyTarget(value), value, options); | ||
} | ||
@@ -56,2 +52,4 @@ return value; | ||
function getKeys(target) { | ||
if (!isEmpty_1.isValid(target)) | ||
return []; | ||
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)); | ||
@@ -73,4 +71,6 @@ } | ||
function mergeObject(target, source, options) { | ||
var destination = options.assign ? target : {}; | ||
if (!options.assign && options.isMergeableObject(target)) { | ||
var destination = options.assign ? target || {} : {}; | ||
if (!options.isMergeableObject(target)) | ||
return target; | ||
if (!options.assign) { | ||
getKeys(target).forEach(function (key) { | ||
@@ -84,2 +84,5 @@ destination[key] = cloneUnlessOtherwiseSpecified(target[key], options); | ||
} | ||
if (!target[key]) { | ||
destination[key] = source[key]; | ||
} | ||
if (propertyIsOnObject(target, key) && | ||
@@ -114,11 +117,2 @@ options.isMergeableObject(source[key])) { | ||
} | ||
function deepmergeAll(array, options) { | ||
if (!Array.isArray(array)) { | ||
throw new Error('first argument should be an array'); | ||
} | ||
return array.reduce(function (prev, next) { | ||
return deepmerge(prev, next, options); | ||
}, {}); | ||
} | ||
deepmerge.all = deepmergeAll; | ||
exports.merge = deepmerge; |
@@ -1,2 +0,2 @@ | ||
import FormPath, { Pattern as FormPathPattern } from 'cool-path'; | ||
import { Path as FormPath, Pattern as FormPathPattern } from '@formily/path'; | ||
export { FormPath, FormPathPattern }; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var cool_path_1 = __importDefault(require("cool-path")); | ||
exports.FormPath = cool_path_1.default; | ||
exports.FormPath = void 0; | ||
var path_1 = require("@formily/path"); | ||
Object.defineProperty(exports, "FormPath", { enumerable: true, get: function () { return path_1.Path; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.stringLength = void 0; | ||
var ansiRegex = function () { | ||
@@ -17,4 +18,5 @@ var pattern = [ | ||
}; | ||
exports.stringLength = function (input) { | ||
var stringLength = function (input) { | ||
return stripAnsi(input).replace(astralRegex(), ' ').length; | ||
}; | ||
exports.stringLength = stringLength; |
@@ -9,4 +9,4 @@ import { Subscriber, Subscription } from './types'; | ||
subscribe: (callback?: Subscriber<Payload>) => number; | ||
unsubscribe: (index: number) => void; | ||
unsubscribe: (index?: number) => void; | ||
notify: (payload?: Payload, silent?: boolean) => void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Subscribable = void 0; | ||
var types_1 = require("./types"); | ||
@@ -23,2 +24,7 @@ var array_1 = require("./array"); | ||
} | ||
else if (!index) { | ||
_this.subscribers = { | ||
index: 0 | ||
}; | ||
} | ||
}; | ||
@@ -25,0 +31,0 @@ this.notify = function (payload, silent) { |
@@ -0,1 +1,2 @@ | ||
/// <reference types="react" /> | ||
export declare const getType: (obj: any) => any; | ||
@@ -8,4 +9,11 @@ export declare const isFn: (obj: unknown) => obj is (...args: any[]) => any; | ||
export declare const isNum: (obj: unknown) => obj is number; | ||
export declare const isMap: (obj: unknown) => obj is unknown; | ||
export declare const isSet: (obj: unknown) => obj is unknown; | ||
export declare const isWeakMap: (obj: unknown) => obj is unknown; | ||
export declare const isWeakSet: (obj: unknown) => obj is unknown; | ||
export declare const isNumberLike: (index: any) => index is number; | ||
export declare const isObj: (val: unknown) => val is object; | ||
export declare const isRegExp: (obj: unknown) => obj is RegExp; | ||
export declare const isReactElement: (obj: any) => obj is import("react").ReactElement<any, string | ((props: any) => import("react").ReactElement<any, any>) | (new (props: any) => import("react").Component<any, any, any>)>; | ||
export declare const isHTMLElement: (target: any) => target is EventTarget; | ||
export declare type Subscriber<S> = (payload: S) => void; | ||
@@ -12,0 +20,0 @@ export interface Subscription<S> { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isHTMLElement = exports.isReactElement = exports.isRegExp = exports.isObj = exports.isNumberLike = exports.isWeakSet = exports.isWeakMap = exports.isSet = exports.isMap = exports.isNum = exports.isBool = exports.isStr = exports.isPlainObj = exports.isArr = exports.isFn = exports.getType = void 0; | ||
var isType = function (type) { return function (obj) { | ||
@@ -7,7 +8,8 @@ return obj != null && | ||
}; }; | ||
exports.getType = function (obj) { return Object.prototype.toString.call(obj); }; | ||
var getType = function (obj) { return Object.prototype.toString.call(obj); }; | ||
exports.getType = getType; | ||
exports.isFn = isType([ | ||
'Function', | ||
'AsyncFunction', | ||
'GeneratorFunction' | ||
'GeneratorFunction', | ||
]); | ||
@@ -19,3 +21,20 @@ exports.isArr = Array.isArray; | ||
exports.isNum = isType('Number'); | ||
exports.isObj = function (val) { return typeof val === 'object'; }; | ||
exports.isMap = isType('Map'); | ||
exports.isSet = isType('Set'); | ||
exports.isWeakMap = isType('WeakMap'); | ||
exports.isWeakSet = isType('WeakSet'); | ||
var isNumberLike = function (index) { | ||
return exports.isNum(index) || /^\d+$/.test(index); | ||
}; | ||
exports.isNumberLike = isNumberLike; | ||
var isObj = function (val) { return typeof val === 'object'; }; | ||
exports.isObj = isObj; | ||
exports.isRegExp = isType('RegExp'); | ||
var isReactElement = function (obj) { | ||
return obj && obj['$$typeof'] && obj['_owner']; | ||
}; | ||
exports.isReactElement = isReactElement; | ||
var isHTMLElement = function (target) { | ||
return Object.prototype.toString.call(target).indexOf('HTML') > -1; | ||
}; | ||
exports.isHTMLElement = isHTMLElement; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uid = void 0; | ||
var IDX = 36, HEX = ''; | ||
@@ -4,0 +5,0 @@ while (IDX--) |
{ | ||
"name": "@formily/shared", | ||
"version": "2.0.0-beta.2", | ||
"license": "MIT", | ||
"main": "lib", | ||
"types": "lib/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/alibaba/formily.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/alibaba/formily/issues" | ||
}, | ||
"homepage": "https://github.com/alibaba/formily#readme", | ||
"engines": { | ||
"npm": ">=3.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "35adb9aa7a1e14519acbd13ec720a05a3744538a", | ||
"scripts": { | ||
"build": "tsc --declaration" | ||
}, | ||
"devDependencies": { | ||
"typescript": "~3.8.0" | ||
}, | ||
"dependencies": { | ||
"camel-case": "~3.0.0", | ||
"cool-path": "^0.1.23", | ||
"lower-case": "~1.1.4", | ||
"scheduler": "~0.19.0", | ||
"upper-case": "~1.1.3" | ||
} | ||
"name": "@formily/shared", | ||
"version": "2.0.0-beta.3", | ||
"license": "MIT", | ||
"main": "lib", | ||
"module": "esm", | ||
"umd:main": "dist/formily.shared.umd.production.js", | ||
"unpkg": "dist/formily.shared.umd.production.js", | ||
"jsdelivr": "dist/formily.shared.umd.production.js", | ||
"jsnext:main": "esm", | ||
"types": "esm/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/alibaba/formily.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/alibaba/formily/issues" | ||
}, | ||
"homepage": "https://github.com/alibaba/formily#readme", | ||
"engines": { | ||
"npm": ">=3.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "2c44ae410a73f02735c63c6430e021a50e21f3ec", | ||
"scripts": { | ||
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm && npm run build:umd", | ||
"build:cjs": "tsc --declaration", | ||
"build:esm": "tsc --declaration --module es2015 --outDir esm", | ||
"build:umd": "rollup --config" | ||
}, | ||
"peerDependencies": { | ||
"@types/react": ">=16.8.0 || >=17.0.0" | ||
}, | ||
"dependencies": { | ||
"@formily/path": "^2.0.0-beta.3", | ||
"camel-case": "^4.1.1", | ||
"lower-case": "^2.0.1", | ||
"no-case": "^3.0.4", | ||
"param-case": "^3.0.4", | ||
"pascal-case": "^3.1.1", | ||
"upper-case": "^2.0.1" | ||
} | ||
} |
@@ -45,3 +45,3 @@ import { isArr, isObj, isStr } from './types' | ||
): void | ||
export function each<T extends {}, TValue>( | ||
export function each<T extends {}, TValue extends T[keyof T]>( | ||
val: T, | ||
@@ -82,3 +82,3 @@ iterator: EachObjectIterator<TValue>, | ||
revert?: boolean | ||
): any | ||
): T[] | ||
export function map<TItem, TResult>( | ||
@@ -88,3 +88,3 @@ val: TItem[], | ||
revert?: boolean | ||
): any | ||
): TResult[] | ||
export function map<T extends {}, TResult>( | ||
@@ -94,4 +94,4 @@ val: T, | ||
revert?: boolean | ||
): any | ||
export function map(val: any, iterator: any, revert?: boolean): any { | ||
): Record<keyof T, TResult> | ||
export function map(val: any, iterator: any, revert?: any): any { | ||
const res = isArr(val) || isStr(val) ? [] : {} | ||
@@ -125,3 +125,3 @@ each( | ||
): T | ||
export function reduce<T extends {}, TValue, TResult = any>( | ||
export function reduce<T extends {}, TValue extends T[keyof T], TResult = any>( | ||
val: T, | ||
@@ -159,3 +159,3 @@ iterator: MemoObjectIterator<TValue, TResult>, | ||
): boolean | ||
export function every<T extends {}, TValue>( | ||
export function every<T extends {}, TValue extends T[keyof T]>( | ||
val: T, | ||
@@ -190,3 +190,3 @@ iterator: EachObjectIterator, | ||
): boolean | ||
export function some<T extends {}, TValue>( | ||
export function some<T extends {}, TValue extends T[keyof T]>( | ||
val: T, | ||
@@ -221,3 +221,3 @@ iterator: EachObjectIterator, | ||
): number | ||
export function findIndex<T extends {}, TValue>( | ||
export function findIndex<T extends {}, TValue extends T[keyof T]>( | ||
val: T, | ||
@@ -256,3 +256,3 @@ iterator: EachObjectIterator, | ||
): T | ||
export function find<T extends {}, TValue>( | ||
export function find<T extends {}, TValue extends T[keyof T]>( | ||
val: T, | ||
@@ -259,0 +259,0 @@ iterator: EachObjectIterator, |
@@ -1,4 +0,7 @@ | ||
import camelCase from 'camel-case' | ||
import lowercase from 'lower-case' | ||
import uppercase from 'upper-case' | ||
export { camelCase, lowercase, uppercase } | ||
import { camelCase } from 'camel-case' | ||
import { pascalCase } from 'pascal-case' | ||
import { lowerCase } from 'lower-case' | ||
import { upperCase } from 'upper-case' | ||
import { paramCase } from 'param-case' | ||
export { lowerCase, upperCase, camelCase, pascalCase, paramCase } |
105
src/clone.ts
@@ -1,93 +0,58 @@ | ||
import { isFn } from './types' | ||
import { instOf } from './instanceof' | ||
import { BigData } from './big-data' | ||
type Filter = (value: any, key: string) => boolean | ||
import { isFn, isPlainObj } from './types' | ||
const NATIVE_KEYS = [ | ||
['Map', (map: any) => new Map(map)], | ||
['WeakMap', (map: any) => new WeakMap(map)], | ||
['WeakSet', (set: any) => new WeakSet(set)], | ||
['Set', (set: any) => new Set(set)], | ||
['Date', (date: any) => new Date(date)], | ||
'FileList', | ||
'File', | ||
'URL', | ||
'RegExp', | ||
[ | ||
'Promise', | ||
(promise: Promise<any>) => | ||
new Promise((resolve, reject) => promise.then(resolve, reject)) | ||
] | ||
] | ||
const isNativeObject = (values: any): any => { | ||
for (let i = 0; i < NATIVE_KEYS.length; i++) { | ||
const item = NATIVE_KEYS[i] | ||
if (Array.isArray(item) && item[0]) { | ||
if (instOf(values, item[0])) { | ||
return item[1] ? item[1] : item[0] | ||
} | ||
} else { | ||
if (instOf(values, item)) { | ||
return item | ||
} | ||
} | ||
} | ||
} | ||
export const shallowClone = (values: any) => { | ||
let nativeClone: (values: any) => any | ||
if (Array.isArray(values)) { | ||
return values.slice(0) | ||
} else if (isNativeObject(values)) { | ||
nativeClone = isNativeObject(values) | ||
return isFn(nativeClone) ? nativeClone(values) : values | ||
} else if (typeof values === 'object' && !!values) { | ||
} else if (isPlainObj(values)) { | ||
if ('$$typeof' in values && '_owner' in values) { | ||
return values | ||
} | ||
if (values['_isAMomentObject']) { | ||
return values | ||
} | ||
if (values['_isJSONSchemaObject']) { | ||
return values | ||
} | ||
if (isFn(values['toJS'])) { | ||
return values | ||
} | ||
if (isFn(values['toJSON'])) { | ||
return values | ||
} | ||
return { | ||
...values | ||
...values, | ||
} | ||
} else if (typeof values === 'object') { | ||
return new values.constructor(values) | ||
} | ||
return values | ||
} | ||
export const clone = (values: any, filter?: Filter) => { | ||
let nativeClone: (values: any) => any | ||
export const clone = (values: any) => { | ||
if (Array.isArray(values)) { | ||
return values.map(item => clone(item, filter)) | ||
} else if (isNativeObject(values)) { | ||
nativeClone = isNativeObject(values) | ||
return isFn(nativeClone) ? nativeClone(values) : values | ||
} else if (typeof values === 'object' && !!values) { | ||
const res = [] | ||
values.forEach((item) => { | ||
res.push(clone(item)) | ||
}) | ||
return res | ||
} else if (isPlainObj(values)) { | ||
if ('$$typeof' in values && '_owner' in values) { | ||
return values | ||
} | ||
if (values._isAMomentObject) { | ||
if (values['_isAMomentObject']) { | ||
return values | ||
} | ||
if (values._isJSONSchemaObject) { | ||
if (values['_isJSONSchemaObject']) { | ||
return values | ||
} | ||
if (BigData.isBigData(values)) { | ||
return BigData.clone(values) | ||
if (isFn(values['toJS'])) { | ||
return values['toJS']() | ||
} | ||
if (isFn(values.toJS)) { | ||
return values | ||
if (isFn(values['toJSON'])) { | ||
return values['toJSON']() | ||
} | ||
if (isFn(values.toJSON)) { | ||
return values | ||
} | ||
if (Object.getOwnPropertySymbols(values || {}).length) { | ||
return values | ||
} | ||
const res = {} | ||
for (const key in values) { | ||
if (Object.hasOwnProperty.call(values, key)) { | ||
if (isFn(filter)) { | ||
if (filter(values[key], key)) { | ||
res[key] = clone(values[key], filter) | ||
} else { | ||
res[key] = values[key] | ||
} | ||
} else { | ||
res[key] = clone(values[key], filter) | ||
} | ||
res[key] = clone(values[key]) | ||
} | ||
@@ -94,0 +59,0 @@ } |
@@ -1,4 +0,3 @@ | ||
import { isFn, isArr } from './types' | ||
import { isArr } from './types' | ||
import { instOf } from './instanceof' | ||
import { BigData } from './big-data' | ||
const isArray = isArr | ||
@@ -8,6 +7,4 @@ const keyList = Object.keys | ||
type Filter = (comparies: { a: any; b: any }, key: string) => boolean | ||
/* eslint-disable */ | ||
function equal(a: any, b: any, filter?: Filter) { | ||
function equal(a: any, b: any) { | ||
// fast-deep-equal index.js 2.0.1 | ||
@@ -19,12 +16,2 @@ if (a === b) { | ||
if (a && b && typeof a === 'object' && typeof b === 'object') { | ||
const bigDataA = BigData.isBigData(a) | ||
const bigDataB = BigData.isBigData(b) | ||
if (bigDataA !== bigDataB) { | ||
return false | ||
} | ||
if (bigDataA && bigDataB) { | ||
return BigData.compare(a, b) | ||
} | ||
const arrA = isArray(a) | ||
@@ -42,3 +29,3 @@ const arrB = isArray(b) | ||
for (i = length; i-- !== 0; ) { | ||
if (!equal(a[i], b[i], filter)) { | ||
if (!equal(a[i], b[i])) { | ||
return false | ||
@@ -53,3 +40,2 @@ } | ||
} | ||
const momentA = a && a._isAMomentObject | ||
@@ -71,6 +57,2 @@ const momentB = b && b._isAMomentObject | ||
} | ||
const schemaA = a && a.toJSON | ||
const schemaB = b && b.toJSON | ||
if (schemaA !== schemaB) return false | ||
if (schemaA && schemaB) return equal(a.toJSON(), b.toJSON(), filter) | ||
const regexpA = instOf(a, 'RegExp') | ||
@@ -86,2 +68,7 @@ const regexpB = instOf(b, 'RegExp') | ||
const urlB = instOf(b, 'URL') | ||
if (urlA !== urlB) { | ||
return false | ||
} | ||
if (urlA && urlB) { | ||
@@ -91,2 +78,7 @@ return a.href === b.href | ||
const schemaA = a && a.toJSON | ||
const schemaB = b && b.toJSON | ||
if (schemaA !== schemaB) return false | ||
if (schemaA && schemaB) return equal(a.toJSON(), b.toJSON()) | ||
const keys = keyList(a) | ||
@@ -117,13 +109,5 @@ length = keys.length | ||
} else { | ||
if (isFn(filter)) { | ||
if (filter({ a: a[key], b: b[key] }, key)) { | ||
if (!equal(a[key], b[key], filter)) { | ||
return false | ||
} | ||
} | ||
} else { | ||
// all other properties should be traversed as usual | ||
if (!equal(a[key], b[key], filter)) { | ||
return false | ||
} | ||
// all other properties should be traversed as usual | ||
if (!equal(a[key], b[key])) { | ||
return false | ||
} | ||
@@ -137,6 +121,2 @@ } | ||
if (a && b && typeof a === 'function' && typeof b === 'function') { | ||
return a.toString() === b.toString() | ||
} | ||
return a !== a && b !== b | ||
@@ -146,6 +126,7 @@ } | ||
export const isEqual = function exportedEqual(a: any, b: any, filter?: Filter) { | ||
export const isEqual = function exportedEqual(a: any, b: any) { | ||
try { | ||
return equal(a, b, filter) | ||
return equal(a, b) | ||
} catch (error) { | ||
/* istanbul ignore next */ | ||
if ( | ||
@@ -168,4 +149,5 @@ (error.message && error.message.match(/stack|recursion/i)) || | ||
// some other error. we should definitely know about these | ||
/* istanbul ignore next */ | ||
throw error | ||
} | ||
} |
import { each } from './array' | ||
import { isValid } from './isEmpty' | ||
import { isPlainObj, isArr, getType } from './types' | ||
import { BigData } from './big-data' | ||
import { isEmpty, isValid } from './isEmpty' | ||
import { getType, isArr } from './types' | ||
const isUnNormalObject = (value: any) => { | ||
if (value?._owner || value?.$$typeof) { | ||
if (value?._owner && value?.$$typeof) { | ||
return true | ||
@@ -17,10 +17,7 @@ } | ||
const isPlainValue = (val: any) => { | ||
const isEnumableObject = (val: any) => { | ||
if (isUnNormalObject(val)) { | ||
return false | ||
} | ||
if (BigData.isBigData(val)) { | ||
return false | ||
} | ||
return isPlainObj(val) || isArr(val) | ||
return typeof val === 'object' | ||
} | ||
@@ -36,8 +33,8 @@ | ||
getType(defaults_) !== getType(targets) || | ||
!isPlainValue(defaults_) || | ||
!isPlainValue(targets) | ||
!isEnumableObject(defaults_) || | ||
!isEnumableObject(targets) | ||
) { | ||
return isValid(targets) ? targets : defaults_ | ||
return !isEmpty(targets) ? targets : defaults_ | ||
} else { | ||
const results = isPlainObj(defaults_) ? {} : [] | ||
const results = isArr(defaults_) ? [] : {} | ||
each(targets, (value, key) => { | ||
@@ -44,0 +41,0 @@ results[key] = defaults(defaults_[key], value) |
@@ -0,1 +1,2 @@ | ||
/* istanbul ignore next */ | ||
function globalSelf() { | ||
@@ -19,2 +20,2 @@ try { | ||
} | ||
export const globalThisPolyfill = globalSelf() | ||
export const globalThisPolyfill: Window = globalSelf() |
@@ -14,6 +14,4 @@ export * from './array' | ||
export * from './instanceof' | ||
export * from './scheduler' | ||
export * from './defaults' | ||
export * from './log' | ||
export * from './big-data' | ||
export * from './uid' |
@@ -1,4 +0,1 @@ | ||
enum TYPE_STRING { | ||
UNDEFINED = 'undefined' | ||
} | ||
enum CONSOLE_METHODS { | ||
@@ -30,3 +27,3 @@ DEBUG = 'debug', | ||
// custom name | ||
TIPS = 'tips' | ||
TIPS = 'tips', | ||
} | ||
@@ -41,27 +38,6 @@ type ILogData<C, T> = { | ||
private keyword = 'APP' | ||
private defaultMethods = [ | ||
CONSOLE_METHODS.LOG, | ||
CONSOLE_METHODS.ERROR, | ||
CONSOLE_METHODS.WARN | ||
] | ||
private disabled = true | ||
private methods: CONSOLE_METHODS[] = [] | ||
constructor(keyword: string, methods: CONSOLE_METHODS[]) { | ||
constructor(keyword: string) { | ||
this.keyword = keyword | ||
this.methods = methods | ||
this.initConsole() | ||
} | ||
private initConsole(): void { | ||
const hasConsole = typeof console === TYPE_STRING.UNDEFINED | ||
this.disabled = hasConsole | ||
this.methods.forEach((name: CONSOLE_METHODS) => { | ||
if (this.defaultMethods.indexOf(name) > -1) return | ||
this[name] = this.wrap(name) | ||
}) | ||
} | ||
private wrap(name: CONSOLE_METHODS): (content: any) => void { | ||
return (content: any) => { | ||
this.callConsole<any, any>(name, content) | ||
} | ||
} | ||
private getKeyWordStyle(name: CONSOLE_METHODS): string { | ||
@@ -72,9 +48,2 @@ return `[ ${this.keyword} ${name} ]: ` | ||
const logData: ILogData<C, T> = { content, keyword: this.keyword } | ||
if (this.disabled) { | ||
logData.content = void 0 | ||
if (tips) { | ||
logData.tips = void 0 | ||
} | ||
return logData | ||
} | ||
const Console = console | ||
@@ -101,10 +70,4 @@ const keyword = this.getKeyWordStyle(name) | ||
} | ||
public close() { | ||
this.disabled = true | ||
} | ||
public open() { | ||
this.initConsole() | ||
} | ||
} | ||
export const log = new Log('Formily', []) | ||
export const log = new Log('Formily') |
@@ -1,2 +0,2 @@ | ||
import { BigData } from './big-data' | ||
import { isValid } from './isEmpty' | ||
@@ -35,7 +35,3 @@ function defaultIsMergeableObject(value: any) { | ||
if (options.clone !== false && options.isMergeableObject(value)) { | ||
if (BigData.isBigData(value)) { | ||
return BigData.clone(value) | ||
} else { | ||
return deepmerge(emptyTarget(value), value, options) | ||
} | ||
return deepmerge(emptyTarget(value), value, options) | ||
} | ||
@@ -46,3 +42,3 @@ return value | ||
function defaultArrayMerge(target: any, source: any, options: Options) { | ||
return target.concat(source).map(function(element) { | ||
return target.concat(source).map(function (element) { | ||
return cloneUnlessOtherwiseSpecified(element, options) | ||
@@ -62,3 +58,3 @@ }) | ||
return Object.getOwnPropertySymbols | ||
? Object.getOwnPropertySymbols(target).filter(function(symbol) { | ||
? Object.getOwnPropertySymbols(target).filter(function (symbol) { | ||
return target.propertyIsEnumerable(symbol) | ||
@@ -70,2 +66,3 @@ }) | ||
function getKeys(target: any) { | ||
if (!isValid(target)) return [] | ||
return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)) | ||
@@ -75,2 +72,3 @@ } | ||
function propertyIsOnObject(object: any, property: any) { | ||
/* istanbul ignore next */ | ||
try { | ||
@@ -95,13 +93,17 @@ return property in object | ||
function mergeObject(target: any, source: any, options: Options) { | ||
const destination = options.assign ? target : {} | ||
if (!options.assign && options.isMergeableObject(target)) { | ||
getKeys(target).forEach(function(key) { | ||
const destination = options.assign ? target || {} : {} | ||
if (!options.isMergeableObject(target)) return target | ||
if (!options.assign) { | ||
getKeys(target).forEach(function (key) { | ||
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options) | ||
}) | ||
} | ||
getKeys(source).forEach(function(key) { | ||
getKeys(source).forEach(function (key) { | ||
/* istanbul ignore next */ | ||
if (propertyIsUnsafe(target, key)) { | ||
return | ||
} | ||
if (!target[key]) { | ||
destination[key] = source[key] | ||
} | ||
if ( | ||
@@ -161,16 +163,3 @@ propertyIsOnObject(target, key) && | ||
} | ||
function deepmergeAll(objects: object[], options?: Options): object | ||
function deepmergeAll<T>(objects: Partial<T>[], options?: Options): T | ||
function deepmergeAll(array: any, options: any) { | ||
if (!Array.isArray(array)) { | ||
throw new Error('first argument should be an array') | ||
} | ||
return array.reduce(function(prev, next) { | ||
return deepmerge(prev, next, options) | ||
}, {}) | ||
} | ||
deepmerge.all = deepmergeAll | ||
export const merge = deepmerge |
@@ -1,3 +0,3 @@ | ||
import FormPath, { Pattern as FormPathPattern } from 'cool-path' | ||
import { Path as FormPath, Pattern as FormPathPattern } from '@formily/path' | ||
export { FormPath, FormPathPattern } |
@@ -23,5 +23,9 @@ import { isFn, Subscriber, Subscription } from './types' | ||
unsubscribe = (index: number) => { | ||
unsubscribe = (index?: number) => { | ||
if (this.subscribers[index]) { | ||
delete this.subscribers[index] | ||
} else if (!index) { | ||
this.subscribers = { | ||
index: 0 | ||
} | ||
} | ||
@@ -28,0 +32,0 @@ } |
const isType = <T>(type: string | string[]) => (obj: unknown): obj is T => | ||
obj != null && | ||
(Array.isArray(type) ? type : [type]).some( | ||
t => getType(obj) === `[object ${t}]` | ||
(t) => getType(obj) === `[object ${t}]` | ||
) | ||
@@ -10,3 +10,3 @@ export const getType = (obj: any) => Object.prototype.toString.call(obj) | ||
'AsyncFunction', | ||
'GeneratorFunction' | ||
'GeneratorFunction', | ||
]) | ||
@@ -18,4 +18,15 @@ export const isArr = Array.isArray | ||
export const isNum = isType<number>('Number') | ||
export const isMap = isType('Map') | ||
export const isSet = isType('Set') | ||
export const isWeakMap = isType('WeakMap') | ||
export const isWeakSet = isType('WeakSet') | ||
export const isNumberLike = (index: any): index is number => | ||
isNum(index) || /^\d+$/.test(index) | ||
export const isObj = (val: unknown): val is object => typeof val === 'object' | ||
export const isRegExp = isType<RegExp>('RegExp') | ||
export const isReactElement = (obj: any): obj is React.ReactElement<any> => | ||
obj && obj['$$typeof'] && obj['_owner'] | ||
export const isHTMLElement = (target: any): target is EventTarget => { | ||
return Object.prototype.toString.call(target).indexOf('HTML') > -1 | ||
} | ||
@@ -22,0 +33,0 @@ export type Subscriber<S> = (payload: S) => void |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
94711
0
89
2769
0
8
+ Added@formily/path@^2.0.0-beta.3
+ Addedno-case@^3.0.4
+ Addedparam-case@^3.0.4
+ Addedpascal-case@^3.1.1
+ Added@formily/path@2.3.2(transitive)
+ Added@types/react@19.0.10(transitive)
+ Addedcamel-case@4.1.2(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addeddot-case@3.0.4(transitive)
+ Addedlower-case@2.0.2(transitive)
+ Addedno-case@3.0.4(transitive)
+ Addedparam-case@3.0.4(transitive)
+ Addedpascal-case@3.1.2(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedupper-case@2.0.2(transitive)
- Removedcool-path@^0.1.23
- Removedscheduler@~0.19.0
- Removedcamel-case@3.0.0(transitive)
- Removedcool-path@0.1.32(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedlower-case@1.1.4(transitive)
- Removedno-case@2.3.2(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedscheduler@0.19.1(transitive)
- Removedupper-case@1.1.3(transitive)
Updatedcamel-case@^4.1.1
Updatedlower-case@^2.0.1
Updatedupper-case@^2.0.1