template-project/node_modules/exiftool-vendored/dist/Object.js
2025-05-30 18:13:30 +08:00

58 lines
1.9 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isObject = isObject;
exports.keys = keys;
exports.isFunction = isFunction;
exports.fromEntries = fromEntries;
exports.omit = omit;
exports.keysOf = keysOf;
function isObject(obj) {
return typeof obj === "object" && obj !== null;
}
function keys(o) {
return o == null
? []
: Object.keys(o).filter((ea) => ({}).propertyIsEnumerable.call(o, ea));
}
function isFunction(obj) {
return typeof obj === "function";
}
/**
* Turns an array of `[key, value]` pairs into an object.
*
* •Pairs whose key is `null | undefined` **or** value is `undefined` are skipped.
* •If `base` is provided it is mutated and returned (handy for “extend” usecases).
*/
function fromEntries(pairs, base = {}) {
// don't use Object.create(null), json stringify will break!
if (pairs == null || pairs.length === 0)
return base ?? {};
for (const pair of pairs) {
if (pair != null && pair[0] != null && pair[1] !== undefined) {
base[pair[0]] = pair[1];
}
}
return base;
}
function omit(t, ...keysToOmit) {
const result = {};
for (const k of keys(t).filter((ea) => !keysToOmit.includes(ea))) {
result[k] = t[k];
}
return result;
}
/**
* Provides a type-safe exhaustive array of keys for a given interface.
*
* Unfortunately, `satisfies (keyof T)[]` doesn't ensure all keys are present,
* and doesn't guard against duplicates. This function does.
*
* @param t - The interface to extract keys from. This is a Record of keys to
* `true`, which ensures the returned key array is unique.
*/
function keysOf(t) {
return Object.keys(t);
}
// This also doesn't enforce that all keys are present:
// type RequiredKeys<T> = { [K in keyof Required<T>]: K } extends { [K: string]: infer U } ? U[] : never;
//# sourceMappingURL=Object.js.map