From 5d008a4c425550a5dc4e029f39cef292b78e5196 Mon Sep 17 00:00:00 2001 From: maxbilbow Date: Sun, 7 May 2023 14:52:28 +0100 Subject: [PATCH 1/2] Updated prettier config --- .prettierrc.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.prettierrc.json b/.prettierrc.json index 544138b..9fb7ef2 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,3 +1,6 @@ { - "singleQuote": true + "singleQuote": true, + "endOfLine": "lf", + "printWidth": 120, + "parser": "typescript" } From 2f73a1024c023653bc159861077ccfb610517c8a Mon Sep 17 00:00:00 2001 From: maxbilbow Date: Sun, 7 May 2023 15:04:02 +0100 Subject: [PATCH 2/2] diff --- .prettierrc.json | 3 ++- README.md | 5 +---- package-lock.json | 8 ++++---- package.json | 2 +- src/.eslintrc.cjs | 5 +---- src/lib/ServiceProvider.ts | 34 ++++++---------------------------- src/lib/custom-hooks/index.ts | 5 +---- src/lib/jsx/NgTranslate.tsx | 5 +---- src/lib/wrappers/main.ts | 11 +++-------- 9 files changed, 20 insertions(+), 58 deletions(-) diff --git a/.prettierrc.json b/.prettierrc.json index 9fb7ef2..707ea14 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -2,5 +2,6 @@ "singleQuote": true, "endOfLine": "lf", "printWidth": 120, - "parser": "typescript" + "tabWidth": 2, + "arrowParens": "always" } diff --git a/README.md b/README.md index 13ce8d4..d3571da 100644 --- a/README.md +++ b/README.md @@ -29,10 +29,7 @@ const MyReactComponent = ({ title, myController }) => {

{title}

{state}

- +

); diff --git a/package-lock.json b/package-lock.json index dba1b70..ce6ff04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "The Unlicense", "devDependencies": { "@jest/globals": "^29.5.0", - "@tsconfig/node18": "1", + "@tsconfig/node18": "^2.0.0", "@types/angular": "x", "@types/angular-translate": "x", "@types/jest": "^29.5.0", @@ -1242,9 +1242,9 @@ } }, "node_modules/@tsconfig/node18": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-1.0.3.tgz", - "integrity": "sha512-RbwvSJQsuN9TB04AQbGULYfOGE/RnSFk/FLQ5b0NmDf5Kx2q/lABZbHQPKCO1vZ6Fiwkplu+yb9pGdLy1iGseQ==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-2.0.0.tgz", + "integrity": "sha512-uI/B0ShkiEwTk036pncXucVlj4y11EW6mycQvCEzC1PkR2TBvdQZ5Wf96dp+XXWAc70FEDfvwTqanoaDpP6rPw==", "dev": true }, "node_modules/@types/angular": { diff --git a/package.json b/package.json index d94bc21..8de3a96 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "devDependencies": { "@jest/globals": "^29.5.0", - "@tsconfig/node18": "1", + "@tsconfig/node18": "^2.0.0", "@types/angular": "x", "@types/angular-translate": "x", "@types/jest": "^29.5.0", diff --git a/src/.eslintrc.cjs b/src/.eslintrc.cjs index 8bdb156..7676373 100644 --- a/src/.eslintrc.cjs +++ b/src/.eslintrc.cjs @@ -2,10 +2,7 @@ module.exports = { overrides: [ { files: ['**/*.ts', '**/*.tsx'], - extends: [ - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - ], + extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'], parser: '@typescript-eslint/parser', plugins: ['@typescript-eslint'], env: { diff --git a/src/lib/ServiceProvider.ts b/src/lib/ServiceProvider.ts index 7b20d73..bc6afa4 100644 --- a/src/lib/ServiceProvider.ts +++ b/src/lib/ServiceProvider.ts @@ -1,10 +1,4 @@ -import { - IHttpService, - IQService, - translate, - ILogService, - IFilterService, -} from 'angular'; +import { IHttpService, IQService, translate, ILogService, IFilterService } from 'angular'; const globalServices = new Map(); @@ -20,18 +14,9 @@ export function getService( angularServiceName: '$translate', ngOverride: { allowUnsafeAngularService: true } ): translate.ITranslateService; -export function getService( - angularServiceName: '$http', - ngOverride: { allowUnsafeAngularService: true } -): IHttpService; -export function getService( - angularServiceName: '$q', - ngOverride: { allowUnsafeAngularService: true } -): IQService; -export function getService( - angularServiceName: '$log', - ngOverride: { allowUnsafeAngularService: true } -): ILogService; +export function getService(angularServiceName: '$http', ngOverride: { allowUnsafeAngularService: true }): IHttpService; +export function getService(angularServiceName: '$q', ngOverride: { allowUnsafeAngularService: true }): IQService; +export function getService(angularServiceName: '$log', ngOverride: { allowUnsafeAngularService: true }): ILogService; export function getService( angularServiceName: '$filter', ngOverride: { allowUnsafeAngularService: true } @@ -41,10 +26,7 @@ export function getService(angularServiceName: '$http'): never; export function getService(angularServiceName: '$q'): never; export function getService(angularServiceName: '$log'): never; export function getService(angularServiceName: '$filter'): never; -export function getService( - name: ServiceName, - { allowUnsafeAngularService = false } = {} -): T { +export function getService(name: ServiceName, { allowUnsafeAngularService = false } = {}): T { if (name.startsWith('$') && !allowUnsafeAngularService) { throw Error( // eslint-disable-next-line max-len @@ -60,11 +42,7 @@ export function getService( } function findService(name: string) { - if ( - globalServices.has(name) || - typeof window === 'undefined' || - typeof window.angular === 'undefined' - ) { + if (globalServices.has(name) || typeof window === 'undefined' || typeof window.angular === 'undefined') { return globalServices.get(name); } return getAngularService(name); diff --git a/src/lib/custom-hooks/index.ts b/src/lib/custom-hooks/index.ts index 5c981c3..b890eb6 100644 --- a/src/lib/custom-hooks/index.ts +++ b/src/lib/custom-hooks/index.ts @@ -13,9 +13,6 @@ export const useService = ((...params: Parameters) => { * @see NgTranslate for a better way to do this. */ export function useTranslate() { - const $translate = useMemo( - () => getAngularService('$translate'), - [] - ); + const $translate = useMemo(() => getAngularService('$translate'), []); return (id: string, subs?: unknown) => $translate.instant(id, subs); } diff --git a/src/lib/jsx/NgTranslate.tsx b/src/lib/jsx/NgTranslate.tsx index 48e3dbe..de5890f 100644 --- a/src/lib/jsx/NgTranslate.tsx +++ b/src/lib/jsx/NgTranslate.tsx @@ -12,10 +12,7 @@ type Props = { * @returns */ const NgTranslate = ({ id, substitutions }: Props) => { - const $translate = useMemo( - () => getAngularService('$translate'), - [] - ); + const $translate = useMemo(() => getAngularService('$translate'), []); return <>{$translate.instant(id, substitutions)}; }; diff --git a/src/lib/wrappers/main.ts b/src/lib/wrappers/main.ts index c7cc845..91e32d6 100644 --- a/src/lib/wrappers/main.ts +++ b/src/lib/wrappers/main.ts @@ -2,14 +2,9 @@ import { IModule } from 'angular'; import * as React from 'react'; import { angularizeDirective, WrapperOptions } from './angularizeDirective'; -export function angularize( - reactElement: React.ElementType, - { - name, - module, - ...options - }: WrapperOptions & { name: string; module: IModule } -) { +type AngularizeOptions = WrapperOptions & WrapperOptions & { name: string; module: IModule }; + +export function angularize(reactElement: React.ElementType, { name, module, ...options }: AngularizeOptions) { angularizeDirective(reactElement, name, module, options); return module; }