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 2.0.0-beta.0

4

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

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

},
"gitHead": "d712d3a7d28fad2e5a95b324c3bf0c865b52e01b",
"gitHead": "edf8f5b38d7c128501d01151729a85a7ca9ef132",
"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