UNPKG

@zsnout/ithkuil

Version:

A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.

30 lines (29 loc) 924 B
/** * Merges two objects, overriding values of the first object with values from * the second. `undefined` and `null` values in the second object are ignored. * * @example * fillDefaults({ name: "Ithkuil IV", creation: 2020 }, { creation: 2023 }) * // { name: "Ithkuil IV", creation: 2023 } * * @example * fillDefaults( * { case: "THM", caseScope: "CCN" }, * { case: undefined, caseScope: "CCS" }, * ) * // { case: "THM", caseScope: "CCS" } * * @param defaultValue The default object. * @param additions The additions to be included into the object. * @returns An object containing the merged defaults and additions. */ export function fillDefaults(defaultValue, additions) { const output = { ...defaultValue }; for (const key in additions) { const value = additions[key]; if (value != null) { output[key] = value; } } return output; }