@monstermann/unplugin-auto-import-fn
Version:
A utility library for TypeScript.
541 lines (537 loc) • 8.53 kB
JavaScript
//#region src/modules.ts
const modules = {
array: [
"append",
"at",
"atOr",
"atOrElse",
"atOrThrow",
"clone",
"compact",
"concat",
"countBy",
"drop",
"dropLast",
"empty",
"every",
"filter",
"find",
"findIndex",
"findIndexOr",
"findIndexOrElse",
"findIndexOrThrow",
"findLast",
"findLastIndex",
"findLastIndexOr",
"findLastIndexOrElse",
"findLastIndexOrThrow",
"findLastOr",
"findLastOrElse",
"findLastOrThrow",
"findMap",
"findMapAll",
"findMapLast",
"findMapLastOr",
"findMapLastOrElse",
"findMapLastOrThrow",
"findMapOr",
"findMapOrElse",
"findMapOrThrow",
"findOr",
"findOrElse",
"findOrThrow",
"findRemove",
"findRemoveLast",
"findRemoveLastOr",
"findRemoveLastOrElse",
"findRemoveLastOrThrow",
"findRemoveOr",
"findRemoveOrElse",
"findRemoveOrThrow",
"findReplace",
"findReplaceLast",
"findReplaceLastOr",
"findReplaceLastOrElse",
"findReplaceLastOrThrow",
"findReplaceOr",
"findReplaceOrElse",
"findReplaceOrThrow",
"first",
"firstOr",
"firstOrElse",
"firstOrThrow",
"flatMap",
"forEach",
"groupBy",
"has",
"hasAll",
"hasAny",
"hasNone",
"indexBy",
"indexOf",
"indexOfOr",
"indexOfOrElse",
"indexOfOrThrow",
"insertAllAt",
"insertAllAtOr",
"insertAllAtOrElse",
"insertAllAtOrThrow",
"insertAt",
"insertAtOr",
"insertAtOrElse",
"insertAtOrThrow",
"isArray",
"isEmpty",
"isShallowEqual",
"join",
"last",
"lastIndexOf",
"lastIndexOfOr",
"lastIndexOfOrElse",
"lastIndexOfOrThrow",
"lastOr",
"lastOrElse",
"lastOrThrow",
"length",
"mapAt",
"mapAtOr",
"mapAtOrElse",
"mapAtOrThrow",
"mapEach",
"maxOr",
"maxOrElse",
"maxOrThrow",
"meanOr",
"meanOrElse",
"meanOrThrow",
"medianOr",
"medianOrElse",
"medianOrThrow",
"minOr",
"minOrElse",
"minOrThrow",
"none",
"partition",
"prepend",
"random",
"randomOr",
"randomOrElse",
"reduce",
"reject",
"remove",
"removeAll",
"removeAt",
"removeAtOr",
"removeAtOrElse",
"removeAtOrThrow",
"removeLast",
"removeLastOr",
"removeLastOrElse",
"removeLastOrThrow",
"removeOrElse",
"removeOrThrow",
"replace",
"replaceLast",
"replaceLastOr",
"replaceLastOrElse",
"replaceLastOrThrow",
"replaceOr",
"replaceOrElse",
"replaceOrThrow",
"setAt",
"setAtOr",
"setAtOrElse",
"setAtOrThrow",
"shuffle",
"slice",
"some",
"sort",
"sum",
"take",
"takeLast",
"union",
"unique"
],
function: [
"FnError",
"dfdlT",
"dfdl",
"flow",
"ifElse",
"invoke",
"is",
"isAsyncIterable",
"isBoolean",
"isDate",
"isError",
"isFalsy",
"isFunction",
"isImmutable",
"isIterable",
"isMutable",
"isMutating",
"isNot",
"isPrimitive",
"isRegExp",
"isSymbol",
"isTruthy",
"log",
"markAsImmutable",
"markAsMutable",
"noop",
"not",
"once",
"pauseMutations",
"pipe",
"startMutations",
"tap",
"when",
"withMutations"
],
map: [
"clone",
"compact",
"filter",
"forEach",
"get",
"getOr",
"getOrElse",
"getOrThrow",
"has",
"hasAll",
"hasAny",
"hasNone",
"isEmpty",
"isMap",
"isShallowEqual",
"map",
"mapEach",
"mapOr",
"mapOrElse",
"mapOrThrow",
"reject",
"remove",
"removeAll",
"removeOr",
"removeOrElse",
"removeOrThrow",
"set"
],
number: [
"add",
"ceil",
"clamp",
"div",
"exp",
"floor",
"gt",
"gte",
"isBigInt",
"isFinite",
"isFloat",
"isInRange",
"isInt",
"isNotFinite",
"isNumber",
"limitPrecision",
"lt",
"lte",
"max",
"min",
"mul",
"or",
"orElse",
"orThrow",
"randomInt",
"round",
"sub",
"toFixed",
"toString"
],
object: [
"assign",
"clone",
"entries",
"evolve",
"forEach",
"fromEntries",
"get",
"getOr",
"getOrElse",
"getOrThrow",
"hasKey",
"hasProp",
"is",
"isEmpty",
"isObject",
"isShallowEqual",
"keys",
"map",
"mapAssign",
"mapMerge",
"matches",
"merge",
"omit",
"pick",
"set",
"test",
"testAll",
"values"
],
option: [
"filter",
"isNone",
"isSome",
"map",
"mapOr",
"mapOrElse",
"or",
"orElse",
"orThrow"
],
promise: [
"debounce",
"defer",
"isPromise",
"limit",
"orElse",
"queue",
"sleep",
"then",
"throttle"
],
result: [
"andThen",
"err",
"errP",
"isErr",
"isOk",
"isResult",
"mapErr",
"mapOk",
"ok",
"okOr",
"okOrElse",
"okOrThrow",
"okP",
"orElse",
"tapErr",
"tapOk"
],
set: [
"add",
"addAll",
"addOr",
"addOrElse",
"addOrThrow",
"clone",
"compact",
"difference",
"forEach",
"has",
"hasAll",
"hasAny",
"hasNone",
"intersection",
"isDisjointFrom",
"isEmpty",
"isSet",
"isShallowEqual",
"isSubsetOf",
"isSupersetOf",
"mapEach",
"remove",
"removeAll",
"removeOr",
"removeOrElse",
"removeOrThrow",
"size",
"symmetricDifference",
"toArray",
"union"
],
string: [
"append",
"camelCase",
"capitalize",
"constantCase",
"drop",
"dropLast",
"endsWith",
"has",
"hasAll",
"hasAny",
"hasNone",
"indexOf",
"indexOfOr",
"indexOfOrElse",
"indexOfOrThrow",
"isEmpty",
"isString",
"kebabCase",
"lastIndexOf",
"lastIndexOfOr",
"lastIndexOfOrElse",
"lastIndexOfOrThrow",
"length",
"lowerCase",
"match",
"matchOr",
"matchOrElse",
"matchOrThrow",
"padEnd",
"padStart",
"parseFloat",
"parseFloatOr",
"parseFloatOrElse",
"parseFloatOrThrow",
"parseInt",
"parseIntOr",
"parseIntOrElse",
"parseIntOrThrow",
"pascalCase",
"prepend",
"repeat",
"replace",
"replaceAll",
"reverse",
"slice",
"snakeCase",
"split",
"startsWith",
"take",
"takeLast",
"test",
"titleCase",
"trim",
"trimEnd",
"trimStart",
"uncapitalize",
"upperCase"
],
types: [
"Err",
"Ok",
"Result",
"ErrP",
"OkP",
"ResultP",
"ErrLike",
"OkLike",
"ResultLike",
"InferOk",
"InferErr",
"SimplifyResult",
"Debounced",
"Deferred",
"Limited",
"Throttled"
]
};
//#endregion
//#region src/named.ts
function shouldInclude(name, include) {
if (!include) return true;
if (Array.isArray(include)) return include.includes(name);
if (typeof include === "function") return include(name);
return include.test(name);
}
function shouldExclude(name, exclude) {
if (!exclude) return false;
if (Array.isArray(exclude)) return exclude.includes(name);
if (typeof exclude === "function") return exclude(name);
return exclude.test(name);
}
function named(category, type = false) {
return function(options) {
const imports = [];
for (const name of modules[category]) {
if (!shouldInclude(name, options?.include)) continue;
if (shouldExclude(name, options?.exclude)) continue;
const alias = (options?.aliases)?.[name] || name;
if (alias === name) imports.push([name]);
else imports.push([name, alias]);
}
return {
from: `/fn/${category}`,
imports,
type
};
};
}
//#endregion
//#region src/wildcard.ts
function wildcard(category, defaultName) {
return function(name) {
return { [`/fn/${category}`]: [["*", name || defaultName]] };
};
}
//#endregion
//#region src/index.ts
const autoImports = {
array: {
named: named("array"),
wildcard: wildcard("array", "A")
},
function: {
named: named("function"),
wildcard: wildcard("function", "F")
},
map: {
named: named("map"),
wildcard: wildcard("map", "M")
},
number: {
named: named("number"),
wildcard: wildcard("number", "N")
},
object: {
named: named("object"),
wildcard: wildcard("object", "O")
},
option: {
named: named("option"),
wildcard: wildcard("option", "Ot")
},
promise: {
named: named("promise"),
wildcard: wildcard("promise", "P")
},
result: {
named: named("result"),
wildcard: wildcard("result", "R")
},
set: {
named: named("set"),
wildcard: wildcard("set", "St")
},
string: {
named: named("string"),
wildcard: wildcard("string", "S")
},
types: { named: named("types", true) }
};
const recommended = [
autoImports.function.named(),
autoImports.array.wildcard(),
autoImports.map.wildcard(),
autoImports.number.wildcard(),
autoImports.object.wildcard(),
autoImports.option.wildcard(),
autoImports.promise.wildcard(),
autoImports.result.wildcard(),
autoImports.result.named({ include: [
"ok",
"okP",
"err",
"errP"
] }),
autoImports.set.wildcard(),
autoImports.string.wildcard()
];
var src_default = {
...autoImports,
recommended
};
//#endregion
export { src_default as default };