Skip to content

Commit

Permalink
partial ts port
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Jan 7, 2023
1 parent 962e5d5 commit daeaf17
Show file tree
Hide file tree
Showing 25 changed files with 12,088 additions and 343 deletions.
163 changes: 163 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
module.exports = {
env: {
es6: true,
node: true
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
plugins: [],
ignorePatterns: ['**/doc', '**/build', 'admin/'],
reportUnusedDisableDirectives: true,
rules: {
/* pretier takes care of these two rules
indent: [
'error',
4,
{
SwitchCase: 1
}
],
'array-element-newline': [
'error',
{
ArrayExpression: 'consistent',
ArrayPattern: { minItems: 3 }
}
],*/
curly: 'error',
'brace-style': 'error',
'arrow-parens': ['error', 'as-needed'],
'no-console': 'off',
'no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrors: 'all' }],
'no-useless-escape': 'warn',
'no-constant-condition': 'off',
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }],
'no-var': 'error',
'prefer-const': 'error',
'no-throw-literal': 'error',
'prefer-promise-reject-errors': 'error',
'require-await': 'error',
'no-return-await': 'error',
eqeqeq: ['error', 'always'],
quotes: [
'error',
'single',
{
avoidEscape: true,
allowTemplateLiterals: true
}
],
semi: ['error', 'always'],
'comma-dangle': [
'error',
{
arrays: 'never',
objects: 'never',
imports: 'never',
exports: 'never',
functions: 'ignore'
}
],
'no-trailing-spaces': 'error',
'prettier/prettier': 'error',
'no-nested-ternary': 'off', // maybe turn this on later
'no-unneeded-ternary': 'error'
},
parserOptions: {
ecmaVersion: 2019
},
overrides: [
// we need ts parser for ts files
{
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2019,
sourceType: 'module',
project: './tsconfig.json'
},
files: ['**/*.ts', '**/*.tsx'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{
functions: false,
typedefs: false,
classes: false
}
],
'@typescript-eslint/no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
argsIgnorePattern: '^_'
}
],
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/no-non-null-assertion': 'off', // This is necessary for Map.has()/get()!
'@typescript-eslint/no-inferrable-types': [
'error',
{
ignoreProperties: true,
ignoreParameters: true
}
],
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': false,
'ts-ignore': true,
'ts-nocheck': true,
'ts-check': false
}
],
'@typescript-eslint/restrict-template-expressions': [
'error',
{
allowNumber: true,
allowBoolean: true,
// This is necessary to log errors
// TODO: Consider switching to false when we may annotate catch clauses
allowAny: true,
allowNullish: true
}
],
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: false
}
],
// We can turn this on from time to time but in general these rules
// make our lives harder instead of easier
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-call': 'off',

// Although this rule makes sense, it takes about a second to execute (and we don't need it)
'@typescript-eslint/no-implied-eval': 'off',

'@typescript-eslint/explicit-module-boundary-types': [
'warn',
{ allowArgumentsExplicitlyTypedAsAny: true }
],
'@typescript-eslint/no-this-alias': 'off',

// Prefer simple property access and declaration without quotes
'dot-notation': 'off',
'@typescript-eslint/dot-notation': [
'error',
{
allowPrivateClassPropertyAccess: true,
allowProtectedClassPropertyAccess: true
}
],
'quote-props': ['error', 'as-needed']
}
}
]
};
77 changes: 0 additions & 77 deletions .eslintrc.json

This file was deleted.

19 changes: 19 additions & 0 deletions build/lib/tools.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Tests whether the given variable is a real object and not an Array
* @param it The variable to test
*/
export declare function isObject(it: any): it is Record<string, any>;
/**
* Tests whether the given variable is really an Array
* @param it The variable to test
*/
export declare function isArray(it: any): it is any[];
/**
* Translates text using the Google Translate API
* @param text The text to translate
* @param targetLang The target languate
* @param yandex api key
*/
export declare function translateText(text: string, targetLang: string, yandex: string): Promise<void | string>;
export declare function translateYandex(text: string, targetLang: string, yandex: string): Promise<string>;
export declare function translateGoogle(text: string, targetLang: string): Promise<string>;
81 changes: 81 additions & 0 deletions build/lib/tools.js

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

1 change: 1 addition & 0 deletions build/lib/tools.js.map

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

45 changes: 45 additions & 0 deletions build/lib/upnp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Tries to read HTML page.
*
* @param link http link, like http://192.168.1.2:80/abc/de.xml
* @param timeout timeout in ms (default 500)
* @param callback return result
*/
export declare function httpGet(link: string, timeout: number, callback: (err: any, result: string | null, link?: string) => void): void;
/**
* Helper function scan UPnP devices.
*
* First of all it sends UDP Multicast to detect devices with defined ST to port 1900.
*
* The answer will be parsed in form:
* <pre><code>
* {
* "HTTP/1.1 200 OK": "",
* "CACHE-CONTROL": "max-age = 1800"
* "EXT:
* "LOCATION": "http://192.168.1.55:1400/xml/device_description.xml",
* "SERVER": "Linux UPnP/1.0 Sonos/34.16-37101 (ZP90)",
* "ST": "urn:schemas-upnp-org:device:ZonePlayer:1",
* "USN": "uuid:RINCON_000E58A0099A04567::urn:schemas-upnp-org:device:ZonePlayer:1",
* "X-RINCON-HOUSEHOLD": "Sonos_vCu667379mc1UczAwr12311234",
* "X-RINCON-BOOTSEQ": "82",
* "X-RINCON-WIFIMODE": "0",
* "X-RINCON-VARIANT": "0"
* }
* </code></pre>
* If readXml is enabled and result.LOCATION exists, so this location will be read and delivered as xmlData.
* You can call the function with object too
* <pre><code>
* ssdpScan({ip: '192.168.1.3', st: 'urn:dial-multiscreen-org:service:dial:1', readXml: true}, function (error, result, ip, xmlData) {
* if (result) console.log('Found UPnP device');
* });
* </code></pre>
*
* @alias ssdpScan
* @memberof tools
* @param text filter string like "urn:dial-multiscreen-org:service:dial:1"
* @param readXml if LOCATION xml should be read
* @param timeout timeout in ms (default 1000)
* @param callback return result
*/
export declare function ssdpScan(text: string, readXml: boolean, timeout: number, callback: (err: any, res: any, ip?: string, xmlData?: any) => void): void;
Loading

0 comments on commit daeaf17

Please sign in to comment.