style(format): add sorting imports plugin and fix eslint config (#625)

* Add prettier sort

* Fix prettier setting in eslint

* Apply prettier

* Fix depdencies

* Add .yarn folder in excludes of vitest

* Revert pick I don't know why this is changed
This commit is contained in:
Dayong Lee 2024-10-01 14:00:45 +09:00 committed by GitHub
parent 8f7e0960cb
commit 23aa7db57d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
200 changed files with 865 additions and 782 deletions

View File

@ -1,14 +0,0 @@
{
"arrowParens": "avoid",
"bracketSameLine": false,
"bracketSpacing": true,
"endOfLine": "lf",
"jsxSingleQuote": false,
"printWidth": 120,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}

18
.prettierrc.cjs Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: false,
bracketSpacing: true,
endOfLine: 'lf',
jsxSingleQuote: false,
printWidth: 120,
proseWrap: 'preserve',
quoteProps: 'as-needed',
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
plugins: [require.resolve('@trivago/prettier-plugin-sort-imports')],
importOrder: ['^vitest', '^es-toolkit', '<THIRD_PARTY_MODULES>', '^@(.*)$', '^[.]/', '^[.]{2,}/'],
importOrderSortSpecifiers: true,
importOrderCaseInsensitive: true,
};

View File

@ -1,47 +1,38 @@
import { DocNodeFunction } from "@deno/doc";
import { formatParam } from "./nodes/param.ts";
import { formatTypeParam } from "./nodes/type-param.ts";
import { formatType } from "./nodes/type.ts";
import { FormatOption } from "./options.ts";
import { DocNodeFunction } from '@deno/doc';
import { formatParam } from './nodes/param.ts';
import { formatTypeParam } from './nodes/type-param.ts';
import { formatType } from './nodes/type.ts';
import { FormatOption } from './options.ts';
export function formatFunctionDoc(
node: DocNodeFunction,
options: FormatOption = {},
): string {
let result = "";
export function formatFunctionDoc(node: DocNodeFunction, options: FormatOption = {}): string {
let result = '';
if (node.functionDef.isAsync) {
result += "async ";
result += 'async ';
}
result += "function";
result += 'function';
if (node.functionDef.isGenerator) {
result += "*";
result += '*';
}
result += " ";
result += ' ';
result += node.name;
if (node.functionDef.typeParams.length > 0) {
result += "<";
result += node.functionDef.typeParams.map((p) =>
formatTypeParam(p, options)
).join(
", ",
);
result += ">";
result += '<';
result += node.functionDef.typeParams.map(p => formatTypeParam(p, options)).join(', ');
result += '>';
}
result += "(";
result += node.functionDef.params.map((p) => formatParam(p, options)).join(
", ",
);
result += ")";
result += '(';
result += node.functionDef.params.map(p => formatParam(p, options)).join(', ');
result += ')';
if (node.functionDef.returnType != null) {
result += ": ";
result += ': ';
result += formatType(node.functionDef.returnType, options);
}

View File

@ -1,24 +1,21 @@
import { FormatOption } from "../options.ts";
import { FormatOption } from '../options.ts';
export function formatReadonly(
node: { readonly?: boolean | "+" | "-" },
options: FormatOption,
): string {
export function formatReadonly(node: { readonly?: boolean | '+' | '-' }, options: FormatOption): string {
if (!options.display?.readonly) {
return "";
return '';
}
switch (node.readonly) {
case true: {
return "readonly ";
return 'readonly ';
}
case "+": {
return "+readonly ";
case '+': {
return '+readonly ';
}
case "-": {
return "-readonly ";
case '-': {
return '-readonly ';
}
}
return "";
return '';
}

View File

@ -1,20 +1,17 @@
import { LiteralCallSignatureDef } from "@deno/doc";
import { formatParam } from "./param.ts";
import { formatType } from "./type.ts";
import { FormatOption } from "../options.ts";
import { LiteralCallSignatureDef } from '@deno/doc';
import { formatParam } from './param.ts';
import { formatType } from './type.ts';
import { FormatOption } from '../options.ts';
export function formatCallSignatureDef(
node: LiteralCallSignatureDef,
options: FormatOption,
) {
let result = "";
export function formatCallSignatureDef(node: LiteralCallSignatureDef, options: FormatOption) {
let result = '';
result += "(";
result += node.params.map((param) => formatParam(param, options)).join(", ");
result += ")";
result += '(';
result += node.params.map(param => formatParam(param, options)).join(', ');
result += ')';
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}

View File

@ -1,17 +1,17 @@
import { DecoratorDef } from "@deno/doc";
import { FormatOption } from "../options.ts";
import { DecoratorDef } from '@deno/doc';
import { FormatOption } from '../options.ts';
// eslint-disable-next-line
export function formatDecorator(node: DecoratorDef, _: FormatOption) {
let result = "";
let result = '';
result += "@";
result += '@';
result += node.name;
if (node.args != null && node.args.length > 0) {
result += "(";
result += node.args.join(", ");
result += ")";
result += '(';
result += node.args.join(', ');
result += ')';
}
return result;

View File

@ -1,23 +1,20 @@
import { LiteralIndexSignatureDef } from "@deno/doc";
import { formatReadonly } from "../helpers/readonly.ts";
import { formatParam } from "./param.ts";
import { formatType } from "./type.ts";
import { FormatOption } from "../options.ts";
import { LiteralIndexSignatureDef } from '@deno/doc';
import { formatParam } from './param.ts';
import { formatType } from './type.ts';
import { formatReadonly } from '../helpers/readonly.ts';
import { FormatOption } from '../options.ts';
export function formatIndexSignatureDef(
node: LiteralIndexSignatureDef,
options: FormatOption,
) {
let result = "";
export function formatIndexSignatureDef(node: LiteralIndexSignatureDef, options: FormatOption) {
let result = '';
result += formatReadonly(node, options);
result += "[";
result += node.params.map((p) => formatParam(p, options)).join(", ");
result += "]";
result += '[';
result += node.params.map(p => formatParam(p, options)).join(', ');
result += ']';
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}

View File

@ -1,10 +1,10 @@
import { LiteralMethodDef } from "@deno/doc";
import { formatParam } from "./param.ts";
import { formatType } from "./type.ts";
import { FormatOption } from "../options.ts";
import { LiteralMethodDef } from '@deno/doc';
import { formatParam } from './param.ts';
import { formatType } from './type.ts';
import { FormatOption } from '../options.ts';
export function formatMethodDef(node: LiteralMethodDef, options: FormatOption) {
let result = "";
let result = '';
if (node.computed) {
result += `[${node.name}]`;
@ -13,15 +13,15 @@ export function formatMethodDef(node: LiteralMethodDef, options: FormatOption) {
}
if (node.optional) {
result += "?";
result += '?';
}
result += "(";
result += node.params.map((x) => formatParam(x, options)).join(", ");
result += ")";
result += '(';
result += node.params.map(x => formatParam(x, options)).join(', ');
result += ')';
if (node.returnType != null) {
result += ": ";
result += ': ';
result += formatType(node.returnType, options);
}

View File

@ -1,27 +1,27 @@
import { ObjectPatPropDef } from "@deno/doc";
import { formatParam } from "./param.ts";
import { ObjectPatPropDef } from '@deno/doc';
import { formatParam } from './param.ts';
export function formatObjectPatProp(node: ObjectPatPropDef) {
switch (node.kind) {
case "keyValue": {
case 'keyValue': {
return node.key;
}
case "assign": {
let result = "";
case 'assign': {
let result = '';
result += node.key;
if (node.value != null) {
result += " = ";
result += ' = ';
result += node.value;
}
return result;
}
case "rest": {
let result = "";
case 'rest': {
let result = '';
result += "...";
result += '...';
result += formatParam(node.arg);
return result;

View File

@ -1,7 +1,7 @@
import { ParamDef } from "@deno/doc";
import { formatType } from "./type.ts";
import { formatObjectPatProp } from "./object-pat-prop.ts";
import { FormatOption } from "../options.ts";
import { ParamDef } from '@deno/doc';
import { formatObjectPatProp } from './object-pat-prop.ts';
import { formatType } from './type.ts';
import { FormatOption } from '../options.ts';
export function formatParam(node: ParamDef, options: FormatOption): string {
if (node.decorators != null) {
@ -9,89 +9,89 @@ export function formatParam(node: ParamDef, options: FormatOption): string {
}
switch (node.kind) {
case "array": {
let result = "";
case 'array': {
let result = '';
result += "[";
result += '[';
result += node.elements
.filter((x) => x != null)
.map((item) => {
.filter(x => x != null)
.map(item => {
return formatParam(item!, options);
})
.join(", ");
.join(', ');
result += "]";
result += ']';
if (node.optional) {
result += "?";
result += '?';
}
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}
return result;
}
case "assign": {
let result = "";
case 'assign': {
let result = '';
result += formatParam(node.left, options);
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}
return result;
}
case "identifier": {
let result = "";
case 'identifier': {
let result = '';
result += node.name;
if (node.optional) {
result += "?";
result += '?';
}
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}
return result;
}
case "object": {
let result = "";
case 'object': {
let result = '';
result += "{";
result += node.props.map((prop) => formatObjectPatProp(prop)).join(", ");
result += "}";
result += '{';
result += node.props.map(prop => formatObjectPatProp(prop)).join(', ');
result += '}';
if (node.optional) {
result += "?";
result += '?';
}
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}
return result;
}
case "rest": {
let result = "";
case 'rest': {
let result = '';
result += "...";
result += '...';
result += formatParam(node.arg, options);
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}

View File

@ -1,13 +1,10 @@
import { LiteralPropertyDef } from "@deno/doc";
import { formatType } from "./type.ts";
import { formatReadonly } from "../helpers/readonly.ts";
import { FormatOption } from "../options.ts";
import { LiteralPropertyDef } from '@deno/doc';
import { formatType } from './type.ts';
import { formatReadonly } from '../helpers/readonly.ts';
import { FormatOption } from '../options.ts';
export function formatPropertyDef(
node: LiteralPropertyDef,
options: FormatOption,
) {
let result = "";
export function formatPropertyDef(node: LiteralPropertyDef, options: FormatOption) {
let result = '';
result += formatReadonly(node, options);
@ -18,11 +15,11 @@ export function formatPropertyDef(
}
if (node.optional) {
result += "?";
result += '?';
}
if (node.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.tsType, options);
}

View File

@ -1,22 +1,19 @@
import { TsTypeParamDef } from "@deno/doc";
import { FormatOption } from "../options.ts";
import { formatType } from "./type.ts";
import { TsTypeParamDef } from '@deno/doc';
import { formatType } from './type.ts';
import { FormatOption } from '../options.ts';
export function formatTypeParam(
node: TsTypeParamDef,
options: FormatOption,
) {
let result = "";
export function formatTypeParam(node: TsTypeParamDef, options: FormatOption) {
let result = '';
result += node.name;
if (node.constraint != null) {
result += " extends ";
result += ' extends ';
result += formatType(node.constraint, options);
}
if (node.default != null) {
result += " = ";
result += ' = ';
result += formatType(node.default, options);
}

View File

@ -1,199 +1,190 @@
import { TsTypeDef } from "@deno/doc";
import { formatTypeParam } from "./type-param.ts";
import { formatParam } from "./param.ts";
import { formatCallSignatureDef } from "./call-signature.ts";
import { formatMethodDef } from "./method.ts";
import { formatPropertyDef } from "./property.ts";
import { formatReadonly } from "../helpers/readonly.ts";
import { formatIndexSignatureDef } from "./index-signature.ts";
import { FormatOption } from "../options.ts";
import { TsTypeDef } from '@deno/doc';
import { formatCallSignatureDef } from './call-signature.ts';
import { formatIndexSignatureDef } from './index-signature.ts';
import { formatMethodDef } from './method.ts';
import { formatParam } from './param.ts';
import { formatPropertyDef } from './property.ts';
import { formatTypeParam } from './type-param.ts';
import { formatReadonly } from '../helpers/readonly.ts';
import { FormatOption } from '../options.ts';
export function formatType(
node: TsTypeDef,
options: FormatOption,
): string {
export function formatType(node: TsTypeDef, options: FormatOption): string {
switch (node.kind) {
case "array": {
case 'array': {
switch (node.array.kind) {
case "union":
case "intersection":
case 'union':
case 'intersection':
return `Array<${formatType(node.array, options)}>`;
}
return `${formatType(node.array, options)}[]`;
}
case "conditional": {
let result = "";
case 'conditional': {
let result = '';
result += formatType(node.conditionalType.checkType, options);
result += " extends ";
result += ' extends ';
result += formatType(node.conditionalType.extendsType, options);
result += " ? ";
result += ' ? ';
result += formatType(node.conditionalType.trueType, options);
result += " : ";
result += ' : ';
result += formatType(node.conditionalType.falseType, options);
return result;
}
case "infer": {
let result = "";
case 'infer': {
let result = '';
result += "infer ";
result += 'infer ';
result += formatTypeParam(node.infer.typeParam, options);
return result;
}
case "importType": {
let result = "";
case 'importType': {
let result = '';
result += "import(";
result += 'import(';
result += node.importType.specifier;
result += ")";
result += ')';
if (node.importType.qualifier != null) {
result += ".";
result += '.';
result += node.importType.qualifier;
}
if (node.importType.typeParams != null) {
result += "<";
result += node.importType.typeParams.map((param) =>
formatType(param, options)
)
.join(", ");
result += ">";
result += '<';
result += node.importType.typeParams.map(param => formatType(param, options)).join(', ');
result += '>';
}
return result;
}
case "fnOrConstructor": {
let result = "";
case 'fnOrConstructor': {
let result = '';
if (node.fnOrConstructor.constructor) {
result += "new ";
result += 'new ';
}
result += "(";
result += node.fnOrConstructor.params.map((param) =>
formatParam(param, options)
)
.join(", ");
result += ")";
result += '(';
result += node.fnOrConstructor.params.map(param => formatParam(param, options)).join(', ');
result += ')';
result += " => ";
result += ' => ';
result += formatType(node.fnOrConstructor.tsType, options);
return result;
}
case "indexedAccess": {
let result = "";
case 'indexedAccess': {
let result = '';
result += formatType(node.indexedAccess.objType, options);
result += "[";
result += '[';
result += formatType(node.indexedAccess.indexType, options);
result += "]";
result += ']';
return result;
}
case "intersection": {
return node.intersection.map((u) => formatType(u, options)).join(" & ");
case 'intersection': {
return node.intersection.map(u => formatType(u, options)).join(' & ');
}
case "mapped": {
let result = "";
case 'mapped': {
let result = '';
result += formatReadonly(node.mappedType, options);
result += "[";
result += '[';
if (node.mappedType.typeParam.constraint != null) {
result += node.mappedType.typeParam.name;
result += " in ";
result += ' in ';
result += formatType(node.mappedType.typeParam.constraint, options);
} else {
result += formatTypeParam(node.mappedType.typeParam, options);
}
if (node.mappedType.nameType != null) {
result += " as ";
result += ' as ';
result += formatType(node.mappedType.nameType, options);
}
result += "]";
result += ']';
switch (node.mappedType.optional) {
case true: {
result += "?";
result += '?';
break;
}
case "+": {
result += "+?";
case '+': {
result += '+?';
break;
}
case "-": {
result += "-?";
case '-': {
result += '-?';
break;
}
}
if (node.mappedType.tsType != null) {
result += ": ";
result += ': ';
result += formatType(node.mappedType.tsType, options);
}
return result;
}
case "keyword": {
case 'keyword': {
return node.keyword;
}
case "literal": {
case 'literal': {
switch (node.literal.kind) {
case "boolean": {
case 'boolean': {
if (node.literal.boolean) {
return "true";
return 'true';
} else {
return "false";
return 'false';
}
}
case "string": {
case 'string': {
return node.literal.string;
}
case "template": {
let result = "";
case 'template': {
let result = '';
result += "`";
result += '`';
for (const tsType of node.literal.tsTypes) {
if (tsType.kind === "literal") {
if (tsType.literal.kind === "string") {
if (tsType.kind === 'literal') {
if (tsType.literal.kind === 'string') {
result += tsType.literal.string;
continue;
}
}
result += "${";
result += '${';
result += formatType(tsType, options);
result += "}";
result += '}';
}
result += "`";
result += '`';
return result;
}
case "number": {
case 'number': {
return node.literal.number.toString();
}
case "bigInt": {
case 'bigInt': {
return node.literal.string;
}
}
@ -201,75 +192,66 @@ export function formatType(
throw new Error(`Not reachable`);
}
case "optional": {
case 'optional': {
return `${formatType(node.optional, options)}?`;
}
case "parenthesized": {
case 'parenthesized': {
return `(${formatType(node.parenthesized, options)})`;
}
case "rest": {
case 'rest': {
return `...${formatType(node.rest, options)}`;
}
case "this": {
case 'this': {
return `this`;
}
case "tuple": {
let result = "";
case 'tuple': {
let result = '';
result += "[";
result += node.tuple.map((item) => formatType(item, options)).join(", ");
result += "]";
result += '[';
result += node.tuple.map(item => formatType(item, options)).join(', ');
result += ']';
return result;
}
case "typeLiteral": {
let result = "";
case 'typeLiteral': {
let result = '';
result += "{ ";
result += node.typeLiteral.callSignatures.map((sig) =>
formatCallSignatureDef(sig, options)
).join("; ");
result += node.typeLiteral.methods.map((m) => formatMethodDef(m, options))
.join(
"; ",
);
result += node.typeLiteral.properties.map((p) =>
formatPropertyDef(p, options)
)
.join("; ");
result += node.typeLiteral.indexSignatures.map((indexSignature) =>
formatIndexSignatureDef(indexSignature, options)
)
.join("; ");
result += '{ ';
result += node.typeLiteral.callSignatures.map(sig => formatCallSignatureDef(sig, options)).join('; ');
result += node.typeLiteral.methods.map(m => formatMethodDef(m, options)).join('; ');
result += node.typeLiteral.properties.map(p => formatPropertyDef(p, options)).join('; ');
result += node.typeLiteral.indexSignatures
.map(indexSignature => formatIndexSignatureDef(indexSignature, options))
.join('; ');
result += result += " }";
result += result += ' }';
result += "}";
result += '}';
return result;
}
case "typeOperator": {
let result = "";
case 'typeOperator': {
let result = '';
switch (node.typeOperator.operator) {
case "readonly": {
case 'readonly': {
if (!options.display?.readonly) {
break;
}
result += node.typeOperator.operator;
result += " ";
result += ' ';
break;
}
default: {
result += node.typeOperator.operator;
result += " ";
result += ' ';
break;
}
}
@ -279,32 +261,29 @@ export function formatType(
return result;
}
case "typeQuery": {
case 'typeQuery': {
return `typeof ${node.typeQuery}`;
}
case "typeRef": {
let result = "";
case 'typeRef': {
let result = '';
result += node.typeRef.typeName;
if (node.typeRef.typeParams != null) {
result += "<";
result += node.typeRef.typeParams.map((p) => formatType(p, options))
.join(
", ",
);
result += ">";
result += '<';
result += node.typeRef.typeParams.map(p => formatType(p, options)).join(', ');
result += '>';
}
return result;
}
case "union": {
return node.union.map((u) => formatType(u, options)).join(" | ");
case 'union': {
return node.union.map(u => formatType(u, options)).join(' | ');
}
case "typePredicate": {
case 'typePredicate': {
return node.repr;
}
}

View File

@ -1,25 +1,24 @@
import "@std/dotenv/load";
import { doc, DocNode } from "@deno/doc";
import { differenceWith, groupBy } from "@es-toolkit/es-toolkit";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { toDocumentationItem } from "./operations/toDocumentationItem.ts";
import { render as renderEN } from "./operations/render/en.ts";
import { render as renderKO } from "./operations/render/ko.ts";
import { render as renderZH } from "./operations/render/zh_hans.ts";
import { render as renderJA } from "./operations/render/ja.ts";
import { translate } from "./operations/translate.ts";
import { DocumentationItem } from "./types/DocumentationItem.ts";
import { Locale } from "./types/Locale.ts";
import { RenderOptions } from "./operations/render/types.ts";
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { doc, DocNode } from '@deno/doc';
import { differenceWith, groupBy } from '@es-toolkit/es-toolkit';
import '@std/dotenv/load';
import { render as renderEN } from './operations/render/en.ts';
import { render as renderJA } from './operations/render/ja.ts';
import { render as renderKO } from './operations/render/ko.ts';
import { RenderOptions } from './operations/render/types.ts';
import { render as renderZH } from './operations/render/zh_hans.ts';
import { toDocumentationItem } from './operations/toDocumentationItem.ts';
import { translate } from './operations/translate.ts';
import { DocumentationItem } from './types/DocumentationItem.ts';
import { Locale } from './types/Locale.ts';
// eslint-disable-next-line
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const basePath = path.resolve(__dirname, "..", "..", "src");
const basePath = path.resolve(__dirname, '..', '..', 'src');
const openAiApiKey = Deno.env.get("OPENAI_API_KEY")!;
const openAiApiKey = Deno.env.get('OPENAI_API_KEY')!;
if (openAiApiKey == null) {
throw new Error(`OPENAI_API_KEY is not provided.`);
@ -29,43 +28,35 @@ type DocumentationItems = Array<{ docPath: string; item: DocumentationItem }>;
type DocumentationPaths = Record<Locale, string>;
async function run() {
const docsRoot = path.resolve(__dirname, "..", "..", "docs");
const docsRoot = path.resolve(__dirname, '..', '..', 'docs');
const docsPaths: DocumentationPaths = {
en: path.join(docsRoot, "reference"),
ko: path.join(docsRoot, "ko", "reference"),
ja: path.join(docsRoot, "ja", "reference"),
zh_hans: path.join(docsRoot, "zh_hans", "reference"),
en: path.join(docsRoot, 'reference'),
ko: path.join(docsRoot, 'ko', 'reference'),
ja: path.join(docsRoot, 'ja', 'reference'),
zh_hans: path.join(docsRoot, 'zh_hans', 'reference'),
};
const items = toDocumentationItems(
await doc(`file:${path.join(basePath, "index.ts")}`),
);
const items = toDocumentationItems(await doc(`file:${path.join(basePath, 'index.ts')}`));
await renderDocs(docsPaths, items);
const compatItems = differenceWith(
toDocumentationItems(
await doc(`file:${path.join(basePath, "compat", "index.ts")}`),
),
toDocumentationItems(await doc(`file:${path.join(basePath, 'compat', 'index.ts')}`)),
items,
(x, y) => x.item.name === y.item.name,
(x, y) => x.item.name === y.item.name
);
await renderDocs(docsPaths, compatItems, { compat: true });
}
async function renderDocs(
docsPaths: DocumentationPaths,
items: DocumentationItems,
options: RenderOptions = {},
) {
async function renderDocs(docsPaths: DocumentationPaths, items: DocumentationItems, options: RenderOptions = {}) {
for (const { docPath, item } of items) {
console.log(`> Doc: ${docPath}`);
const enPath = path.join(docsPaths.en, docPath);
if (!await exists(enPath)) {
if (!(await exists(enPath))) {
console.log(`> Generating English docs for for: ${docPath}`);
await Deno.mkdir(path.dirname(enPath), { recursive: true });
await Deno.writeTextFile(enPath, renderEN(item, options));
@ -73,27 +64,27 @@ async function renderDocs(
const koPath = path.join(docsPaths.ko, docPath);
if (!await exists(koPath)) {
if (!(await exists(koPath))) {
console.log(`> Generating Korean docs for for: ${docPath}`);
const translated = await translate(item, "ko", { openAiApiKey });
const translated = await translate(item, 'ko', { openAiApiKey });
await Deno.mkdir(path.dirname(koPath), { recursive: true });
await Deno.writeTextFile(koPath, renderKO(translated, options));
}
const jaPath = path.join(docsPaths.ja, docPath);
if (!await exists(jaPath)) {
if (!(await exists(jaPath))) {
console.log(`> Generating Japanese docs for for: ${docPath}`);
const translated = await translate(item, "ja", { openAiApiKey });
const translated = await translate(item, 'ja', { openAiApiKey });
await Deno.mkdir(path.dirname(jaPath), { recursive: true });
await Deno.writeTextFile(jaPath, renderJA(translated, options));
}
const zhPath = path.join(docsPaths.zh_hans, docPath);
if (!await exists(zhPath)) {
if (!(await exists(zhPath))) {
console.log(`> Generating Simplified Chinese docs for for: ${docPath}`);
const translated = await translate(item, "zh_hans", { openAiApiKey });
const translated = await translate(item, 'zh_hans', { openAiApiKey });
await Deno.mkdir(path.dirname(zhPath), { recursive: true });
await Deno.writeTextFile(zhPath, renderZH(translated, options));
}
@ -113,15 +104,15 @@ async function exists(path: string): Promise<boolean> {
}
function toDocumentationItems(docs: DocNode[]): DocumentationItems {
const entries = Object.entries(groupBy(docs, (x) => x.name));
const entries = Object.entries(groupBy(docs, x => x.name));
return entries
.filter(([name, entries]) => {
if (name === "") {
if (name === '') {
return false;
}
if (entries.some((x) => x.kind !== "class" && x.kind !== "function")) {
if (entries.some(x => x.kind !== 'class' && x.kind !== 'function')) {
return false;
}
@ -129,10 +120,7 @@ function toDocumentationItems(docs: DocNode[]): DocumentationItems {
})
.map(([name, entries]) => {
const sourcePath = fileURLToPath(entries[0].location.filename);
const docPath: string = path.relative(basePath, sourcePath).replace(
/.ts$/g,
".md",
);
const docPath: string = path.relative(basePath, sourcePath).replace(/.ts$/g, '.md');
return {
docPath: docPath,

View File

@ -1,15 +1,10 @@
import { DocumentationItem } from "../../types/DocumentationItem.ts";
import { RenderOptions } from "./types.ts";
import { RenderOptions } from './types.ts';
import { DocumentationItem } from '../../types/DocumentationItem.ts';
export function render(item: DocumentationItem, options: RenderOptions = {}) {
return [
title(item.name),
compatNotice(options),
item.description,
signature(item),
examples(item),
]
.filter((x) => x != null).join("\n\n");
return [title(item.name), compatNotice(options), item.description, signature(item), examples(item)]
.filter(x => x != null)
.join('\n\n');
}
function title(name: string) {
@ -31,12 +26,7 @@ When imported from \`es-toolkit/compat\`, it behaves exactly like lodash and pro
}
function signature(item: DocumentationItem) {
return [
"## Signature",
symbolInterface(item),
parameters(item),
returns(item),
].filter((x) => x != null).join("\n\n");
return ['## Signature', symbolInterface(item), parameters(item), returns(item)].filter(x => x != null).join('\n\n');
}
function symbolInterface(item: DocumentationItem): string {
@ -55,10 +45,7 @@ function parameters(item: DocumentationItem) {
return `
### Parameters
${
item.parameters.map((p) => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`)
.join("\n")
}
${item.parameters.map(p => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`).join('\n')}
`.trim();
}
@ -91,7 +78,7 @@ function examples(item: DocumentationItem) {
## Examples
\`\`\`typescript
${item.exampleCodes.join("\n\n")}
${item.exampleCodes.join('\n\n')}
\`\`\`
`.trim();
}

View File

@ -1,15 +1,10 @@
import { DocumentationItem } from "../../types/DocumentationItem.ts";
import { RenderOptions } from "./types.ts";
import { RenderOptions } from './types.ts';
import { DocumentationItem } from '../../types/DocumentationItem.ts';
export function render(item: DocumentationItem, options: RenderOptions = {}) {
return [
title(item.name),
compatNotice(options),
item.description,
signature(item),
examples(item),
]
.filter((x) => x != null).join("\n\n");
return [title(item.name), compatNotice(options), item.description, signature(item), examples(item)]
.filter(x => x != null)
.join('\n\n');
}
function title(name: string) {
@ -31,14 +26,9 @@ function compatNotice(options: RenderOptions) {
}
function signature(item: DocumentationItem) {
return [
"## インターフェース",
symbolInterface(item),
parameters(item),
returns(item),
]
.filter((x) => x != null)
.join("\n\n");
return ['## インターフェース', symbolInterface(item), parameters(item), returns(item)]
.filter(x => x != null)
.join('\n\n');
}
function symbolInterface(item: DocumentationItem): string {
@ -57,10 +47,7 @@ function parameters(item: DocumentationItem) {
return `
###
${
item.parameters.map((p) => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`)
.join("\n")
}
${item.parameters.map(p => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`).join('\n')}
`.trim();
}
@ -85,7 +72,7 @@ function examples(item: DocumentationItem) {
##
\`\`\`typescript
${item.exampleCodes.join("\n\n")}
${item.exampleCodes.join('\n\n')}
\`\`\`
`.trim();
}

View File

@ -1,15 +1,10 @@
import { DocumentationItem } from "../../types/DocumentationItem.ts";
import { RenderOptions } from "./types.ts";
import { RenderOptions } from './types.ts';
import { DocumentationItem } from '../../types/DocumentationItem.ts';
export function render(item: DocumentationItem, options: RenderOptions = {}) {
return [
title(item.name),
compatNotice(options),
item.description,
signature(item),
examples(item),
]
.filter((x) => x != null).join("\n\n");
return [title(item.name), compatNotice(options), item.description, signature(item), examples(item)]
.filter(x => x != null)
.join('\n\n');
}
function title(name: string) {
@ -31,12 +26,7 @@ function compatNotice(options: RenderOptions) {
}
function signature(item: DocumentationItem) {
return [
"## 인터페이스",
symbolInterface(item),
parameters(item),
returns(item),
].filter((x) => x != null).join("\n\n");
return ['## 인터페이스', symbolInterface(item), parameters(item), returns(item)].filter(x => x != null).join('\n\n');
}
function symbolInterface(item: DocumentationItem): string {
@ -55,10 +45,7 @@ function parameters(item: DocumentationItem) {
return `
###
${
item.parameters.map((p) => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`)
.join("\n")
}
${item.parameters.map(p => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`).join('\n')}
`.trim();
}
@ -83,7 +70,7 @@ function examples(item: DocumentationItem) {
##
\`\`\`typescript
${item.exampleCodes.join("\n\n")}
${item.exampleCodes.join('\n\n')}
\`\`\`
`.trim();
}

View File

@ -1,15 +1,10 @@
import { DocumentationItem } from "../../types/DocumentationItem.ts";
import { RenderOptions } from "./types.ts";
import { RenderOptions } from './types.ts';
import { DocumentationItem } from '../../types/DocumentationItem.ts';
export function render(item: DocumentationItem, options: RenderOptions = {}) {
return [
title(item.name),
compatNotice(options),
item.description,
signature(item),
examples(item),
]
.filter((x) => x != null).join("\n\n");
return [title(item.name), compatNotice(options), item.description, signature(item), examples(item)]
.filter(x => x != null)
.join('\n\n');
}
function title(name: string) {
@ -31,8 +26,7 @@ function compatNotice(options: RenderOptions) {
}
function signature(item: DocumentationItem) {
return ["## 签名", symbolInterface(item), parameters(item), returns(item)]
.filter((x) => x != null).join("\n\n");
return ['## 签名', symbolInterface(item), parameters(item), returns(item)].filter(x => x != null).join('\n\n');
}
function symbolInterface(item: DocumentationItem): string {
@ -51,10 +45,7 @@ function parameters(item: DocumentationItem) {
return `
###
${
item.parameters.map((p) => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`)
.join("\n")
}
${item.parameters.map(p => `- \`${p.name}\` (\`${p.type}\`): ${p.document}`).join('\n')}
`.trim();
}
@ -79,7 +70,7 @@ function examples(item: DocumentationItem) {
##
\`\`\`typescript
${item.exampleCodes.join("\n\n")}
${item.exampleCodes.join('\n\n')}
\`\`\`
`.trim();
}

View File

@ -1,18 +1,9 @@
import {
DocNode,
JsDocTag,
JsDocTagDocRequired,
JsDocTagParam,
JsDocTagReturn,
} from "@deno/doc";
import { DocumentationItem } from "../types/DocumentationItem.ts";
import { formatFunctionDoc } from "../formatters/function.ts";
import { formatClassDoc } from "../formatters/class.ts";
import { DocNode, JsDocTag, JsDocTagDocRequired, JsDocTagParam, JsDocTagReturn } from '@deno/doc';
import { formatClassDoc } from '../formatters/class.ts';
import { formatFunctionDoc } from '../formatters/function.ts';
import { DocumentationItem } from '../types/DocumentationItem.ts';
export function toDocumentationItem(
symbolName: string,
docs: DocNode[],
): DocumentationItem {
export function toDocumentationItem(symbolName: string, docs: DocNode[]): DocumentationItem {
const lastDoc = docs.at(-1) ?? docs.at(0);
const tags = lastDoc?.jsDoc?.tags ?? [];
@ -20,7 +11,7 @@ export function toDocumentationItem(
if (description == null) {
throw new Error(
`No description provided for ${symbolName} (${lastDoc?.location.filename}:${lastDoc?.location.line}:${lastDoc?.location.col}).`,
`No description provided for ${symbolName} (${lastDoc?.location.filename}:${lastDoc?.location.line}:${lastDoc?.location.col}).`
);
}
@ -40,10 +31,10 @@ function toSignature(symbolName: string, docs: DocNode[]) {
}
switch (docs[0].kind) {
case "function": {
case 'function': {
return toFunctionSignature(symbolName, docs);
}
case "class": {
case 'class': {
return toClassSignature(symbolName, docs);
}
}
@ -53,45 +44,36 @@ function toSignature(symbolName: string, docs: DocNode[]) {
function toFunctionSignature(symbolName: string, docs: DocNode[]) {
return docs
.map((doc) => {
if (doc.kind !== "function") {
throw new Error(
`Unsupported document type in ${symbolName}: ${doc.kind}`,
);
.map(doc => {
if (doc.kind !== 'function') {
throw new Error(`Unsupported document type in ${symbolName}: ${doc.kind}`);
}
return `${formatFunctionDoc(doc, { display: { readonly: false } })};`;
})
.join("\n");
.join('\n');
}
function toClassSignature(symbolName: string, docs: DocNode[]) {
return docs
.map((doc) => {
if (doc.kind !== "class") {
throw new Error(
`Unsupported document type in ${symbolName}: ${doc.kind}`,
);
.map(doc => {
if (doc.kind !== 'class') {
throw new Error(`Unsupported document type in ${symbolName}: ${doc.kind}`);
}
return `${formatClassDoc(doc, { display: { readonly: false } })}`;
})
.join("\n");
.join('\n');
}
function toParameters(
symbolName: string,
tags: JsDocTag[],
): DocumentationItem["parameters"] {
const parameters = tags.filter((tag): tag is JsDocTagParam =>
tag.kind === "param"
);
function toParameters(symbolName: string, tags: JsDocTag[]): DocumentationItem['parameters'] {
const parameters = tags.filter((tag): tag is JsDocTagParam => tag.kind === 'param');
if (parameters.length === 0) {
return null;
}
return parameters.map((param) => {
return parameters.map(param => {
if (param.name == null) {
throw new Error(`parameter name is not provided in ${symbolName}.`);
}
@ -107,17 +89,13 @@ function toParameters(
return {
name: param.name,
type: param.type,
document: param.doc.replace(/^- /g, ""),
document: param.doc.replace(/^- /g, ''),
};
});
}
function toReturns(
symbolName: string,
tags: JsDocTag[],
): DocumentationItem["returns"] {
const returns =
tags.filter((x): x is JsDocTagReturn => x.kind === "return")[0];
function toReturns(symbolName: string, tags: JsDocTag[]): DocumentationItem['returns'] {
const returns = tags.filter((x): x is JsDocTagReturn => x.kind === 'return')[0];
if (returns == null) {
return null;
@ -129,18 +107,16 @@ function toReturns(
return {
type: returns.type ?? null,
document: returns.doc.replace(/^- /g, ""),
document: returns.doc.replace(/^- /g, ''),
};
}
function toExampleCodes(tags: JsDocTag[]) {
const examples = tags.filter((x): x is JsDocTagDocRequired =>
x.kind === "example"
);
const examples = tags.filter((x): x is JsDocTagDocRequired => x.kind === 'example');
if (examples.length === 0) {
return [];
}
return examples.map((x) => x.doc.trim());
return examples.map(x => x.doc.trim());
}

View File

@ -1,7 +1,7 @@
import { pick, toMerged } from "@es-toolkit/es-toolkit";
import OpenAI from "openai";
import { DocumentationItem } from "../types/DocumentationItem.ts";
import { Locale } from "../types/Locale.ts";
import OpenAI from 'openai';
import { pick, toMerged } from '@es-toolkit/es-toolkit';
import { DocumentationItem } from '../types/DocumentationItem.ts';
import { Locale } from '../types/Locale.ts';
interface TranslateOptions {
openAiApiKey: string;
@ -10,7 +10,7 @@ interface TranslateOptions {
export async function translate(
doc: DocumentationItem,
locale: Locale,
{ openAiApiKey }: TranslateOptions,
{ openAiApiKey }: TranslateOptions
): Promise<DocumentationItem> {
const client = new OpenAI({
apiKey: openAiApiKey,
@ -18,10 +18,10 @@ export async function translate(
const item = {
description: doc.description,
parameters: doc.parameters?.map((param) => {
return pick(param, ["document"]);
parameters: doc.parameters?.map(param => {
return pick(param, ['document']);
}),
returns: pick(doc.returns! ?? {}, ["document"]),
returns: pick(doc.returns! ?? {}, ['document']),
};
const prompt = `
@ -39,8 +39,8 @@ ${JSON.stringify(item, null, 2)}
`;
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: prompt }],
model: 'gpt-4o',
messages: [{ role: 'user', content: prompt }],
});
const translatedItem = response.choices[0].message.content;

View File

@ -2,13 +2,11 @@ export interface DocumentationItem {
name: string;
description: string;
signature: string;
parameters:
| Array<{
name: string;
type: string;
document: string;
}>
| null;
parameters: Array<{
name: string;
type: string;
document: string;
}> | null;
returns: {
type: string | null;
document: string;

View File

@ -1 +1 @@
export type Locale = "en" | "ko" | "ja" | "zh_hans";
export type Locale = 'en' | 'ko' | 'ja' | 'zh_hans';

View File

@ -1,8 +1,8 @@
import type { API, FileInfo } from 'jscodeshift';
import { formatBrokenSyntax } from './_internal/formatter/brokenSyntax';
import { transformAssert } from './_internal/transform/assert';
import { transformImport } from './_internal/transform/import';
import { transformLodashStable } from './_internal/transform/lodashStable';
import { transformAssert } from './_internal/transform/assert';
export default function transform(file: FileInfo, { jscodeshift }: API) {
try {

View File

@ -8,9 +8,7 @@
"prettier.prettierPath": ".yarn/sdks/prettier/index.cjs",
"typescript.tsdk": ".yarn/sdks/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"deno.enablePaths": [
"./.scripts/docs"
],
"deno.enablePaths": ["./.scripts/docs"],
"deno.config": "./.scripts/docs/deno.json",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { filter as filterToolkit } from 'es-toolkit/compat';
import { filter as filterLodash } from 'lodash';
import { bench, describe } from 'vitest';
const arr = [
{ a: 0, b: true },

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { initial as initialLodash } from 'lodash';
import { initial as initialToolkit } from 'es-toolkit';
import { initial as initialLodash } from 'lodash';
// Helper function to generate a large array
function generateLargeArray(size) {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { invert as invertByLodash } from 'lodash';
import { invert as invertByToolkit } from 'es-toolkit';
import { invert as invertByLodash } from 'lodash';
const object: { [key: string]: string } = {};
for (let i = 0; i < 10000; i++) {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { isFinite as isFiniteToolkit } from 'es-toolkit/compat';
import { isFinite as isFiniteLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('isFinite', () => {
bench('es-toolkit/isFinite', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { isRegExp as isRegExpToolkit } from 'es-toolkit/predicate';
import { isRegExp as isRegExpToolkitCompat } from 'es-toolkit/compat';
import { isRegExp as isRegExpToolkit } from 'es-toolkit/predicate';
import { isRegExp as isRegExpLodash } from 'lodash';
describe('isRegExp', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { isString as isStringToolkit } from 'es-toolkit/predicate';
import { isString as isStringToolkitCompat } from 'es-toolkit/compat';
import { isString as isStringToolkit } from 'es-toolkit/predicate';
import { isString as isStringLodash } from 'lodash';
describe('isString', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { isSymbol as isSymbolToolkit } from 'es-toolkit/predicate';
import { isSymbol as isSymbolToolkitCompat } from 'es-toolkit/compat';
import { isSymbol as isSymbolToolkit } from 'es-toolkit/predicate';
import { isSymbol as isSymbolLodash } from 'lodash';
describe('isSymbol', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { omitBy as omitByToolkit } from 'es-toolkit';
import { omitBy as omitByLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('omitBy', () => {
bench('es-toolkit/omitBy', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { once as onceToolkit } from 'es-toolkit';
import { once as onceLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('once', () => {
bench('es-toolkit/once', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { property as propertyToolkit } from 'es-toolkit/compat';
import { property as propertyLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('property', () => {
bench('es-toolkit/property', () => {

View File

@ -1,4 +1,4 @@
import { describe, bench } from 'vitest';
import { bench, describe } from 'vitest';
import { set as setToolkitCompat } from 'es-toolkit/compat';
import { set as lodashSet } from 'lodash';

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { some as someToolkit } from 'es-toolkit/compat';
import { some as someLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('some', () => {
bench('es-toolkit/some', () => {

View File

@ -1,7 +1,7 @@
import { bench, describe } from 'vitest';
import { startCase as startCaseToolkit } from 'es-toolkit';
import { startCase as startCaseToolkitCompat } from 'es-toolkit/compat';
import { startCase as startCaseLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('startCase', () => {
bench('es-toolkit/startCase', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { fill as fillLodash } from 'lodash';
import { toFilled as toFilledToolkit } from 'es-toolkit';
import { fill as fillLodash } from 'lodash';
describe('fill function performance comparison', () => {
bench('es-toolkit/toFilled', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { union as unionToolkit } from 'es-toolkit';
import { union as unionLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('union', () => {
bench('es-toolkit/union', () => {

View File

@ -1,7 +1,7 @@
import { bench, describe } from 'vitest';
import { uniqBy as uniqByToolkit } from 'es-toolkit';
import { uniqBy as uniqByLodash } from 'lodash';
import { randomInt } from 'crypto';
import { uniqBy as uniqByLodash } from 'lodash';
describe('uniqBy, small arrays', () => {
bench('es-toolkit/uniqBy', () => {

View File

@ -1,7 +1,7 @@
import { bench, describe } from 'vitest';
import { uniqWith as uniqWithToolkit } from 'es-toolkit';
import { uniqWith as uniqWithLodash } from 'lodash';
import { randomInt } from 'crypto';
import { uniqWith as uniqWithLodash } from 'lodash';
describe('uniqWith, small arrays', () => {
bench('es-toolkit/uniqWith', () => {

View File

@ -1,4 +1,4 @@
import { describe, bench } from 'vitest';
import { bench, describe } from 'vitest';
import { unset as unsetToolkitCompat } from 'es-toolkit/compat';
import { unset as unsetLodash } from 'lodash';

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { unzipWith as unzipWithToolkit } from 'es-toolkit';
import { unzipWith as unzipWithLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('unzipWith', () => {
bench('es-toolkit/unzipWith', () => {

View File

@ -1,6 +1,6 @@
import { bench, describe } from 'vitest';
import { xorWith as xorWithToolkit } from 'es-toolkit';
import { xorWith as xorWithLodash } from 'lodash';
import { bench, describe } from 'vitest';
describe('xorWith', () => {
bench('es-toolkit/xorWith', () => {

View File

@ -40,20 +40,10 @@ const ids = titles.map(title => title.toLowerCase().replaceAll('"', '').replace(
</script>
<template>
<template
v-for="(category, index) in categories"
:key="category"
>
<h3
:id="ids[index]"
tabindex="-1"
>
<template v-for="(category, index) in categories" :key="category">
<h3 :id="ids[index]" tabindex="-1">
{{ titles[index] }}
<a
class="header-anchor"
:href="`#${ids[index]}`"
:aria-label="`Permalink to ${ids[index]}`"
/>
<a class="header-anchor" :href="`#${ids[index]}`" :aria-label="`Permalink to ${ids[index]}`" />
</h3>
<table tabindex="0">
<thead>
@ -63,16 +53,9 @@ const ids = titles.map(title => title.toLowerCase().replaceAll('"', '').replace(
</tr>
</thead>
<tbody>
<tr
v-for="item in data[category]"
:key="item.name"
>
<tr v-for="item in data[category]" :key="item.name">
<td>
<a
:href="`https://lodash.com/docs/4.17.15#${item.name}`"
target="_blank"
rel="noopener noreferrer"
>{{
<a :href="`https://lodash.com/docs/4.17.15#${item.name}`" target="_blank" rel="noopener noreferrer">{{
item.name
}}</a>
</td>

View File

@ -1,11 +1,11 @@
import { defineConfig } from 'vitepress';
import container from 'markdown-it-container';
import { defineConfig } from 'vitepress';
import { renderSandbox } from 'vitepress-plugin-sandpack';
import { en } from './en.mts';
import { ko } from './ko.mts';
import { ja } from './ja.mts';
import { zh_hans } from './zh_hans.mts';
import { ko } from './ko.mts';
import { shared } from './shared.mts';
import { zh_hans } from './zh_hans.mts';
export default defineConfig({
...shared,

View File

@ -1,7 +1,7 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from './libs/sortByText.mts';
import { getSidebarItems } from './libs/getSidebarItems.mts';
import path from 'node:path';
import { type DefaultTheme, defineConfig } from 'vitepress';
import { getSidebarItems } from './libs/getSidebarItems.mts';
import { sortByText } from './libs/sortByText.mts';
const docsRoot = path.resolve(import.meta.dirname, '..');

View File

@ -1,7 +1,7 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from './libs/sortByText.mts';
import { getSidebarItems } from './libs/getSidebarItems.mts';
import path from 'node:path';
import { type DefaultTheme, defineConfig } from 'vitepress';
import { getSidebarItems } from './libs/getSidebarItems.mts';
import { sortByText } from './libs/sortByText.mts';
const docsRoot = path.resolve(import.meta.dirname, '..');

View File

@ -1,6 +1,6 @@
import { readdirSync } from 'fs';
import { resolve } from 'path';
import functions from './functions.json';
import { readdirSync } from 'fs';
export default {
load() {

View File

@ -1,6 +1,6 @@
import { DefaultTheme } from 'vitepress';
import path from 'node:path';
import glob from 'fast-glob';
import path from 'node:path';
import { DefaultTheme } from 'vitepress';
export function getSidebarItems(docsRoot: string, ...parts: string[]): DefaultTheme.SidebarItem[] {
const files = glob.sync(path.join(docsRoot, ...parts, '*'));

View File

@ -1,7 +1,7 @@
import { type DefaultTheme, defineConfig } from 'vitepress';
import { sortByText } from './libs/sortByText.mts';
import path from 'node:path';
import { type DefaultTheme, defineConfig } from 'vitepress';
import { getSidebarItems } from './libs/getSidebarItems.mts';
import { sortByText } from './libs/sortByText.mts';
const docsRoot = path.resolve(import.meta.dirname, '..');

View File

@ -1,10 +1,10 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import jsdoc from 'eslint-plugin-jsdoc';
import prettier from 'eslint-config-prettier';
import pluginVue from 'eslint-plugin-vue';
import noForOfArrayPlugin from 'eslint-plugin-no-for-of-array';
import prettier from 'eslint-plugin-prettier/recommended';
import pluginVue from 'eslint-plugin-vue';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import pluginJs from '@eslint/js';
export default [
{

View File

@ -137,17 +137,20 @@
"@eslint/js": "^9.9.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/broken-link-checker": "^0",
"@types/eslint": "^9",
"@types/jscodeshift": "^0.11.11",
"@types/node": "^20.12.11",
"@types/tar": "^6.1.13",
"@vitest/coverage-istanbul": "^1.5.2",
"@vue/compiler-sfc": "^3.5.10",
"broken-link-checker": "^0.7.8",
"eslint": "^9.9.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jsdoc": "^50.2.2",
"eslint-plugin-no-for-of-array": "^0.0.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-vue": "^9.28.0",
"execa": "^9.3.0",
"globals": "^15.9.0",
@ -162,6 +165,11 @@
"typescript-eslint": "^8.1.0",
"vitest": "^1.5.2"
},
"dependenciesMeta": {
"@trivago/prettier-plugin-sort-imports@4.3.0": {
"unplugged": true
}
},
"sideEffects": false,
"scripts": {
"prepack": "yarn build",

View File

@ -1,12 +1,11 @@
// @ts-check
import fs from 'node:fs';
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import dtsPlugin from 'rollup-plugin-dts';
import terserPlugin from '@rollup/plugin-terser';
import tsPlugin from '@rollup/plugin-typescript';
import dtsPlugin from 'rollup-plugin-dts';
// eslint-disable-next-line @typescript-eslint/naming-convention
const __dirname = dirname(fileURLToPath(import.meta.url));

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { compact } from './compact';
describe('compact', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { isSubset } from './isSubset';
describe('isSubset', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { orderBy } from './orderBy';
describe('orderBy', () => {

View File

@ -1,4 +1,4 @@
import { describe, expect, it, expectTypeOf } from 'vitest';
import { describe, expect, expectTypeOf, it } from 'vitest';
import { partition } from './partition';
describe('partition', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { sortBy } from './sortBy';
describe('sortBy', () => {

View File

@ -1,5 +1,7 @@
import { describe, it, expect } from 'vitest';
import { takeWhile } from './takeWhile'; // adjust the import path as necessary
import { describe, expect, it } from 'vitest';
import { takeWhile } from './takeWhile';
// adjust the import path as necessary
describe('takeWhile', () => {
it('should return elements while the predicate is true', () => {

View File

@ -1,5 +1,4 @@
import { describe, expect, it } from 'vitest';
import { unzip } from './unzip';
describe('unzip', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { compareValues } from './compareValues';
describe('compareValues', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { getTag } from './getTag';
describe('getTag function', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { isKey } from './isKey';
describe('isKey', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { toArgs } from './toArgs';
describe('toArgs', () => {

View File

@ -1,5 +1,5 @@
import { chunk } from './chunk.ts';
import { describe, expect, it } from 'vitest';
import { chunk } from './chunk.ts';
/**
* @see https://github.com/lodash/lodash/blob/6a2cc1dfcf7634fea70d1bc5bd22db453df67b42/test/chunk.spec.js#L1

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { difference } from './difference';
import { LARGE_ARRAY_SIZE } from '../_internal/LARGE_ARRAY_SIZE';
import { range } from '../../math/range';
import { LARGE_ARRAY_SIZE } from '../_internal/LARGE_ARRAY_SIZE';
/**
* @see https://github.com/lodash/lodash/blob/6a2cc1dfcf7634fea70d1bc5bd22db453df67b42/test/difference-methods.spec.js#L1

View File

@ -1,9 +1,9 @@
import { describe, expect, it } from 'vitest';
import { every } from './every';
import { identity } from '../_internal/identity';
import { empties } from '../_internal/empties';
import { stubTrue } from '../_internal/stubTrue';
import { identity } from '../_internal/identity';
import { stubFalse } from '../_internal/stubFalse';
import { stubTrue } from '../_internal/stubTrue';
describe('every', () => {
it('should return true for array with all elements passing predicate', () => {

View File

@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { falsey } from '../_internal/falsey';
import { fill } from './fill.ts';
import { falsey } from '../_internal/falsey';
describe('fill', () => {
it('should use a default `start` of `0` and a default `end` of `length`', () => {

View File

@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
import { empties } from '../_internal/empties';
import { find } from './find';
import { empties } from '../_internal/empties';
import { slice } from '../_internal/slice';
describe('find', () => {

View File

@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { findLastIndex } from './findLastIndex';
import { falsey } from '../_internal/falsey';
import { slice } from '../_internal/slice';
import { stubZero } from '../_internal/stubZero';
import { falsey } from '../_internal/falsey';
describe('findLastIndex', () => {
const objects = [

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { flatten } from './flatten';
import { args } from '../_internal/args';

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { flattenDeep } from './flattenDeep';
import { args } from '../_internal/args';

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { flattenDepth } from './flattenDepth';
import { args } from '../_internal/args';

View File

@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { head, first } from '../index';
import { first, head } from '../index';
/**
* @see https://github.com/lodash/lodash/blob/6a2cc1dfcf7634fea70d1bc5bd22db453df67b42/test/head.spec.js#L1

View File

@ -1,10 +1,10 @@
import { describe, expect, it } from 'vitest';
import { includes } from './includes';
import { describe, it, expect } from 'vitest';
import { stubFalse } from '../_internal/stubFalse';
import { empties } from '../_internal/empties';
import { toArgs } from '../_internal/toArgs';
import { args } from '../_internal/args';
import { empties } from '../_internal/empties';
import { falsey } from '../_internal/falsey';
import { stubFalse } from '../_internal/stubFalse';
import { toArgs } from '../_internal/toArgs';
describe('includes', () => {
Object.entries({

View File

@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { orderBy } from './orderBy.ts';
import { falsey } from '../_internal/falsey.ts';
import { zipObject } from '../../array/zipObject.ts';
import { partialRight } from '../../function/partialRight.ts';
import { falsey } from '../_internal/falsey.ts';
describe('orderBy', () => {
class Pair {

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { size } from './size';
import { falsey } from '../_internal/falsey';
import { toArgs } from '../_internal/toArgs';
import { size } from './size';
const args = toArgs([1, 2, 3]);
/**

View File

@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { some } from './some';
import { empties } from '../_internal/empties';
import { identity } from '../_internal/identity';
import { stubFalse } from '../_internal/stubFalse';
import { empties } from '../_internal/empties';
import { stubTrue } from '../_internal/stubTrue';
describe('some', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { attempt } from './attempt';
import { isEqual } from '../../predicate/isEqual';

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { bind } from './bind';
import { isEqual } from '../../predicate/isEqual';

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { bindKey } from './bindKey';
describe('bindKey', () => {

View File

@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { curry } from './curry';
import { describe, expect, it } from 'vitest';
import { bind } from './bind';
import { curry } from './curry';
import { partial } from '../../function/partial';
import { partialRight } from '../../function/partialRight';

View File

@ -1,8 +1,8 @@
import { describe, expect, it, vi } from 'vitest';
import { debounce } from './debounce';
import { noop } from '../../function/noop';
import { delay } from '../../promise/delay';
import { identity } from '../_internal/identity';
import { noop } from '../../function/noop';
describe('debounce', () => {
it('should debounce function calls', async () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { rearg } from './rearg';
describe('rearg', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { rest } from './rest';
describe('rest', () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { spread } from './spread';
describe('spread', () => {

View File

@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { throttle } from './throttle';
import { noop } from '../../function/noop';
import { delay } from '../../promise/delay';
import { identity } from '../_internal/identity';
import { noop } from '../../function/noop';
describe('throttle', () => {
it('should throttle a function', async () => {

View File

@ -1,4 +1,4 @@
import { describe, it, expect } from 'vitest';
import { describe, expect, it } from 'vitest';
import { parseInt } from './parseInt';
describe('parseInt', () => {

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { random } from './random';
import { uniq } from '../../array/uniq';
import { stubTrue } from '../_internal/stubTrue';
import { random } from './random';
import { describe, expect, it } from 'vitest';
describe('random', () => {
const array = Array.from({ length: 100 });

View File

@ -1,6 +1,6 @@
import { clamp } from './clamp.ts';
import { random as randomToolkit } from '../../math/random.ts';
import { randomInt as randomIntToolkit } from '../../math/randomInt.ts';
import { clamp } from './clamp.ts';
/**
* Generate a random number within 0 and 1.

View File

@ -1,8 +1,8 @@
import { describe, expect, it } from 'vitest';
import { cloneDeep } from './cloneDeep';
import { range } from '../../math/range';
import { LARGE_ARRAY_SIZE } from '../_internal/LARGE_ARRAY_SIZE';
import { args } from '../_internal/args';
import { LARGE_ARRAY_SIZE } from '../_internal/LARGE_ARRAY_SIZE';
import { stubTrue } from '../_internal/stubTrue';
describe('cloneDeep', () => {

View File

@ -1,6 +1,6 @@
import { falsey } from '../_internal/falsey';
import { describe, expect, it } from 'vitest';
import { fromPairs } from './fromPairs';
import { falsey } from '../_internal/falsey';
describe('fromPairs', () => {
it('should convert an array of key-value pairs into an object', () => {

View File

@ -1,7 +1,7 @@
import type { Get } from './get.types.ts';
import { isDeepKey } from '../_internal/isDeepKey.ts';
import { toKey } from '../_internal/toKey.ts';
import { toPath } from '../util/toPath.ts';
import type { Get } from './get.types.ts';
/**
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.

View File

@ -1,11 +1,11 @@
import { describe, expect, it } from 'vitest';
import { toArgs } from '../_internal/toArgs';
import { has } from './has';
import { stubTrue } from '../_internal/stubTrue';
import { range } from '../../math/range';
import { args } from '../_internal/args';
import { symbol } from '../_internal/symbol';
import { stubFalse } from '../_internal/stubFalse';
import { stubTrue } from '../_internal/stubTrue';
import { symbol } from '../_internal/symbol';
import { toArgs } from '../_internal/toArgs';
describe('has', () => {
it(`should check for own properties`, () => {

View File

@ -1,7 +1,7 @@
import { isDeepKey } from '../_internal/isDeepKey.ts';
import { isIndex } from '../_internal/isIndex.ts';
import { toPath } from '../util/toPath.ts';
import { isArguments } from '../predicate/isArguments.ts';
import { toPath } from '../util/toPath.ts';
/**
* Checks if a given path exists within an object.

View File

@ -1,6 +1,6 @@
import { property } from './property.ts';
import { mapKeys as mapKeysToolkit } from '../../object/mapKeys.ts';
import { identity } from '../_internal/identity.ts';
import { property } from './property.ts';
/**
* Creates a new object with the same values as the given object, but with keys generated

View File

@ -1,6 +1,6 @@
import { property } from './property.ts';
import { mapValues as mapValuesToolkit } from '../../object/mapValues.ts';
import { identity } from '../_internal/identity.ts';
import { property } from './property.ts';
/**
* Creates a new object with the same keys as the given object, but with values generated

View File

@ -1,11 +1,11 @@
import { describe, expect, it } from 'vitest';
import { merge } from './merge';
import { args } from '../_internal/args';
import { isArguments } from '../predicate/isArguments';
import { typedArrays } from '../_internal/typedArrays';
import { range } from '../../math/range';
import { stubTrue } from '../_internal/stubTrue';
import { isEqual } from '../../predicate/isEqual';
import { args } from '../_internal/args';
import { stubTrue } from '../_internal/stubTrue';
import { typedArrays } from '../_internal/typedArrays';
import { isArguments } from '../predicate/isArguments';
describe('merge', () => {
it('should merge `source` into `object`', () => {

View File

@ -1,5 +1,5 @@
import { noop } from '../../function/noop.ts';
import { mergeWith } from './mergeWith.ts';
import { noop } from '../../function/noop.ts';
/**
* Merges the properties of one or more source objects into the target object.

Some files were not shown because too many files have changed in this diff Show More