diff --git a/.prettierrc b/.prettierrc index 5324000..98d4830 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,8 +1,8 @@ { - "useTabs": false, - "printWidth": 800, - "tabWidth": 2, - "singleQuote": true, - "trailingComma": "es5", - "semi": true -} \ No newline at end of file + "useTabs": false, + "printWidth": 800, + "tabWidth": 2, + "singleQuote": true, + "trailingComma": "es5", + "semi": true +} diff --git a/README.md b/README.md index f3bdae9..805dfc6 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ A zero-dependency (for the forseen future hopefully), typescript-ready, fast, li # Getting started First get your locale files going. A json file is enough: + ```json // en.json { @@ -26,32 +27,34 @@ First get your locale files going. A json file is enough: ``` Then, you can use the package like this: + ```ts -import { Localization } from "shrimple-locales"; -import enLocale from "./en.json"; -import esLocale from "./es.json"; +import { Localization } from 'shrimple-locales'; +import enLocale from './en.json'; +import esLocale from './es.json'; const loc = new Localization({ - defaultLocale: "en", - fallbackLocale: "en", - locales: { - en: enLocale, - es: esLocale - } -}) + defaultLocale: 'en', + fallbackLocale: 'en', + locales: { + en: enLocale, + es: esLocale, + }, +}); // ... later in the code -foo(`${loc.get('salutes.hello')} ${loc.get('world')}`) // Hello World +foo(`${loc.get('salutes.hello')} ${loc.get('world')}`); // Hello World -loc.setLocale('es') -foo(`${loc.get('salutes.hello')} ${loc.get('world')}`) // Hola Mundo +loc.setLocale('es'); +foo(`${loc.get('salutes.hello')} ${loc.get('world')}`); // Hola Mundo ``` # Roadmap + - [x] Basic functionality - [x] Fallback locales - [x] Default locales - [x] Set locale - [x] Get all locales (`localizationFor()`) - [] Make the package read files or a directory -... and more to come! \ No newline at end of file + ... and more to come! diff --git a/package.json b/package.json index cefe882..b2a799f 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "scripts": { "build": "tsup", "dev": "tsup --watch", - "test": "vitest --disable-console-intercept" + "test": "vitest --disable-console-intercept", + "format": "prettier --write ." }, "exports": { ".": { @@ -28,6 +29,7 @@ "package.json" ], "devDependencies": { + "prettier": "3.4.1", "shrimple-locales": "^0.2.0", "tsup": "^8.0.1", "typescript": "^5.3.3", diff --git a/src/test.ts b/src/test.ts index f433e7a..d136df6 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,33 +1,33 @@ // The file is here because tsconfig is set to compile all files in src folder, and not the tests folder -import { Localization } from "./index"; +import { Localization } from './index'; export const locales = new Localization({ - defaultLocale: 'en', - fallbackLocale: 'en', - locales: { - en: { - hello: 'Hello', - inside: { - world: 'World', - 'another/object': { - key: 'key inside' - } - }, - interp: { - hello: 'Hello {{int}}' - } + defaultLocale: 'en', + fallbackLocale: 'en', + locales: { + en: { + hello: 'Hello', + inside: { + world: 'World', + 'another/object': { + key: 'key inside', }, - es: { - hello: 'Hola', - inside: { - world: 'Mundo', - 'another/object': { - key: 'key dentro' - } - }, - interp: { - hello: 'Hola {{int}}' - } - } - } -}) \ No newline at end of file + }, + interp: { + hello: 'Hello {{int}}', + }, + }, + es: { + hello: 'Hola', + inside: { + world: 'Mundo', + 'another/object': { + key: 'key dentro', + }, + }, + interp: { + hello: 'Hola {{int}}', + }, + }, + }, +}); diff --git a/src/util/getLocales.ts b/src/util/getLocales.ts index 9bc62ab..6d69275 100644 --- a/src/util/getLocales.ts +++ b/src/util/getLocales.ts @@ -1,5 +1,5 @@ -import { interpolate } from "./interpolate"; -import { Interpolations, LocaleObject, Locales } from "./types"; +import { interpolate } from './interpolate'; +import { Interpolations, LocaleObject, Locales } from './types'; export default function getLocales(args: Args): string | Record { const { key, locales, defaultLang, fallbackLang, interpolations } = args; @@ -8,18 +8,18 @@ export default function getLocales(args: Args): string | Record for (const lang in locales) { // Navigate through nested keys let value = locales[lang]; - for (const k of key.split(".")) { + for (const k of key.split('.')) { value = value[k] as LocaleObject; if (!value) break; } // Handle both string values and object values if (value) { - if (typeof value === "object") { + if (typeof value === 'object') { const innerKey = Object.keys(value)[0]; const interpolatedKey = interpolate(innerKey, interpolations); translations[lang] = value[interpolatedKey] as string; - } else if (typeof value === "string") { + } else if (typeof value === 'string') { translations[lang] = interpolate(value, interpolations); } } @@ -35,9 +35,9 @@ export default function getLocales(args: Args): string | Record } type Args = { - key: string, - locales: Locales, - defaultLang?: string, - fallbackLang?: string, - interpolations?: Interpolations -} \ No newline at end of file + key: string; + locales: Locales; + defaultLang?: string; + fallbackLang?: string; + interpolations?: Interpolations; +}; diff --git a/src/util/sanitize.ts b/src/util/sanitize.ts index 5294453..f0a86f0 100644 --- a/src/util/sanitize.ts +++ b/src/util/sanitize.ts @@ -3,9 +3,9 @@ export default function sanitize(text: string): string { /[&<>]/g, (char) => ({ - "&": "&", - "<": "<", - ">": ">", - })[char] || char, + '&': '&', + '<': '<', + '>': '>', + })[char] || char ); } diff --git a/tests/get.test.ts b/tests/get.test.ts index 31a0247..eab966d 100644 --- a/tests/get.test.ts +++ b/tests/get.test.ts @@ -1,9 +1,9 @@ -import { it, expect } from "vitest"; -import { locales } from "../src/test"; +import { it, expect } from 'vitest'; +import { locales } from '../src/test'; -it("should give multiple keys correctly for both langs", () => { - expect(locales.t("hello", {}, 'en')).toBe("Hello"); - expect(locales.t("hello", {}, 'es')).toBe("Hola"); - expect(locales.t("hello")).toBe("Hello"); - expect(locales.t("inside.world", {}, 'en')).toBe("World"); +it('should give multiple keys correctly for both langs', () => { + expect(locales.t('hello', {}, 'en')).toBe('Hello'); + expect(locales.t('hello', {}, 'es')).toBe('Hola'); + expect(locales.t('hello')).toBe('Hello'); + expect(locales.t('inside.world', {}, 'en')).toBe('World'); }); diff --git a/tests/getInterps.test.ts b/tests/getInterps.test.ts index f3571bd..ead7615 100644 --- a/tests/getInterps.test.ts +++ b/tests/getInterps.test.ts @@ -1,12 +1,12 @@ -import { it, expect } from "vitest"; -import { locales } from "../src/test"; +import { it, expect } from 'vitest'; +import { locales } from '../src/test'; -it("should return values with interpolations replaced", () => { - expect(locales.t("interp.hello", { int: 'noway' }, 'en')).toBe("Hello noway"); +it('should return values with interpolations replaced', () => { + expect(locales.t('interp.hello', { int: 'noway' }, 'en')).toBe('Hello noway'); // test to handle nonexistent interpolaitons, should return the normal {{}} string - expect(locales.t("interp.hello", {}, 'en')).toBe("Hello {{int}}"); + expect(locales.t('interp.hello', {}, 'en')).toBe('Hello {{int}}'); // check to prevent XSS - expect(locales.t("interp.hello", { int: '' }, 'en')).toBe(`Hello <script>alert("XSS")</script>`); -}); \ No newline at end of file + expect(locales.t('interp.hello', { int: '' }, 'en')).toBe(`Hello <script>alert("XSS")</script>`); +}); diff --git a/tests/localizationFor.test.ts b/tests/localizationFor.test.ts index c804fc5..1913f65 100644 --- a/tests/localizationFor.test.ts +++ b/tests/localizationFor.test.ts @@ -1,17 +1,17 @@ -import { it, expect } from "vitest"; -import { locales } from "../src/test.js"; +import { it, expect } from 'vitest'; +import { locales } from '../src/test.js'; -it("should give multiple keys correctly for both langs", () => { - expect(locales.localizationFor("hello")).toEqual({ - en: "Hello", - es: "Hola", +it('should give multiple keys correctly for both langs', () => { + expect(locales.localizationFor('hello')).toEqual({ + en: 'Hello', + es: 'Hola', }); - expect(locales.localizationFor("inside.world")).toEqual({ - en: "World", - es: "Mundo", + expect(locales.localizationFor('inside.world')).toEqual({ + en: 'World', + es: 'Mundo', }); - expect(locales.localizationFor("inside.another/object.key")).toEqual({ - en: "key inside", - es: "key dentro", + expect(locales.localizationFor('inside.another/object.key')).toEqual({ + en: 'key inside', + es: 'key dentro', }); }); diff --git a/tsconfig.json b/tsconfig.json index 17dfe00..4810faa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,109 +1,109 @@ { - "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "./src", /* Specify the root folder within your source files. */ - "moduleResolution": "Node", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - "allowImportingTsExtensions": false, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ - // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ - // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - - /* Type Checking */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } - } \ No newline at end of file + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs" /* Specify what module code is generated. */, + "rootDir": "./src" /* Specify the root folder within your source files. */, + "moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */, + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + "allowImportingTsExtensions": false /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */, + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + // "outDir": "./", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + + /* Type Checking */ + "strict": true /* Enable all strict type-checking options. */, + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} diff --git a/tsup.config.js b/tsup.config.js index dfb84d9..be74c62 100644 --- a/tsup.config.js +++ b/tsup.config.js @@ -1,4 +1,4 @@ -import { defineConfig } from 'tsup' +import { defineConfig } from 'tsup'; export default defineConfig({ entry: ['./src/index.ts', './src/test.ts'], @@ -7,4 +7,4 @@ export default defineConfig({ format: ['cjs', 'esm'], dts: true, clean: true, -}) \ No newline at end of file +}); diff --git a/yarn.lock b/yarn.lock index 52b3d70..b0761f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1209,6 +1209,11 @@ postcss@^8.4.38: picocolors "^1.0.0" source-map-js "^1.2.0" +prettier@3.4.1: + version "3.4.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.4.1.tgz#e211d451d6452db0a291672ca9154bc8c2579f7b" + integrity sha512-G+YdqtITVZmOJje6QkXQWzl3fSfMxFwm1tjTyo9exhkmWSqC4Yhd1+lug++IlR2mvRVAxEDDWYkQdeSztajqgg== + pretty-format@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.7.0.tgz#ca42c758310f365bfa71a0bda0a807160b776812" @@ -1361,8 +1366,16 @@ std-env@^3.5.0: resolved "https://registry.yarnpkg.com/std-env/-/std-env-3.7.0.tgz#c9f7386ced6ecf13360b6c6c55b8aaa4ef7481d2" integrity sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0: - name string-width-cjs +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.1.0: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -1380,8 +1393,14 @@ string-width@^5.0.1, string-width@^5.1.2: emoji-regex "^9.2.2" strip-ansi "^7.0.1" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: - name strip-ansi-cjs +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==