LendAndRegret/node_modules/es-toolkit/dist/compat/util/iteratee.mjs
2026-05-02 17:27:43 +08:00

29 lines
755 B
JavaScript

import { identity } from '../../function/identity.mjs';
import { property } from '../object/property.mjs';
import { matches } from '../predicate/matches.mjs';
import { matchesProperty } from '../predicate/matchesProperty.mjs';
function iteratee(value) {
if (value == null) {
return identity;
}
switch (typeof value) {
case 'function': {
return value;
}
case 'object': {
if (Array.isArray(value) && value.length === 2) {
return matchesProperty(value[0], value[1]);
}
return matches(value);
}
case 'string':
case 'symbol':
case 'number': {
return property(value);
}
}
}
export { iteratee };