Skip to content

chore: add prettier #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/prefer-literal-enum-member": "off",
"comma-dangle": [
"error",
"always-multiline"
]
"comma-dangle": ["error", "always-multiline"]
}
},
{
"files": "*.html",
"extends": [
"plugin:@angular-eslint/template/recommended"
],
"rules": {
}
"extends": ["plugin:@angular-eslint/template/recommended"],
"rules": {}
}
]
}
11 changes: 6 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
title: ""
labels: bug
assignees: json-derulo

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -21,9 +21,10 @@ Steps to reproduce the behavior:
A clear and concise description of what you expected to happen.

**Versions**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 1.0.0]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 1.0.0]

**Additional context**
Add any other context about the problem here.
7 changes: 3 additions & 4 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

title: ""
labels: ""
assignees: ""
---

**Description**
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Verify build

on:
pull_request_target:
types: [ opened, synchronize, reopened ]
types: [opened, synchronize, reopened]

jobs:
build:
Expand Down Expand Up @@ -46,3 +46,17 @@ jobs:

- name: test
run: npm run test -- --watch=false --browsers=ChromeHeadless

prettier:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: install
run: npm ci

- name: prettier
run: npx prettier . --check
4 changes: 1 addition & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846
"recommendations": [
"angular.ng-template"
]
"recommendations": ["angular.ng-template"]
}
170 changes: 83 additions & 87 deletions README.md

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
"builder": "@angular-devkit/build-angular:karma",
"options": {
"tsConfig": "projects/angular-ecmascript-intl/tsconfig.spec.json",
"polyfills": [
"zone.js",
"zone.js/testing"
]
"polyfills": ["zone.js", "zone.js/testing"]
}
}
}
Expand All @@ -53,9 +50,7 @@
"outputPath": "dist/angular-intl-demo",
"index": "projects/angular-intl-demo/src/index.html",
"main": "projects/angular-intl-demo/src/main.ts",
"polyfills": [
"zone.js"
],
"polyfills": ["zone.js"],
"tsConfig": "projects/angular-intl-demo/tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
Expand Down
34 changes: 25 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"watch": "ng build --watch --configuration development",
"test": "ng test --code-coverage=true",
"lint": "eslint --ignore-path=.gitignore .",
"release": "release-it"
"release": "release-it",
"prettier": "prettier . --write"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -54,6 +55,7 @@
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "~2.1.0",
"ng-packagr": "~16.1.0",
"prettier": "~3.0.0",
"typescript": "~5.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {InjectionToken} from "@angular/core";
import {IntlCountryPipeOptions} from "./intl-country.pipe";
import { InjectionToken } from '@angular/core';
import { IntlCountryPipeOptions } from './intl-country.pipe';

export const INTL_COUNTRY_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlCountryPipeOptions, 'locale'>>('IntlCountryPipeDefaultOptions');
export const INTL_COUNTRY_PIPE_DEFAULT_OPTIONS = new InjectionToken<
Omit<IntlCountryPipeOptions, 'locale'>
>('IntlCountryPipeDefaultOptions');
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {IntlCountryPipe} from './intl-country.pipe';
import {TestBed} from "@angular/core/testing";
import {INTL_LOCALES} from "../locale";
import {INTL_COUNTRY_PIPE_DEFAULT_OPTIONS} from "./intl-country-pipe-default-options";
import { IntlCountryPipe } from './intl-country.pipe';
import { TestBed } from '@angular/core/testing';
import { INTL_LOCALES } from '../locale';
import { INTL_COUNTRY_PIPE_DEFAULT_OPTIONS } from './intl-country-pipe-default-options';

describe('IntlCountryPipe', () => {
let testUnit: IntlCountryPipe;
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('IntlCountryPipe', () => {
});

it('should fall back to the browser default locale', () => {
TestBed.configureTestingModule({providers: [IntlCountryPipe]});
TestBed.configureTestingModule({ providers: [IntlCountryPipe] });

const result1 = TestBed.inject(IntlCountryPipe).transform('US');
const result2 = new IntlCountryPipe(navigator.language).transform('US');
Expand Down Expand Up @@ -86,7 +86,9 @@ describe('IntlCountryPipe', () => {
});
testUnit = TestBed.inject(IntlCountryPipe);

expect(testUnit.transform('DE', {type: 'language'})).toEqual('Deutschland');
expect(testUnit.transform('DE', { type: 'language' })).toEqual(
'Deutschland',
);
});
});

Expand All @@ -102,6 +104,8 @@ describe('IntlCountryPipe', () => {
});
testUnit = TestBed.inject(IntlCountryPipe);

expect(testUnit.transform('US', {locale: 'de-DE'})).toEqual('Vereinigte Staaten');
expect(testUnit.transform('US', { locale: 'de-DE' })).toEqual(
'Vereinigte Staaten',
);
});
});
Original file line number Diff line number Diff line change
@@ -1,36 +1,49 @@
import {Inject, Optional, Pipe, PipeTransform} from '@angular/core';
import {INTL_LOCALES} from "../locale";
import {INTL_COUNTRY_PIPE_DEFAULT_OPTIONS} from "./intl-country-pipe-default-options";
import {IntlPipeOptions} from "../intl-pipe-options";
import { Inject, Optional, Pipe, PipeTransform } from '@angular/core';
import { INTL_LOCALES } from '../locale';
import { INTL_COUNTRY_PIPE_DEFAULT_OPTIONS } from './intl-country-pipe-default-options';
import { IntlPipeOptions } from '../intl-pipe-options';

export type IntlCountryPipeOptions = Omit<Partial<Intl.DisplayNamesOptions>, 'languageDisplay'> & IntlPipeOptions;
export type IntlCountryPipeOptions = Omit<
Partial<Intl.DisplayNamesOptions>,
'languageDisplay'
> &
IntlPipeOptions;

@Pipe({
name: 'intlCountry',
standalone: true,
})
export class IntlCountryPipe implements PipeTransform {
constructor(
@Optional()
@Inject(INTL_LOCALES)
readonly locale?: string | string[] | null,
@Optional()
@Inject(INTL_COUNTRY_PIPE_DEFAULT_OPTIONS)
readonly defaultOptions?: Omit<IntlCountryPipeOptions, 'locale'> | null,
) {}

constructor(@Optional() @Inject(INTL_LOCALES) readonly locale?: string | string[] | null,
@Optional() @Inject(INTL_COUNTRY_PIPE_DEFAULT_OPTIONS) readonly defaultOptions?: Omit<IntlCountryPipeOptions, 'locale'> | null) {
}

transform(value: string | null | undefined, options?: IntlCountryPipeOptions): string | null {
transform(
value: string | null | undefined,
options?: IntlCountryPipeOptions,
): string | null {
if (!value) {
return null;
}

const {locale, ...intlOptions} = options ?? {};
const { locale, ...intlOptions } = options ?? {};

try {
return new Intl.DisplayNames(locale ?? this.locale ?? undefined, {
...this.defaultOptions, ...intlOptions,
type: 'region',
}).of(value) ?? null;
return (
new Intl.DisplayNames(locale ?? this.locale ?? undefined, {
...this.defaultOptions,
...intlOptions,
type: 'region',
}).of(value) ?? null
);
} catch (e) {
console.error('Error while transforming the country', e);
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {InjectionToken} from "@angular/core";
import {IntlCurrencyPipeOptions} from "./intl-currency.pipe";
import { InjectionToken } from '@angular/core';
import { IntlCurrencyPipeOptions } from './intl-currency.pipe';

export const INTL_CURRENCY_PIPE_DEFAULT_OPTIONS = new InjectionToken<Omit<IntlCurrencyPipeOptions, 'locale'>>('IntlCurrencyPipeDefaultOptions');
export const INTL_CURRENCY_PIPE_DEFAULT_OPTIONS = new InjectionToken<
Omit<IntlCurrencyPipeOptions, 'locale'>
>('IntlCurrencyPipeDefaultOptions');
Loading