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AAC;AACnB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE;IAC7B,MAAM,OAAO,GAAgB;QAC3B,cAAc,EAAE,kBAAkB;KACnC,CAAC;IACF,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,CAAC,aAAa,GAAG,UAAU,KAAK,EAAE,CAAC;IAC5C,CAAC;IAED,MAAM,IAAI,GAAgB;QACxB,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,aAAa;QAC1B,OAAO;QACP,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,aAAa;KACxB,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,aAAqB,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1D,GAAG,iBAAiB,EAAE;IACtB,MAAM,EAAE,aAAa,CAAC,WAAW,EAAE;CACpC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClE,MAAM,CAAC,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"} |
| import { Jsonify } from 'type-fest'; | ||
| export declare const UnauthorizedErrorEvent = "@slangy/client:unauthorized"; | ||
| export declare const urlWithQuery: <Query extends object>(url: string, params: Jsonify<Query>) => string; | ||
@@ -3,0 +4,0 @@ export declare const getRequest: <Res, NoResponse extends boolean = false>(url: string) => Promise<NoResponse extends true ? void : Jsonify<Res>>; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/rest/request.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+EpC,eAAO,MAAM,YAAY,8BAA+B,MAAM,mCAE7D,CAAC;AAEF,eAAO,MAAM,UAAU,iDA1B0B,MAAM,2DA0BI,CAAC;AAC5D,eAAO,MAAM,WAAW,yDAf+B,MAAM,yEAeR,CAAC;AACtD,eAAO,MAAM,uBAAuB,yDAhBmB,MAAM,yEAgBU,CAAC;AACxE,eAAO,MAAM,mBAAmB,iDA7BiB,MAAM,2DA6Bc,CAAC;AACtE,eAAO,MAAM,YAAY,yDAlB8B,MAAM,yEAkBN,CAAC;AACxD,eAAO,MAAM,wBAAwB,yDAnBkB,MAAM,yEAmBY,CAAC;AAC1E,eAAO,MAAM,oBAAoB,iDAhCgB,MAAM,2DAgCgB,CAAC;AACxE,eAAO,MAAM,UAAU,yDArBgC,MAAM,yEAqBV,CAAC;AACpD,eAAO,MAAM,sBAAsB,yDAtBoB,MAAM,yEAsBQ,CAAC;AACtE,eAAO,MAAM,kBAAkB,iDAnCkB,MAAM,2DAmCY,CAAC;AACpE,eAAO,MAAM,aAAa,iDApCuB,MAAM,2DAoCgB,CAAC"} | ||
| {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/rest/request.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,eAAO,MAAM,sBAAsB,gCAAgC,CAAC;AAgFpE,eAAO,MAAM,YAAY,8BAA+B,MAAM,mCAE7D,CAAC;AAEF,eAAO,MAAM,UAAU,iDA1B0B,MAAM,2DA0BI,CAAC;AAC5D,eAAO,MAAM,WAAW,yDAf+B,MAAM,yEAeR,CAAC;AACtD,eAAO,MAAM,uBAAuB,yDAhBmB,MAAM,yEAgBU,CAAC;AACxE,eAAO,MAAM,mBAAmB,iDA7BiB,MAAM,2DA6Bc,CAAC;AACtE,eAAO,MAAM,YAAY,yDAlB8B,MAAM,yEAkBN,CAAC;AACxD,eAAO,MAAM,wBAAwB,yDAnBkB,MAAM,yEAmBY,CAAC;AAC1E,eAAO,MAAM,oBAAoB,iDAhCgB,MAAM,2DAgCgB,CAAC;AACxE,eAAO,MAAM,UAAU,yDArBgC,MAAM,yEAqBV,CAAC;AACpD,eAAO,MAAM,sBAAsB,yDAtBoB,MAAM,yEAsBQ,CAAC;AACtE,eAAO,MAAM,kBAAkB,iDAnCkB,MAAM,2DAmCY,CAAC;AACpE,eAAO,MAAM,aAAa,iDApCuB,MAAM,2DAoCgB,CAAC"} |
@@ -0,17 +1,20 @@ | ||
| import { ClientErrorStatusCode } from '@slangy/common/http/statusCode.js'; | ||
| import { BadRequestError } from '@slangy/common/rest/error.js'; | ||
| import { stringify } from 'qs'; | ||
| export const UnauthorizedErrorEvent = '@slangy/client:unauthorized'; | ||
| import { createInitForDelete, createInitForGet, createInitForPatch, createInitForPost, createInitForPut, } from './init.js'; | ||
| const statusMiddleware = async (res) => { | ||
| switch (res.status) { | ||
| case 400: { | ||
| case ClientErrorStatusCode.ClientErrorBadRequest: { | ||
| const validationErrors = await res.json(); | ||
| throw new BadRequestError('Bad request error', validationErrors); | ||
| } | ||
| case 401: { | ||
| // TODO: handle unauthorized | ||
| return res; | ||
| case ClientErrorStatusCode.ClientErrorUnauthorized: { | ||
| const event = new CustomEvent(UnauthorizedErrorEvent, { detail: res }); | ||
| window.dispatchEvent(event); | ||
| throw event; | ||
| } | ||
| default: { | ||
| if (res.status >= 400) { | ||
| // TODO: consider using a custom error class (maybe the one implemented in turbo-server -moving it to turbo-common-) | ||
| if (res.status >= 402) { | ||
| // TODO: consider using a custom error class | ||
| const error = new Error('Request failed'); | ||
@@ -18,0 +21,0 @@ error.cause = res.status; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/rest/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe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B,IAAI,CAAC,MAAM,CAAC,CAAC;IACf,CAAC;IACD,OAAO,CAAC,GAAG,EAAE,KAAK;QAChB,IAAI,CAAC;YACH,GAAG,KAAK,EAAE;YACV,CAAC,GAAG,CAAC,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;IACD,KAAK;QACH,IAAI,CAAC,EAAE,CAAC,CAAC;IACX,CAAC;IACD,OAAO,CAAC,GAAW;QACjB,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;QAEvB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;CACF,CAAC;AAEF,eAAe,aAAa,CAAC"} |
+18
-15
| { | ||
| "name": "@slangy/client", | ||
| "version": "2.0.1", | ||
| "version": "2.1.0", | ||
| "author": { | ||
@@ -10,2 +10,5 @@ "name": "Dani Lupión", | ||
| "type": "module", | ||
| "files": [ | ||
| "dist/**/*" | ||
| ], | ||
| "exports": { | ||
@@ -34,21 +37,21 @@ "./*": "./dist/*" | ||
| "qs": "^6.11.2", | ||
| "type-fest": "^4.4.0" | ||
| "type-fest": "^4.8.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/gtag.js": "^0.0.16", | ||
| "@types/jest": "^29.5.5", | ||
| "@types/node": "^20.8.6", | ||
| "@typescript-eslint/eslint-plugin": "^6.7.5", | ||
| "@typescript-eslint/parser": "^6.7.5", | ||
| "eslint": "^8.51.0", | ||
| "eslint-config-prettier": "^9.0.0", | ||
| "@types/gtag.js": "^0.0.18", | ||
| "@types/jest": "^29.5.10", | ||
| "@types/node": "^20.10.2", | ||
| "@typescript-eslint/eslint-plugin": "^6.13.1", | ||
| "@typescript-eslint/parser": "^6.13.1", | ||
| "eslint": "^8.55.0", | ||
| "eslint-config-prettier": "^9.1.0", | ||
| "eslint-import-resolver-typescript": "^3.6.1", | ||
| "eslint-plugin-eslint-comments": "^3.2.0", | ||
| "eslint-plugin-import": "^2.28.1", | ||
| "eslint-plugin-jest": "^27.4.2", | ||
| "eslint-plugin-import": "^2.29.0", | ||
| "eslint-plugin-jest": "^27.6.0", | ||
| "jest": "^29.7.0", | ||
| "lint-staged": "^14.0.1", | ||
| "nodemon": "^3.0.1", | ||
| "prettier": "^3.0.3", | ||
| "typescript": "^5.2.2" | ||
| "lint-staged": "^15.1.0", | ||
| "nodemon": "^3.0.2", | ||
| "prettier": "^3.1.0", | ||
| "typescript": "^5.3.2" | ||
| }, | ||
@@ -55,0 +58,0 @@ "lint-staged": { |
| { | ||
| "env": { | ||
| "node": true, | ||
| "es6": true | ||
| }, | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:@typescript-eslint/recommended", | ||
| "plugin:jest/recommended", | ||
| "plugin:jest/style", | ||
| "plugin:eslint-comments/recommended", | ||
| "plugin:import/errors", | ||
| "plugin:import/warnings", | ||
| "plugin:import/recommended", | ||
| "plugin:import/typescript", | ||
| // "plugin:n/recommended-module", currently not working properly with typescript, review in the future | ||
| "prettier" | ||
| ], | ||
| "globals": { | ||
| "Atomics": "readonly", | ||
| "SharedArrayBuffer": "readonly" | ||
| }, | ||
| "settings": { | ||
| "import/resolver": { | ||
| "node": { | ||
| "extensions": [".js", ".jsx", ".ts", ".tsx"] | ||
| }, | ||
| "typescript": { | ||
| "project": "./tsconfig.json" | ||
| } | ||
| } | ||
| }, | ||
| "parser": "@typescript-eslint/parser", | ||
| "parserOptions": { | ||
| "ecmaVersion": 2020, | ||
| "sourceType": "module" | ||
| }, | ||
| "plugins": ["@typescript-eslint"], | ||
| "rules": { | ||
| "node/no-missing-import": "off", | ||
| "@typescript-eslint/no-unused-vars": ["error", { "ignoreRestSiblings": true }], | ||
| "import/order": ["error", { "newlines-between": "always", "alphabetize": { "order": "asc" } }], | ||
| "sort-imports": [ | ||
| "error", | ||
| { | ||
| "ignoreCase": false, | ||
| "ignoreDeclarationSort": true, | ||
| "ignoreMemberSort": false, | ||
| "memberSyntaxSortOrder": ["none", "all", "multiple", "single"] | ||
| } | ||
| ] | ||
| } | ||
| } |
| { | ||
| "printWidth": 100, | ||
| "singleQuote": true, | ||
| "trailingComma": "all" | ||
| } |
| const measurementId = process.env.REACT_APP_GA_MEASUREMENT_ID; | ||
| const measurementIdPresent = () => { | ||
| return measurementId !== undefined; | ||
| }; | ||
| let initializationPromise: Promise<void> | undefined; | ||
| export const initialize = () => { | ||
| if (measurementIdPresent() && !initializationPromise) { | ||
| initializationPromise = new Promise((resolve) => { | ||
| const googleScript = document.createElement('script'); | ||
| googleScript.async = true; | ||
| googleScript.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`; | ||
| googleScript.addEventListener('load', () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (window as any).dataLayer = (window as any).dataLayer || []; | ||
| window.gtag = function gtag() { | ||
| // eslint-disable-next-line prefer-rest-params, @typescript-eslint/no-explicit-any | ||
| (window as any).dataLayer.push(arguments); | ||
| }; | ||
| window.gtag('js', new Date()); | ||
| window.gtag('config', measurementId || ''); | ||
| resolve(); | ||
| }); | ||
| document.head.appendChild(googleScript); | ||
| }); | ||
| } | ||
| }; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const safeGtag: Gtag.Gtag = (...args: any[]) => { | ||
| if (initializationPromise) { | ||
| return initializationPromise.then(() => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| (gtag as any)(...args); | ||
| }); | ||
| } | ||
| return undefined; | ||
| }; | ||
| type PageviewParams = { | ||
| pathname?: string; | ||
| title?: string; | ||
| }; | ||
| export const pageview = async ({ pathname, title }: PageviewParams) => { | ||
| await safeGtag('event', 'page_view', { | ||
| page_path: pathname, | ||
| page_title: title, | ||
| send_to: measurementId, | ||
| }); | ||
| }; |
| export * from '@slangy/common/api/pagination.js'; |
| export { email, password } from '@slangy/common/regex.js'; |
| import Method from '@slangy/common/http/method.js'; | ||
| let token: string | undefined; | ||
| export const setToken = (newToken?: string) => { | ||
| token = newToken; | ||
| }; | ||
| const createDefaultInit = () => { | ||
| const headers: HeadersInit = { | ||
| 'content-type': 'application/json', | ||
| }; | ||
| if (token) { | ||
| headers.authorization = `Bearer ${token}`; | ||
| } | ||
| const init: RequestInit = { | ||
| cache: 'no-cache', | ||
| credentials: 'same-origin', | ||
| headers, | ||
| redirect: 'follow', | ||
| referrer: 'no-referrer', | ||
| }; | ||
| return init; | ||
| }; | ||
| const createInitFactory = (requestMethod: Method) => () => ({ | ||
| ...createDefaultInit(), | ||
| method: requestMethod.toUpperCase(), | ||
| }); | ||
| export const createInitForGet = createInitFactory(Method.GET); | ||
| export const createInitForPost = createInitFactory(Method.POST); | ||
| export const createInitForPut = createInitFactory(Method.PUT); | ||
| export const createInitForPatch = createInitFactory(Method.PATCH); | ||
| export const createInitForDelete = createInitFactory(Method.DELETE); |
| export type ApiModel<BaseModel, Id = number> = BaseModel & { | ||
| id: Id; | ||
| }; |
| import { BadRequestError, ValidationError } from '@slangy/common/rest/error.js'; | ||
| import { stringify } from 'qs'; | ||
| import { Jsonify } from 'type-fest'; | ||
| import { | ||
| createInitForDelete, | ||
| createInitForGet, | ||
| createInitForPatch, | ||
| createInitForPost, | ||
| createInitForPut, | ||
| } from './init.js'; | ||
| type SafeResponse<Data> = Omit<Response, 'json'> & { | ||
| json: () => Promise<Data>; | ||
| }; | ||
| type BadRequestResponse = SafeResponse<ValidationError>; | ||
| const statusMiddleware = async <Res>(res: SafeResponse<Res> | BadRequestResponse) => { | ||
| switch (res.status) { | ||
| case 400: { | ||
| const validationErrors = await (res as BadRequestResponse).json(); | ||
| throw new BadRequestError('Bad request error', validationErrors); | ||
| } | ||
| case 401: { | ||
| // TODO: handle unauthorized | ||
| return res as SafeResponse<Res>; | ||
| } | ||
| default: { | ||
| if (res.status >= 400) { | ||
| // TODO: consider using a custom error class (maybe the one implemented in turbo-server -moving it to turbo-common-) | ||
| const error = new Error('Request failed'); | ||
| error.cause = res.status; | ||
| throw error; | ||
| } | ||
| return res as SafeResponse<Res>; | ||
| } | ||
| } | ||
| }; | ||
| const jsonMiddleware = <Res>(res: SafeResponse<Res>) => res.json() as Promise<Res>; | ||
| const jsonFetch = async <Res, NoResponse>( | ||
| url: string, | ||
| init: RequestInit, | ||
| noResponse: NoResponse, | ||
| ): Promise<NoResponse extends true ? void : Res> => { | ||
| const result = await fetch(url, init).then(statusMiddleware); | ||
| if (noResponse) { | ||
| return undefined as never; | ||
| } | ||
| return (await jsonMiddleware<Res>(result)) as NoResponse extends true ? void : Res; | ||
| }; | ||
| const bodilessRequest = | ||
| (initFactory: () => RequestInit, noResponse = false) => | ||
| <Res, NoResponse extends boolean = false>(url: string) => { | ||
| return jsonFetch<Jsonify<Res>, NoResponse>( | ||
| url, | ||
| { | ||
| ...initFactory(), | ||
| }, | ||
| noResponse as NoResponse, | ||
| ); | ||
| }; | ||
| const request = | ||
| (initFactory: () => RequestInit, noResponse = false) => | ||
| <Body, Res, NoResponse extends boolean = false>(url: string, data: Body) => | ||
| jsonFetch<Jsonify<Res>, NoResponse>( | ||
| url, | ||
| { | ||
| ...initFactory(), | ||
| body: JSON.stringify(data), | ||
| }, | ||
| noResponse as NoResponse, | ||
| ); | ||
| export const urlWithQuery = <Query extends object>(url: string, params: Jsonify<Query>) => { | ||
| return `${url}?${stringify(params)}`; | ||
| }; | ||
| export const getRequest = bodilessRequest(createInitForGet); | ||
| export const postRequest = request(createInitForPost); | ||
| export const responselessPostRequest = request(createInitForPost, true); | ||
| export const bodilessPostRequest = bodilessRequest(createInitForPost); | ||
| export const patchRequest = request(createInitForPatch); | ||
| export const responselessPatchRequest = request(createInitForPatch, true); | ||
| export const bodilessPatchRequest = bodilessRequest(createInitForPatch); | ||
| export const putRequest = request(createInitForPut); | ||
| export const responselessPutRequest = request(createInitForPut, true); | ||
| export const bodilessPutRequest = bodilessRequest(createInitForPut); | ||
| export const deleteRequest = bodilessRequest(createInitForDelete, true); |
| type Dictionary = { [key: string]: string }; | ||
| const cookieSeparator = '; '; | ||
| const keyValueSeparator = '='; | ||
| const parse = (): Dictionary => | ||
| document.cookie.split(cookieSeparator).reduce((acc, cur) => { | ||
| const [key, value] = cur.split(keyValueSeparator); | ||
| return { | ||
| ...acc, | ||
| [decodeURIComponent(key)]: decodeURIComponent(value), | ||
| }; | ||
| }, {}); | ||
| const save = (newCookies: Dictionary) => { | ||
| const cookies = parse(); | ||
| const newKeys = Object.keys(newCookies); | ||
| const keys = Object.keys(cookies); | ||
| const keysToRemove = keys.filter((k) => !newKeys.includes(k)); | ||
| for (const key of keysToRemove) { | ||
| document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 GMT`; | ||
| } | ||
| const keysToSet = newKeys.filter((k) => !keys.includes(k) || cookies[k] !== newCookies[k]); | ||
| for (const key of keysToSet) { | ||
| document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(newCookies[key])}`; | ||
| } | ||
| }; | ||
| const cookieStorage: Storage = { | ||
| key(index) { | ||
| const values = Object.entries(parse()); | ||
| return values[index] && values[index][1]; | ||
| }, | ||
| get length() { | ||
| return Object.entries(parse()).length; | ||
| }, | ||
| removeItem(key) { | ||
| const values = parse(); | ||
| delete values[key]; | ||
| save(values); | ||
| }, | ||
| setItem(key, value) { | ||
| save({ | ||
| ...parse(), | ||
| [key]: value, | ||
| }); | ||
| }, | ||
| clear() { | ||
| save({}); | ||
| }, | ||
| getItem(key: string) { | ||
| const values = parse(); | ||
| return values[key]; | ||
| }, | ||
| }; | ||
| export default cookieStorage; |
| import cookies from './cookieStorage.js'; | ||
| export const localStorage = window.localStorage; | ||
| export const sessionStorage = window.sessionStorage; | ||
| export const cookieStorage = cookies; |
| export * from '@slangy/common/string.js'; |
-107
| { | ||
| "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": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
| "lib": [ | ||
| "dom", | ||
| "dom.iterable", | ||
| "esnext", | ||
| ],/* 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 TC39 stage 2 draft 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": "NodeNext", /* Specify what module code is generated. */ | ||
| "rootDir": "./src", /* Specify the root folder within your source files. */ | ||
| "moduleResolution": "NodeNext", /* 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. */ | ||
| "resolveJsonModule": true, /* Enable importing .json files. */ | ||
| // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'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. */ | ||
| // "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": "./dist", /* 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. */ | ||
| // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ | ||
| // "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. */ | ||
| "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. */ | ||
| } | ||
| } |
3
-25%1
-50%25310
-43.73%37
-24.49%297
-55.74%Updated