Skip to content

Commit 0f7a343

Browse files
Merge pull request #25 from phrase/upgrade-deps-add-eslint-config
feat: add eslint-phrase-config ad upgrade-deps
2 parents e75035f + d23aff6 commit 0f7a343

11 files changed

+579
-714
lines changed

.eslintrc

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,62 +12,5 @@
1212
"project": "./tsconfig.json",
1313
"createDefaultProgram": true
1414
},
15-
"rules": {
16-
"@typescript-eslint/ban-types": [
17-
"error",
18-
{
19-
"types": {
20-
"Object": "Use {} instead",
21-
"String": {
22-
"message": "Use string instead",
23-
"fixWith": "string"
24-
}
25-
}
26-
}
27-
],
28-
"@typescript-eslint/class-name-casing": [
29-
"error"
30-
],
31-
"@typescript-eslint/explicit-member-accessibility": [
32-
"error",
33-
{
34-
"accessibility": "no-public"
35-
}
36-
],
37-
"func-call-spacing": "off",
38-
"@typescript-eslint/func-call-spacing": [
39-
"error"
40-
],
41-
"@typescript-eslint/indent": [
42-
"error",
43-
4
44-
],
45-
"@typescript-eslint/no-floating-promises": "error",
46-
"@typescript-eslint/no-unused-vars": [
47-
"error",
48-
{
49-
"vars": "all",
50-
"args": "none"
51-
}
52-
],
53-
"@typescript-eslint/no-use-before-define": [
54-
"error",
55-
{
56-
"functions": false,
57-
"classes": false
58-
}
59-
],
60-
"@typescript-eslint/no-var-requires": "warn",
61-
"semi": "off",
62-
"@typescript-eslint/semi": [
63-
"error"
64-
],
65-
"@typescript-eslint/type-annotation-spacing": [
66-
"error",
67-
{
68-
"before": false,
69-
"after": true
70-
}
71-
]
72-
}
15+
"extends": "eslint-config-phrase"
7316
}

dist/angular-phrase.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-phrase.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-phrase.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-phrase.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,29 @@
1616
"author": "Manuel Boy <support@phraseapp.com> (https://phraseapp.com)",
1717
"license": "MIT",
1818
"devDependencies": {
19-
"@types/angular": "^1.6.56",
19+
"@types/angular": "^1.7.2",
2020
"@types/angular-mocks": "^1.7.0",
21-
"@types/jasmine": "^3.4.3",
22-
"@typescript-eslint/eslint-plugin": "^2.3.3",
23-
"@typescript-eslint/parser": "^2.3.3",
21+
"@types/angular-translate": "^2.16.2",
22+
"@types/jasmine": "^3.5.11",
23+
"@typescript-eslint/eslint-plugin": "^3.6.1",
24+
"@typescript-eslint/parser": "^3.6.1",
2425
"angular": "^1.7.8",
25-
"angular-mocks": "^1.7.8",
26-
"angular-translate": "^2.18.1",
27-
"eslint": "^6.5.1",
28-
"karma": "^5.0.5",
29-
"karma-chrome-launcher": "^2.0.0",
26+
"angular-mocks": "^1.8.0",
27+
"angular-translate": "^2.18.3",
28+
"eslint": "^7.5.0",
29+
"eslint-config-phrase": "git+https://github.com/phrase/eslint-config-phrase.git#v2",
30+
"karma": "^5.1.0",
31+
"karma-chrome-launcher": "^3.1.0",
3032
"karma-firefox-launcher": "^1.2.0",
31-
"karma-jasmine": "^3.1.1",
33+
"karma-jasmine": "^3.3.1",
3234
"karma-spec-reporter": "^0.0.32",
3335
"karma-webpack": "^4.0.2",
34-
"source-map-loader": "^0.2.4",
35-
"terser-webpack-plugin": "^2.3.0",
36-
"ts-loader": "^7.0.4",
37-
"typescript": "^3.6.4",
36+
"source-map-loader": "^1.0.1",
37+
"terser-webpack-plugin": "^3.0.7",
38+
"ts-loader": "^8.0.1",
39+
"typescript": "^3.9.7",
3840
"webpack": "^4.41.3",
39-
"webpack-cli": "^3.3.10"
41+
"webpack-cli": "^3.3.12"
4042
},
4143
"files": [
4244
"dist",

src/angular-phrase.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ declare global {
22
const angular: ng.IAngularStatic;
33
}
44
import DataUtils from "./data-utils";
5-
65
const phrase = angular.module("phrase", ['pascalprecht.translate', 'ng']);
76

7+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
8+
interface ITranslateServiceExtend extends angular.translate.ITranslateService {
9+
_instant: angular.translate.ITranslateService['instant']
10+
}
11+
812
phrase.value("phraseProjectId", "");
913
phrase.value("phraseEnabled", true);
1014
phrase.value("phraseDecoratorPrefix", "{{__");
@@ -13,10 +17,19 @@ phrase.value("phraseAutoLowercase", true);
1317

1418
phrase.config(["$provide", ($provide: angular.auto.IProvideService) => {
1519
return $provide.decorator("$translate", ["$delegate", "phraseEnabled", "phraseDecoratorPrefix", "phraseDecoratorSuffix",
16-
($translate: any, phraseEnabled: boolean, phraseDecoratorPrefix: string, phraseDecoratorSuffix: string) => {
20+
($translate: ITranslateServiceExtend, phraseEnabled: boolean, phraseDecoratorPrefix: string, phraseDecoratorSuffix: string) => {
1721
if (phraseEnabled) {
1822
$translate._instant = $translate.instant;
19-
$translate.instant = translationId => `${phraseDecoratorPrefix}phrase_${translationId + phraseDecoratorSuffix}`;
23+
$translate.instant = (translationId: string | string[]): any => {
24+
if (typeof translationId === "object") {
25+
return translationId.reduce<Record<string, string>>((prev, curr: string) => {
26+
prev[curr] = `${phraseDecoratorPrefix}phrase_${curr as string}${phraseDecoratorSuffix}`;
27+
return prev;
28+
}, {});
29+
}
30+
31+
return `${phraseDecoratorPrefix}phrase_${translationId as string}${phraseDecoratorSuffix}`;
32+
};
2033
}
2134
return $translate;
2235
}]);
@@ -36,7 +49,7 @@ phrase.config(["$compileProvider", ($compileProvider: angular.ICompileProvider)
3649
compile: (elem, attr) => {
3750
let translationId: string;
3851
if (elem.attr("translate") != undefined) {
39-
if (elem.attr("translate") !== ""){
52+
if (elem.attr("translate") !== "") {
4053
translationId = elem.attr("translate");
4154
} else {
4255
translationId = elem.text();
@@ -46,7 +59,7 @@ phrase.config(["$compileProvider", ($compileProvider: angular.ICompileProvider)
4659
if (translationId) {
4760
let decoratedTranslationId = `${phraseDecoratorPrefix}phrase_${translationId + phraseDecoratorSuffix}`;
4861
if (attr.translateValues) {
49-
decoratedTranslationId = `${decoratedTranslationId} (${attr.translateValues})`;
62+
decoratedTranslationId = `${decoratedTranslationId} (${(attr.translateValues as string)})`;
5063
}
5164
elem.html(decoratedTranslationId);
5265
elem.removeAttr("translate");
@@ -57,13 +70,13 @@ phrase.config(["$compileProvider", ($compileProvider: angular.ICompileProvider)
5770
}]);
5871

5972
phrase.directive("phraseJavascript", ["phraseEnabled", "phraseProjectId", "phraseAutoLowercase", "$window",
60-
(phraseEnabled: boolean, phraseProjectId: string, phraseAutoLowercase: boolean, $window: any) => {
73+
(phraseEnabled: boolean, phraseProjectId: string, phraseAutoLowercase: boolean, $window: Window) => {
6174
return {
6275
restrict: "EA",
6376
replace: true,
6477
link: (): void => {
6578
if (phraseEnabled) {
66-
let url = `https://phraseapp.com/assets/in-context-editor/2.0/app.js?${new Date().getTime()}`;
79+
const url = `https://phraseapp.com/assets/in-context-editor/2.0/app.js?${new Date().getTime()}`;
6780
$window.PHRASEAPP_CONFIG = {
6881
projectId: phraseProjectId,
6982
autoLowercase: phraseAutoLowercase,

src/data-utils.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
export default class DataUtils {
2-
static getScript(source: string, callback?: Function): void {
3-
let script = document.createElement('script') as any;
2+
static getScript(source: string): void {
3+
const script = document.createElement('script');
44
const prior = document.getElementsByTagName('script')[0];
55
script.async = true;
66

7-
script.onload = script.onreadystatechange = function( _, isAbort ) {
8-
if(isAbort || !(script as XMLHttpRequest).readyState || /loaded|complete/.test(script.readyState) ) {
9-
script.onload = script.onreadystatechange = null;
10-
script = undefined;
11-
12-
if(!isAbort && callback) setTimeout(callback, 0);
13-
}
14-
};
15-
167
script.src = source;
178
prior.parentNode.insertBefore(script, prior);
189
}

tsconfig.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@
2222
"exclude": [
2323
"node_modules"
2424
],
25-
"include": [
26-
"src"
27-
]
25+
"include": ["src/**/*", "typings.d.ts"]
2826
}

typings.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface Window {
2+
PHRASEAPP_CONFIG: Record<string, unknown>
3+
}

0 commit comments

Comments
 (0)