Skip to content

Commit

Permalink
refactor: Minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
erayhanoglu committed Nov 21, 2024
1 parent b0eeb4f commit f643130
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,26 @@ export function merge<A, B>(
const functionCache = new Map<string, Function>();

export function getMergeFunction(options?: merge.Options): Function {
const f = option =>
option == null
? 'n'
: typeof option === 'function'
? 'f'
: option
? '1'
: '0';
const cacheKey =
f(options?.deep) +
',' +
f(options?.moveArrays) +
',' +
f(options?.keepExisting) +
',' +
f(options?.copyDescriptors) +
',' +
f(options?.ignore) +
',' +
f(options?.ignoreUndefined) +
',' +
f(options?.ignoreNulls) +
',' +
f(options?.filter);
const cacheKey = [
options?.deep,
options?.moveArrays,
options?.keepExisting,
options?.copyDescriptors,
options?.ignore,
options?.ignoreUndefined,
options?.ignoreNulls,
options?.filter,
]
.map(option =>
option == null
? 'n'
: typeof option === 'function'
? 'f'
: option
? '1'
: '0',
)
.join();
let fn = functionCache.get(cacheKey);
if (!fn) {
fn = buildMerge(options);
Expand Down

0 comments on commit f643130

Please sign in to comment.