Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@uifabricshared/immutable-merge
Advanced tools
This package provides a relatively concise routine to handle merging multiple objects together with the following characteristics:
Property | Description |
---|---|
depth?: number | Depth of recursion. Positive numbers will recurse that number of times, 0 will not recurse, a negative number will recurse infinitely. Unspecified is treated as 0. |
processSingles?: boolean | If true this will run through the tree even if there is only one viable branch. This is used to allow handlers to optionally update branches of the tree. This allows the routine to be used for things like processing all style objects in a complex tree, optionally changing them based on some logic, and returning a minimally updated tree. |
`recurse?: { [key] : boolean | handler }` |
This is the signature for a handler function that can handle a named branch of the tree.
export type IMergeRecursionHandler = (
key: string,
options: IMergeOptions,
...objs: (object | undefined)[]) => object | undefined;
The array of objects or undefined values (internally treated as anything falsy) should be processed, returning a single object or undefined.
The key and options parameters are provided as conveniences in the case that a single handler needs to differentiate different branches or know how deep it is in the tree. In many cases these can be ignored.
export function immutableMergeCore(
options: IMergeOptions, ...objs: (object | undefined)[]
): object | undefined {
The routine works as described above with one notable behavior. Unlike Object.assign()
, undefined values will cause the key to be deleted. Otherwise there is no easy way to delete keys using an immutable style pattern. So merging works as follows:
const obj1 = {
foo: 'hello',
bar: 'world'
};
const obj2 = {
bar: undefined
};
const objIM = immutableMergeCore({}, obj1, obj2);
// objIM.hasOwnProperty('bar') will return false
const objAssign = Object.assign({}, obj1, obj2);
// objAssign.hasOwnProperty('bar') will return true but objAssign['bar'] will be undefined
export function immutableMerge<T extends object>(
...objs: (T | undefined)[]
): T | undefined
This convenience function wraps the common use case of recursively merging multiple objects together. Internally this calls immutableMergeCore
in a fully recursive mode.
export function processImmutable<T extends object>(
processors: IMergeOptions['recurse'], ...objs: (T | undefined)[]
): T | undefined
This convenience function runs the merge routine as a processor for one or more objects. An example use case might be to turn all style entries into a css class name if it is not already a css class name. This should have the following behavior:
The usage would be as follows. Given a processor called myStyleProcessor
:
let complexObject: IMyObjtype = getObjectFromSomewhere();
complexObject = processImmutable({ style: myStyleProcessor }, complexObject);
While the primary use case is for a single object this allows merging to happen at the same time if so desired.
FAQs
Immutable merge routines for deep customizable merging
We found that @uifabricshared/immutable-merge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.