Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@formily/shared

Package Overview
Dependencies
Maintainers
1
Versions
243
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formily/shared - npm Package Compare versions

Comparing version 1.1.7 to 1.2.0-beta.0

2

lib/defaults.d.ts

@@ -1,1 +0,1 @@

export declare const defaults: (...args: any[]) => any;
export declare const defaults: (defaults_: any, targets: any) => any;

@@ -5,16 +5,42 @@ "use strict";

var isEmpty_1 = require("./isEmpty");
exports.defaults = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
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)) {
return true;
}
var result = {};
array_1.each(args, function (target) {
array_1.each(target, function (value, key) {
if (isEmpty_1.isValid(value)) {
result[key] = value;
if ((value === null || value === void 0 ? void 0 : value._isAMomentObject) || (value === null || value === void 0 ? void 0 : value._isJSONSchemaObject)) {
return true;
}
if ((value === null || value === void 0 ? void 0 : value.toJS) || (value === null || value === void 0 ? void 0 : value.toJSON)) {
return true;
}
};
var isPlainValue = 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);
};
exports.defaults = function (defaults_, targets) {
if (types_1.getType(defaults_) !== types_1.getType(targets) ||
!isPlainValue(defaults_) ||
!isPlainValue(targets)) {
return isEmpty_1.isValid(targets) ? targets : defaults_;
}
else {
var results_1 = types_1.isPlainObj(defaults_) ? {} : [];
array_1.each(targets, function (value, key) {
results_1[key] = exports.defaults(defaults_[key], value);
});
array_1.each(defaults_, function (value, key) {
if (!isEmpty_1.isValid(results_1[key])) {
results_1[key] = value;
}
});
});
return result;
return results_1;
}
};

@@ -10,3 +10,3 @@ import { Subscriber, Subscription } from './types';

unsubscribe: (index: number) => void;
notify: (payload?: Payload) => void;
notify: (payload?: Payload, silent?: boolean) => void;
}

@@ -24,3 +24,3 @@ "use strict";

};
this.notify = function (payload) {
this.notify = function (payload, silent) {
if (_this.subscription) {

@@ -33,2 +33,4 @@ if (_this.subscription && types_1.isFn(_this.subscription.notify)) {

}
if (silent)
return;
var filter = function (payload) {

@@ -35,0 +37,0 @@ if (_this.subscription && types_1.isFn(_this.subscription.filter)) {

@@ -0,1 +1,2 @@

export declare const getType: (obj: any) => any;
export declare const isFn: (obj: unknown) => obj is (...args: any[]) => any;

@@ -2,0 +3,0 @@ export declare const isArr: (arg: any) => arg is any[];

@@ -5,4 +5,5 @@ "use strict";

return obj != null &&
(Array.isArray(type) ? type : [type]).some(function (t) { return Object.prototype.toString.call(obj) === "[object " + t + "]"; });
(Array.isArray(type) ? type : [type]).some(function (t) { return exports.getType(obj) === "[object " + t + "]"; });
}; };
exports.getType = function (obj) { return Object.prototype.toString.call(obj); };
exports.isFn = isType([

@@ -9,0 +10,0 @@ 'Function',

{
"name": "@formily/shared",
"version": "1.1.7",
"version": "1.2.0-beta.0",
"license": "MIT",

@@ -21,3 +21,3 @@ "main": "lib",

},
"gitHead": "d712d3a7d28fad2e5a95b324c3bf0c865b52e01b",
"gitHead": "2ce218710edcaa6e1cce2a099940c388ab5eeed0",
"scripts": {

@@ -24,0 +24,0 @@ "build": "tsc --declaration"

import { each } from './array'
import { isValid } from './isEmpty'
export const defaults = (...args: any[]): any => {
const result = {}
each(args, target => {
each(target, (value, key) => {
if (isValid(value)) {
result[key] = value
import { isPlainObj, isArr, getType } from './types'
import { BigData } from './big-data'
const isUnNormalObject = (value: any) => {
if (value?._owner || value?.$$typeof) {
return true
}
if (value?._isAMomentObject || value?._isJSONSchemaObject) {
return true
}
if (value?.toJS || value?.toJSON) {
return true
}
}
const isPlainValue = (val: any) => {
if (isUnNormalObject(val)) {
return false
}
if (BigData.isBigData(val)) {
return false
}
return isPlainObj(val) || isArr(val)
}
/**
*
* @param defaults
* @param targets
*/
export const defaults = (defaults_: any, targets: any) => {
if (
getType(defaults_) !== getType(targets) ||
!isPlainValue(defaults_) ||
!isPlainValue(targets)
) {
return isValid(targets) ? targets : defaults_
} else {
const results = isPlainObj(defaults_) ? {} : []
each(targets, (value, key) => {
results[key] = defaults(defaults_[key], value)
})
each(defaults_, (value, key) => {
if (!isValid(results[key])) {
results[key] = value
}
})
})
return result
return results
}
}

@@ -29,3 +29,3 @@ import { isFn, Subscriber, Subscription } from './types'

notify = (payload?: Payload) => {
notify = (payload?: Payload, silent?: boolean) => {
if (this.subscription) {

@@ -38,2 +38,3 @@ if (this.subscription && isFn(this.subscription.notify)) {

}
if (silent) return
const filter = (payload: Payload) => {

@@ -40,0 +41,0 @@ if (this.subscription && isFn(this.subscription.filter)) {

const isType = <T>(type: string | string[]) => (obj: unknown): obj is T =>
obj != null &&
(Array.isArray(type) ? type : [type]).some(
t => Object.prototype.toString.call(obj) === `[object ${t}]`
t => getType(obj) === `[object ${t}]`
)
export const getType = (obj: any) => Object.prototype.toString.call(obj)
export const isFn = isType<(...args: any[]) => any>([

@@ -7,0 +8,0 @@ 'Function',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc