mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-14 10:55:11 +00:00
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
02a8174509
|
|||
ac570459a3
|
|||
093df107d2 | |||
d166e0f5cf | |||
ef102dc433 | |||
324be2a410 | |||
ad4ad553a4 | |||
7c253c98d7 | |||
e172465258
|
|||
9940961e20
|
|||
f25be8b5f5
|
|||
641f7861b8 | |||
3db69e0537 | |||
1c36d6b93e | |||
10083223e2
|
|||
4435f930ec |
@ -5,4 +5,8 @@ indent_style = tab
|
|||||||
indent_size = 4
|
indent_size = 4
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.yml]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
325
.eslintrc.js
325
.eslintrc.js
@ -1,322 +1,5 @@
|
|||||||
/**
|
module.exports = {
|
||||||
* ESLint custom configuration v1.0.0
|
|
||||||
* packages needed:
|
|
||||||
* eslint
|
|
||||||
* for Typescript
|
|
||||||
* @typescript-eslint/parser
|
|
||||||
* @typescript-eslint/eslint-plugin
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
env: {
|
|
||||||
browser: true,
|
|
||||||
es6: true,
|
|
||||||
node: true
|
|
||||||
},
|
|
||||||
extends: [
|
extends: [
|
||||||
"eslint:all",
|
"./node_modules/@dzeio/config/eslint/typescript"
|
||||||
"plugin:@typescript-eslint/recommended",
|
]
|
||||||
],
|
}
|
||||||
globals: {
|
|
||||||
Atomics: "readonly",
|
|
||||||
SharedArrayBuffer: "readonly"
|
|
||||||
},
|
|
||||||
parser: "@typescript-eslint/parser",
|
|
||||||
parserOptions: {
|
|
||||||
project: "tsconfig.json"
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
"@typescript-eslint"
|
|
||||||
],
|
|
||||||
root: true,
|
|
||||||
rules: {
|
|
||||||
// Tab indent and force switch to have one too
|
|
||||||
indent: [
|
|
||||||
"error",
|
|
||||||
"tab",
|
|
||||||
{SwitchCase: 1}
|
|
||||||
],
|
|
||||||
|
|
||||||
// \n linebreak
|
|
||||||
"linebreak-style": [
|
|
||||||
"error",
|
|
||||||
"unix"
|
|
||||||
],
|
|
||||||
|
|
||||||
// Disable eslint default quote because Typescript replace it
|
|
||||||
quotes: "off",
|
|
||||||
"@typescript-eslint/quotes": [
|
|
||||||
"error",
|
|
||||||
"single",
|
|
||||||
{ avoidEscape: true }
|
|
||||||
],
|
|
||||||
|
|
||||||
// Simply diallow using ';' unless mandatory
|
|
||||||
semi: "off",
|
|
||||||
"@typescript-eslint/semi": [
|
|
||||||
"error",
|
|
||||||
"never",
|
|
||||||
{ "beforeStatementContinuationChars": "always"}
|
|
||||||
],
|
|
||||||
|
|
||||||
// Disallow things that do nothing in the end
|
|
||||||
"no-unused-expressions": "off",
|
|
||||||
"@typescript-eslint/no-unused-expressions": [
|
|
||||||
"error",
|
|
||||||
{ "enforceForJSX": true,}
|
|
||||||
],
|
|
||||||
|
|
||||||
// force overloads to be next to one another
|
|
||||||
"@typescript-eslint/adjacent-overload-signatures": "error",
|
|
||||||
|
|
||||||
// Force to use `Array<thing>
|
|
||||||
"@typescript-eslint/array-type": [
|
|
||||||
"error",
|
|
||||||
{ default: 'generic' }
|
|
||||||
],
|
|
||||||
|
|
||||||
// Warn when no return type is specified
|
|
||||||
"@typescript-eslint/explicit-module-boundary-types": "warn",
|
|
||||||
|
|
||||||
// disallow certain types not safe
|
|
||||||
"@typescript-eslint/ban-types": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"types": {
|
|
||||||
"{}": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@typescript-eslint/consistent-type-assertions": "error",
|
|
||||||
"@typescript-eslint/consistent-type-definitions": "error",
|
|
||||||
"@typescript-eslint/explicit-member-accessibility": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
accessibility: "explicit"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@typescript-eslint/interface-name-prefix": "off",
|
|
||||||
"@typescript-eslint/member-delimiter-style": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
multiline: {
|
|
||||||
delimiter: "none",
|
|
||||||
requireLast: true
|
|
||||||
},
|
|
||||||
singleline: {
|
|
||||||
delimiter: "comma",
|
|
||||||
requireLast: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@typescript-eslint/member-ordering": "error",
|
|
||||||
"@typescript-eslint/no-empty-function": "error",
|
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
|
||||||
"@typescript-eslint/no-misused-new": "error",
|
|
||||||
"@typescript-eslint/no-namespace": "error",
|
|
||||||
"@typescript-eslint/no-parameter-properties": "off",
|
|
||||||
"@typescript-eslint/no-use-before-define": "off",
|
|
||||||
"@typescript-eslint/prefer-for-of": "error",
|
|
||||||
"@typescript-eslint/prefer-function-type": "error",
|
|
||||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
|
||||||
|
|
||||||
"@typescript-eslint/triple-slash-reference": "error",
|
|
||||||
"@typescript-eslint/type-annotation-spacing": "error",
|
|
||||||
"@typescript-eslint/unified-signatures": "error",
|
|
||||||
"arrow-body-style": "error",
|
|
||||||
"arrow-parens": [
|
|
||||||
"error",
|
|
||||||
"always"
|
|
||||||
],
|
|
||||||
|
|
||||||
camelcase: "error",
|
|
||||||
complexity: "off",
|
|
||||||
"constructor-super": "error",
|
|
||||||
curly: "error",
|
|
||||||
"dot-notation": "error",
|
|
||||||
"eol-last": "error",
|
|
||||||
eqeqeq: [
|
|
||||||
"error",
|
|
||||||
"smart"
|
|
||||||
],
|
|
||||||
"guard-for-in": "warn",
|
|
||||||
"id-blacklist": [
|
|
||||||
"error",
|
|
||||||
"any",
|
|
||||||
"Number",
|
|
||||||
"number",
|
|
||||||
"String",
|
|
||||||
"string",
|
|
||||||
"Boolean",
|
|
||||||
"boolean",
|
|
||||||
"Undefined"
|
|
||||||
],
|
|
||||||
"id-match": "error",
|
|
||||||
"max-classes-per-file": [
|
|
||||||
"error",
|
|
||||||
1
|
|
||||||
],
|
|
||||||
"max-len": [
|
|
||||||
"warn",
|
|
||||||
{
|
|
||||||
code: 200
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@typescript-eslint/no-inferrable-types": "off",
|
|
||||||
"new-parens": "error",
|
|
||||||
"no-bitwise": "error",
|
|
||||||
"no-caller": "error",
|
|
||||||
"no-cond-assign": "error",
|
|
||||||
"no-debugger": "error",
|
|
||||||
"no-empty": "error",
|
|
||||||
"no-eval": "error",
|
|
||||||
"no-fallthrough": "off",
|
|
||||||
"no-invalid-this": "off",
|
|
||||||
"no-multiple-empty-lines": "error",
|
|
||||||
"no-new-wrappers": "error",
|
|
||||||
"no-shadow": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
hoist: "all"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"no-throw-literal": "error",
|
|
||||||
"no-trailing-spaces": "error",
|
|
||||||
"no-undef-init": "error",
|
|
||||||
"no-underscore-dangle": "error",
|
|
||||||
"no-unsafe-finally": "error",
|
|
||||||
"no-unused-labels": "error",
|
|
||||||
"no-unused-vars": "off",
|
|
||||||
"no-var": "error",
|
|
||||||
"object-shorthand": "error",
|
|
||||||
"one-var": [
|
|
||||||
"error",
|
|
||||||
"never"
|
|
||||||
],
|
|
||||||
"prefer-const": "error",
|
|
||||||
"quote-props": [
|
|
||||||
"error",
|
|
||||||
"consistent-as-needed"
|
|
||||||
],
|
|
||||||
"radix": "error",
|
|
||||||
|
|
||||||
"space-before-function-paren": "off",
|
|
||||||
"@typescript-eslint/space-before-function-paren": ["error", {
|
|
||||||
asyncArrow: "always",
|
|
||||||
anonymous: "never",
|
|
||||||
named: "never"
|
|
||||||
}],
|
|
||||||
"spaced-comment": "error",
|
|
||||||
"use-isnan": "error",
|
|
||||||
"valid-typeof": "off",
|
|
||||||
|
|
||||||
// some tests from eslint:all
|
|
||||||
"no-tabs": "off",
|
|
||||||
"padded-blocks": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"blocks": "never",
|
|
||||||
"classes": "always",
|
|
||||||
"switches": "never"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"sort-imports": "off",
|
|
||||||
"no-console": "off",
|
|
||||||
"function-call-argument-newline": [
|
|
||||||
"error",
|
|
||||||
"consistent"
|
|
||||||
],
|
|
||||||
"dot-location": [
|
|
||||||
"error",
|
|
||||||
"property"
|
|
||||||
],
|
|
||||||
"object-curly-spacing": [
|
|
||||||
"error",
|
|
||||||
"always"
|
|
||||||
],
|
|
||||||
"array-element-newline": [
|
|
||||||
"error",
|
|
||||||
"consistent"
|
|
||||||
],
|
|
||||||
"function-paren-newline": [
|
|
||||||
"error",
|
|
||||||
"consistent"
|
|
||||||
],
|
|
||||||
"no-use-before-define": "off",
|
|
||||||
"@typescript-eslint/no-use-before-define": "error",
|
|
||||||
"capitalized-comments": "off",
|
|
||||||
"multiline-comment-style": "off",
|
|
||||||
"no-extra-parens": "off",
|
|
||||||
"@typescript-eslint/no-extra-parens": [
|
|
||||||
"error",
|
|
||||||
"all",
|
|
||||||
{ "ignoreJSX": "multi-line" }
|
|
||||||
],
|
|
||||||
"func-style": [
|
|
||||||
"error",
|
|
||||||
"declaration",
|
|
||||||
{ "allowArrowFunctions": true }
|
|
||||||
],
|
|
||||||
"no-ternary": "off",
|
|
||||||
"multiline-ternary": "off",
|
|
||||||
"no-magic-numbers": "off",
|
|
||||||
"max-lines-per-function": [
|
|
||||||
"warn",
|
|
||||||
{
|
|
||||||
"skipBlankLines": true,
|
|
||||||
"skipComments": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"prefer-promise-reject-errors": "warn",
|
|
||||||
"object-property-newline": [
|
|
||||||
"error",
|
|
||||||
{ "allowAllPropertiesOnSameLine": true }
|
|
||||||
],
|
|
||||||
"no-await-in-loop": "warn",
|
|
||||||
"no-undefined": "off",
|
|
||||||
"id-length": "warn",
|
|
||||||
"class-methods-use-this": "off",
|
|
||||||
"array-bracket-newline": [
|
|
||||||
"error",
|
|
||||||
"consistent"
|
|
||||||
],
|
|
||||||
"no-confusing-arrow": "off",
|
|
||||||
"no-nested-ternary": "off",
|
|
||||||
"no-mixed-operators": "off",
|
|
||||||
"max-statements": [
|
|
||||||
"warn",
|
|
||||||
15
|
|
||||||
],
|
|
||||||
"semi-style": [
|
|
||||||
"error",
|
|
||||||
"first"
|
|
||||||
],
|
|
||||||
"no-useless-constructor": "off",
|
|
||||||
"@typescript-eslint/no-useless-constructor": "error",
|
|
||||||
"lines-between-class-members": "off",
|
|
||||||
"@typescript-eslint/lines-between-class-members": "error",
|
|
||||||
"max-lines": [
|
|
||||||
"warn",
|
|
||||||
{
|
|
||||||
"max": 500,
|
|
||||||
"skipBlankLines": true,
|
|
||||||
"skipComments": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"no-plusplus": "off",
|
|
||||||
"id-length": [
|
|
||||||
"warn",
|
|
||||||
{ "exceptions": ["_"] }
|
|
||||||
],
|
|
||||||
"default-param-last": "off",
|
|
||||||
// "@typescript-eslint/default-param-last": "error",
|
|
||||||
// Temporary OFF
|
|
||||||
"@typescript-eslint/default-param-last": "off",
|
|
||||||
"no-continue": "off",
|
|
||||||
"require-atomic-updates": "off",
|
|
||||||
"require-await": "off",
|
|
||||||
"prefer-destructuring": "off",
|
|
||||||
"max-params": ["warn", 5]
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
* text=auto eol=lf
|
35
.github/workflows/build.yml
vendored
35
.github/workflows/build.yml
vendored
@ -1,6 +1,3 @@
|
|||||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
||||||
|
|
||||||
name: Build & Test
|
name: Build & Test
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -18,30 +15,30 @@ jobs:
|
|||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
# Follow current releases https://nodejs.org/en/about/releases/
|
||||||
node-version: [12.x, 14.x, 16.x]
|
node-version: [12.x, 14.x, 16.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: yarn
|
|
||||||
- run: yarn build
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
- name: Install dependencies
|
||||||
- uses: actions/checkout@v2
|
run: npm ci
|
||||||
- name: Use Node.js 12.x
|
|
||||||
uses: actions/setup-node@v1
|
- name: Build
|
||||||
with:
|
run: npm run build
|
||||||
node-version: 12.x
|
|
||||||
- run: yarn && yarn build
|
- name: Test
|
||||||
- run: yarn test
|
run: npm run test
|
||||||
# You may pin to the exact commit or the version.
|
|
||||||
# uses: codecov/codecov-action@6004246f47ab62d32be025ce173b241cd84ac58e
|
- name: Upload Coverage
|
||||||
- uses: codecov/codecov-action@v1.0.13
|
if: matrix.node-version == '16.x'
|
||||||
|
uses: codecov/codecov-action@v1.0.13
|
||||||
with:
|
with:
|
||||||
# Comma-separated list of files to upload
|
# Comma-separated list of files to upload
|
||||||
files: ./coverage/coverage-final.json
|
files: ./coverage/coverage-final.json
|
||||||
|
13
.github/workflows/code-quality.yml
vendored
13
.github/workflows/code-quality.yml
vendored
@ -1,6 +1,3 @@
|
|||||||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
||||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
||||||
|
|
||||||
name: Code Quality Checks
|
name: Code Quality Checks
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -14,14 +11,16 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Checkout
|
||||||
with:
|
uses: actions/checkout@v2
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- name: Setup NodeJS
|
- name: Setup NodeJS
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: '16.x'
|
node-version: '16.x'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: yarn && yarn lint
|
run: npm run lint
|
||||||
|
28
.github/workflows/publish.yml
vendored
Normal file
28
.github/workflows/publish.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
name: publish
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v[0-9]+.[0-9]+.[0-9]+*'
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup NodeJS
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16.x'
|
||||||
|
registry-url: 'https://registry.npmjs.org'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Publish
|
||||||
|
run: npm publish
|
||||||
|
env:
|
||||||
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
34
CHANGELOG.md
34
CHANGELOG.md
@ -7,6 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## 2.4.3 - 2021-07-19
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- ESM exports are back
|
||||||
|
|
||||||
|
## 2.4.2 2021-07-11
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Downgraded to ES2015 to have better suport browsers
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Moved browser export from `Webpack` to `esbuild`
|
||||||
|
|
||||||
|
## 2.4.1 - 2021-07-11
|
||||||
|
|
||||||
|
## Deprecated
|
||||||
|
|
||||||
|
- Deprecated `Languages` Type
|
||||||
|
|
||||||
|
## 2.4.0 - 2021-06-29
|
||||||
|
|
||||||
|
## Added
|
||||||
|
|
||||||
|
- Support for new languages
|
||||||
|
|
||||||
## 2.3.1 - 2021-06-22
|
## 2.3.1 - 2021-06-22
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
@ -199,8 +227,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Constructor arg support for multiple langs
|
- Constructor arg support for multiple langs
|
||||||
- TranslationUtil to go from the SDK value to a text value
|
- TranslationUtil to go from the SDK value to a text value
|
||||||
|
|
||||||
[Unreleased]: https://github.com/tcgdex/javascript-sdk/compare/v2.3.1...HEAD
|
[Unreleased]: https://github.com/tcgdex/javascript-sdk/compare/v2.4.3...HEAD
|
||||||
|
|
||||||
|
[2.4.3]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.4.3
|
||||||
|
[2.4.2]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.4.2
|
||||||
|
[2.4.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.4.1
|
||||||
|
[2.4.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.4.0
|
||||||
[2.3.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.3.1
|
[2.3.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.3.1
|
||||||
[2.3.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.3.0
|
[2.3.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.3.0
|
||||||
[2.2.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.2.0
|
[2.2.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.2.0
|
||||||
|
14
README.md
14
README.md
@ -8,13 +8,15 @@
|
|||||||
<a href="https://app.codecov.io/gh/tcgdex/javascript-sdk/">
|
<a href="https://app.codecov.io/gh/tcgdex/javascript-sdk/">
|
||||||
<img src="https://img.shields.io/codecov/c/github/tcgdex/javascript-sdk?style=flat-square&token=FR4BI94N4Q" alt="npm version">
|
<img src="https://img.shields.io/codecov/c/github/tcgdex/javascript-sdk?style=flat-square&token=FR4BI94N4Q" alt="npm version">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md">
|
<a href="https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md">
|
||||||
<img src="https://img.shields.io/github/license/tcgdex/javascript-sdk?style=flat-square" alt="the TCGdex JAvascript SDK is released under the MIT license." />
|
<img src="https://img.shields.io/github/license/tcgdex/javascript-sdk?style=flat-square" alt="the TCGdex JAvascript SDK is released under the MIT license." />
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md">
|
<a href="https://github.com/tcgdex/javascript-sdk/actions/workflows/build.yml">
|
||||||
<img src="https://img.shields.io/github/workflow/status/tcgdex/javascript-sdk/Build%20&%20Test?style=flat-square" alt="the TCGdex JAvascript SDK is released under the MIT license." />
|
<img src="https://img.shields.io/github/workflow/status/tcgdex/javascript-sdk/Build%20&%20Test?style=flat-square" alt="the TCGdex JAvascript SDK is released under the MIT license." />
|
||||||
</a>
|
</a>
|
||||||
|
<a href="https://discord.gg/NehYTAhsZE">
|
||||||
|
<img src="https://img.shields.io/discord/857231041261076491?color=%235865F2&label=Discord&style=flat-square" alt="Discord Link">
|
||||||
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# TCGdex JavaScript/TypeScript SDK
|
# TCGdex JavaScript/TypeScript SDK
|
||||||
@ -32,11 +34,17 @@ yarn add @tcgdex/sdk
|
|||||||
npm install @tcgdex/sdk
|
npm install @tcgdex/sdk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or in the web browser
|
||||||
|
```html
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2/dist/tcgdex.browser.js"></script>
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
_Note: a complete documentation is in progress_
|
_Note: a complete documentation is in progress_
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
// only if using with NPM/Yarn
|
||||||
import TCGdex from '@tcgdex/sdk'
|
import TCGdex from '@tcgdex/sdk'
|
||||||
|
|
||||||
// initialize the SDK
|
// initialize the SDK
|
||||||
|
6746
package-lock.json
generated
6746
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
117
package.json
117
package.json
@ -1,58 +1,59 @@
|
|||||||
{
|
{
|
||||||
"name": "@tcgdex/sdk",
|
"name": "@tcgdex/sdk",
|
||||||
"version": "2.4.0",
|
"version": "2.4.4",
|
||||||
"main": "./dist/cjs/tcgdex.node.js",
|
"main": "./dist/cjs/tcgdex.node.js",
|
||||||
"types": "./dist/types/tcgdex.d.ts",
|
"module": "./dist/modules/tcgdex.node.js",
|
||||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
"types": "./dist/types/tcgdex.d.ts",
|
||||||
"homepage": "https://github.com/tcgdex/javascript-sdk",
|
"description": "Communicate with the Open Source TCGdex API in Javascript/Typescript using the SDK",
|
||||||
"author": "Aviortheking",
|
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||||
"keywords": [
|
"homepage": "https://github.com/tcgdex/javascript-sdk",
|
||||||
"tcgdex",
|
"author": "Aviortheking",
|
||||||
"pokemon",
|
"keywords": [
|
||||||
"trading",
|
"tcgdex",
|
||||||
"card",
|
"pokemon",
|
||||||
"tcg",
|
"trading",
|
||||||
"sdk",
|
"card",
|
||||||
"api",
|
"tcg",
|
||||||
"typescript",
|
"sdk",
|
||||||
"javascript",
|
"api",
|
||||||
"typing"
|
"typescript",
|
||||||
],
|
"javascript",
|
||||||
"license": "MIT",
|
"typing"
|
||||||
"devDependencies": {
|
],
|
||||||
"@babel/core": "^7.14.6",
|
"license": "MIT",
|
||||||
"@babel/preset-env": "^7.14.7",
|
"devDependencies": {
|
||||||
"@babel/preset-typescript": "^7.14.5",
|
"@babel/core": "^7.14.6",
|
||||||
"@types/node-fetch": "^2.5.10",
|
"@babel/preset-env": "^7.14.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
"@babel/preset-typescript": "^7.14.5",
|
||||||
"@typescript-eslint/parser": "^4.28.0",
|
"@dzeio/config": "^1.0.0",
|
||||||
"eslint": "^7.29.0",
|
"@types/node-fetch": "^2.5.10",
|
||||||
"jest": "^27.0.5",
|
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||||
"ts-loader": "^9.2.3",
|
"@typescript-eslint/parser": "^4.28.0",
|
||||||
"ts-node": "^10.0.0",
|
"esbuild": "^0.12.15",
|
||||||
"typescript": "^4.1.3",
|
"eslint": "^7.29.0",
|
||||||
"webpack": "^5.40.0",
|
"jest": "^27.0.5",
|
||||||
"webpack-nano": "^1.1.1"
|
"ts-node": "^10.0.0",
|
||||||
},
|
"typescript": "^4.1.3"
|
||||||
"engines": {
|
},
|
||||||
"node": ">=12"
|
"engines": {
|
||||||
},
|
"node": ">=12"
|
||||||
"dependencies": {
|
},
|
||||||
"isomorphic-unfetch": "^3.1.0",
|
"dependencies": {
|
||||||
"unfetch": "^4.2.0"
|
"isomorphic-unfetch": "^3.1.0",
|
||||||
},
|
"unfetch": "^4.2.0"
|
||||||
"scripts": {
|
},
|
||||||
"prebuild": "node scripts/export-version-number.js",
|
"scripts": {
|
||||||
"build": "npm run prebuild && npm run build:cjs && npm run build:browser && npm run build:es2015",
|
"prebuild": "node scripts/export-version-number.js",
|
||||||
"build:cjs": "tsc --project tsconfig.json",
|
"build": "npm run prebuild && npm run build:cjs && npm run build:browser && npm run build:es2015",
|
||||||
"build:es2015": "tsc --project tsconfig.es2015.json",
|
"build:cjs": "tsc --project tsconfig.json",
|
||||||
"build:browser": "wp --config webpack.config.js",
|
"build:es2015": "tsc --project tsconfig.es2015.json",
|
||||||
"prepublishOnly": "npm run build",
|
"build:browser": "esbuild ./src/tcgdex.browser.ts --bundle --minify --sourcemap --target=es2016,chrome90,firefox78,safari14,ios13,edge90 --outfile=dist/tcgdex.browser.js",
|
||||||
"lint": "eslint",
|
"prepublishOnly": "npm run build",
|
||||||
"test": "jest --coverage"
|
"lint": "eslint",
|
||||||
},
|
"test": "jest --coverage"
|
||||||
"files": [
|
},
|
||||||
"dist"
|
"files": [
|
||||||
],
|
"dist"
|
||||||
"sideEffects": false
|
],
|
||||||
}
|
"sideEffects": false
|
||||||
|
}
|
||||||
|
@ -1,31 +1,31 @@
|
|||||||
import TCGdex from './tcgdex'
|
import TCGdex from './tcgdex'
|
||||||
import { version } from './version.json'
|
import { version } from './version.json'
|
||||||
|
|
||||||
export default class Request {
|
export default class Request {
|
||||||
|
|
||||||
// 1 hour of TTL by default
|
// 1 hour of TTL by default
|
||||||
public static ttl = 1000 * 60 * 60
|
public static ttl = 1000 * 60 * 60
|
||||||
|
|
||||||
private static cache: Record<string, {response: any, time: number}> = {}
|
private static cache: Record<string, {response: any, time: number}> = {}
|
||||||
|
|
||||||
public static async fetch<T>(url: string): Promise<T | undefined> {
|
public static async fetch<T>(url: string): Promise<T | undefined> {
|
||||||
let request = this.cache[url]
|
let request = this.cache[url]
|
||||||
const now = new Date().getTime()
|
const now = new Date().getTime()
|
||||||
if (!request || now - request.time > this.ttl) {
|
if (!request || now - request.time > this.ttl) {
|
||||||
const unfetch = TCGdex.fetch
|
const unfetch = TCGdex.fetch
|
||||||
const resp = await unfetch(url, {
|
const resp = await unfetch(url, {
|
||||||
headers: {
|
headers: {
|
||||||
'user-agent': `@tcgdex/javascript-sdk/${version}`
|
'user-agent': `@tcgdex/javascript-sdk/${version}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cache[url] = { response: await resp.json(), time: now }
|
this.cache[url] = { response: await resp.json(), time: now }
|
||||||
request = this.cache[url]
|
request = this.cache[url]
|
||||||
}
|
}
|
||||||
return request.response
|
return request.response
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
export type SupportedLanguages = 'en' | 'fr' | 'es' | 'it' | 'pt' | 'de'
|
export type SupportedLanguages = 'en' | 'fr' | 'es' | 'it' | 'pt' | 'de'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated This is not used anymore in the API V2
|
||||||
|
*/
|
||||||
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
|
export type Languages<T = string> = Partial<Record<SupportedLanguages, T>>
|
||||||
|
|
||||||
export interface SerieResume {
|
export interface SerieResume {
|
||||||
id: string
|
id: string
|
||||||
name: string
|
name: string
|
||||||
|
logo?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Serie extends SerieResume {
|
export interface Serie extends SerieResume {
|
||||||
|
@ -3,4 +3,4 @@ import unfetch from 'unfetch'
|
|||||||
|
|
||||||
TCGdex.fetch = window.fetch ?? unfetch as any
|
TCGdex.fetch = window.fetch ?? unfetch as any
|
||||||
|
|
||||||
module.exports = TCGdex
|
(global ?? window).TCGdex = TCGdex
|
||||||
|
370
src/tcgdex.ts
370
src/tcgdex.ts
@ -1,185 +1,185 @@
|
|||||||
import RequestWrapper from './Request'
|
import RequestWrapper from './Request'
|
||||||
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
|
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
|
||||||
type Endpoint = 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
type Endpoint = 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
||||||
|
|
||||||
const ENDPOINTS: Array<Endpoint> = ['cards', 'categories', 'hp', 'illustrators', 'rarities', 'retreats', 'series', 'sets', 'types']
|
const ENDPOINTS: Array<Endpoint> = ['cards', 'categories', 'hp', 'illustrators', 'rarities', 'retreats', 'series', 'sets', 'types']
|
||||||
const BASE_URL = 'https://api.tcgdex.net/v2'
|
const BASE_URL = 'https://api.tcgdex.net/v2'
|
||||||
export default class TCGdex {
|
export default class TCGdex {
|
||||||
|
|
||||||
public static fetch: typeof fetch
|
public static fetch: typeof fetch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated to change the lang use `this.lang`
|
* @deprecated to change the lang use `this.lang`
|
||||||
*/
|
*/
|
||||||
public static defaultLang: SupportedLanguages = 'en'
|
public static defaultLang: SupportedLanguages = 'en'
|
||||||
|
|
||||||
public constructor(public lang?: SupportedLanguages) {}
|
public constructor(public lang?: SupportedLanguages) {}
|
||||||
|
|
||||||
public getLang(): SupportedLanguages {
|
public getLang(): SupportedLanguages {
|
||||||
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut to easily fetch a card using both it's global id and it's local ID
|
* Shortcut to easily fetch a card using both it's global id and it's local ID
|
||||||
* @param id the card global/local ID
|
* @param id the card global/local ID
|
||||||
* @param set the card set name/ID (optionnal)
|
* @param set the card set name/ID (optionnal)
|
||||||
* @returns the card object
|
* @returns the card object
|
||||||
*/
|
*/
|
||||||
public async fetchCard(id: string | number, set?: string): Promise<Card | undefined> {
|
public async fetchCard(id: string | number, set?: string): Promise<Card | undefined> {
|
||||||
const path = set ? ['sets', set] : ['cards']
|
const path = set ? ['sets', set] : ['cards']
|
||||||
// @ts-expect-error the base endpoint is 'sets' or 'cards'
|
// @ts-expect-error the base endpoint is 'sets' or 'cards'
|
||||||
return this.fetch(...path, id)
|
return this.fetch(...path, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut to easily fetch cards using an optionnal set name/ID
|
* Shortcut to easily fetch cards using an optionnal set name/ID
|
||||||
* @param set the card set name/ID (optionnal)
|
* @param set the card set name/ID (optionnal)
|
||||||
* @returns a card list
|
* @returns a card list
|
||||||
*/
|
*/
|
||||||
public async fetchCards(set?: string): Promise<Array<CardResume> | undefined> {
|
public async fetchCards(set?: string): Promise<Array<CardResume> | undefined> {
|
||||||
if (set) {
|
if (set) {
|
||||||
const fSet = await this.fetch('sets', set)
|
const fSet = await this.fetch('sets', set)
|
||||||
return fSet ? fSet.cards : undefined
|
return fSet ? fSet.cards : undefined
|
||||||
}
|
}
|
||||||
return this.fetch('cards')
|
return this.fetch('cards')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use `this.fetch('sets', set)`
|
* @deprecated use `this.fetch('sets', set)`
|
||||||
*/
|
*/
|
||||||
public async fetchSet(set: string): Promise<Set | undefined> {
|
public async fetchSet(set: string): Promise<Set | undefined> {
|
||||||
return this.fetch('sets', set)
|
return this.fetch('sets', set)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use `this.fetch('series', serie)`
|
* @deprecated use `this.fetch('series', serie)`
|
||||||
*/
|
*/
|
||||||
public async fetchSerie(serie: string): Promise<Serie | undefined> {
|
public async fetchSerie(serie: string): Promise<Serie | undefined> {
|
||||||
return this.fetch('series', serie)
|
return this.fetch('series', serie)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated use `this.fetch('series')`
|
* @deprecated use `this.fetch('series')`
|
||||||
*/
|
*/
|
||||||
public async fetchSeries(): Promise<SerieList | undefined> {
|
public async fetchSeries(): Promise<SerieList | undefined> {
|
||||||
return this.fetch('series')
|
return this.fetch('series')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shortcut to easily fetch sets using an optionnal serie name/ID
|
* Shortcut to easily fetch sets using an optionnal serie name/ID
|
||||||
* @param serie the card set name/ID (optionnal)
|
* @param serie the card set name/ID (optionnal)
|
||||||
* @returns a card list
|
* @returns a card list
|
||||||
*/
|
*/
|
||||||
public async fetchSets(serie?: string): Promise<SetList | undefined> {
|
public async fetchSets(serie?: string): Promise<SetList | undefined> {
|
||||||
if (serie) {
|
if (serie) {
|
||||||
const fSerie = await this.fetch('series', serie)
|
const fSerie = await this.fetch('series', serie)
|
||||||
return fSerie ? fSerie.sets : undefined
|
return fSerie ? fSerie.sets : undefined
|
||||||
}
|
}
|
||||||
return this.fetch('sets')
|
return this.fetch('sets')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a card using its global id
|
* Fetch a card using its global id
|
||||||
* @param endpoint_0 'cards'
|
* @param endpoint_0 'cards'
|
||||||
* @param endpoint_1 {string} the card global ID
|
* @param endpoint_1 {string} the card global ID
|
||||||
*/
|
*/
|
||||||
public async fetch(...type: ['cards', string]): Promise<Card | undefined>
|
public async fetch(...type: ['cards', string]): Promise<Card | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch every cards in the database
|
* Fetch every cards in the database
|
||||||
* @param endpoint_0 'cards'
|
* @param endpoint_0 'cards'
|
||||||
*/
|
*/
|
||||||
public async fetch(type: 'cards'): Promise<Array<CardResume> | undefined>
|
public async fetch(type: 'cards'): Promise<Array<CardResume> | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a card using its local id and its set
|
* Fetch a card using its local id and its set
|
||||||
* @param endpoint_0 'sets'
|
* @param endpoint_0 'sets'
|
||||||
* @param endpoint_1 {string} the set name or ID
|
* @param endpoint_1 {string} the set name or ID
|
||||||
* @param endpoint_2 {string} the card local ID
|
* @param endpoint_2 {string} the card local ID
|
||||||
*/
|
*/
|
||||||
public async fetch(...endpoint: ['sets', string, string]): Promise<Card | undefined>
|
public async fetch(...endpoint: ['sets', string, string]): Promise<Card | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a set
|
* Fetch a set
|
||||||
* @param endpoint_0 'sets'
|
* @param endpoint_0 'sets'
|
||||||
* @param endpoint_1 {string} the set name or ID
|
* @param endpoint_1 {string} the set name or ID
|
||||||
*/
|
*/
|
||||||
public async fetch(...endpoint: ['sets', string]): Promise<Set | undefined>
|
public async fetch(...endpoint: ['sets', string]): Promise<Set | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch every sets
|
* Fetch every sets
|
||||||
* @param endpoint_0 'sets'
|
* @param endpoint_0 'sets'
|
||||||
*/
|
*/
|
||||||
public async fetch(endpoint: 'sets'): Promise<SetList | undefined>
|
public async fetch(endpoint: 'sets'): Promise<SetList | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a serie
|
* Fetch a serie
|
||||||
* @param endpoint_0 'series'
|
* @param endpoint_0 'series'
|
||||||
* @param endpoint_1 {string} the serie name or ID
|
* @param endpoint_1 {string} the serie name or ID
|
||||||
*/
|
*/
|
||||||
public async fetch(...endpoint: ['series', string]): Promise<Serie | undefined>
|
public async fetch(...endpoint: ['series', string]): Promise<Serie | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch every series
|
* Fetch every series
|
||||||
* @param endpoint_0 'series'
|
* @param endpoint_0 'series'
|
||||||
*/
|
*/
|
||||||
public async fetch(endpoint: 'series'): Promise<SerieList | undefined>
|
public async fetch(endpoint: 'series'): Promise<SerieList | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch cards depending on a specific filter
|
* Fetch cards depending on a specific filter
|
||||||
* @param endpoint_0 {'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'}
|
* @param endpoint_0 {'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'}
|
||||||
* Possible value 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'
|
* Possible value 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'
|
||||||
* @param endpoint_1 {string} the value set while fetching the index
|
* @param endpoint_1 {string} the value set while fetching the index
|
||||||
*/
|
*/
|
||||||
public async fetch(...endpoint: ['categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types', string]): Promise<StringEndpoint | undefined>
|
public async fetch(...endpoint: ['categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types', string]): Promise<StringEndpoint | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch cards depending on a specific filter
|
* Fetch cards depending on a specific filter
|
||||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
||||||
* Possible value 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'
|
* Possible value 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'
|
||||||
* @param endpoint_1 {string} Fetch the possible values to use depending on the endpoint
|
* @param endpoint_1 {string} Fetch the possible values to use depending on the endpoint
|
||||||
*/
|
*/
|
||||||
public async fetch(endpoint: 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'): Promise<Array<string> | undefined>
|
public async fetch(endpoint: 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'): Promise<Array<string> | undefined>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch The differents endpoints depending on the first argument
|
* Fetch The differents endpoints depending on the first argument
|
||||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
||||||
* Possible value 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
* Possible value 'cards' | 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'series' | 'sets' | 'types'
|
||||||
* @param endpoint_1 {string} (Optionnal) some details to go from the index file to the item file (mostly the ID/name)
|
* @param endpoint_1 {string} (Optionnal) some details to go from the index file to the item file (mostly the ID/name)
|
||||||
* @param endpoint_2 {string} (Optionnal) only for sets the card local ID to fetch the card through the set
|
* @param endpoint_2 {string} (Optionnal) only for sets the card local ID to fetch the card through the set
|
||||||
*/
|
*/
|
||||||
public async fetch(...endpoint: Array<Endpoint | string>): Promise<any | undefined> {
|
public async fetch(...endpoint: Array<Endpoint | string>): Promise<any | undefined> {
|
||||||
if (endpoint.length === 0) {
|
if (endpoint.length === 0) {
|
||||||
throw new Error('endpoint to fetch is empty!')
|
throw new Error('endpoint to fetch is empty!')
|
||||||
}
|
}
|
||||||
// @ts-expect-error with the precedent check, we KNOW that type is not empty
|
// @ts-expect-error with the precedent check, we KNOW that type is not empty
|
||||||
const baseEndpoint = endpoint.shift().toLowerCase() as Endpoint
|
const baseEndpoint = endpoint.shift().toLowerCase() as Endpoint
|
||||||
if (!ENDPOINTS.includes(baseEndpoint)) {
|
if (!ENDPOINTS.includes(baseEndpoint)) {
|
||||||
throw new Error(`unknown endpoint to fetch! (${baseEndpoint})`)
|
throw new Error(`unknown endpoint to fetch! (${baseEndpoint})`)
|
||||||
}
|
}
|
||||||
return this.makeRequest(baseEndpoint, ...endpoint)
|
return this.makeRequest(baseEndpoint, ...endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to make the request and normalize the whole path
|
* Function to make the request and normalize the whole path
|
||||||
*/
|
*/
|
||||||
private makeRequest<T = any>(...url: Array<string | number>) {
|
private makeRequest<T = any>(...url: Array<string | number>) {
|
||||||
// Normalize path
|
// Normalize path
|
||||||
const path = url.map((subPath) => encodeURI(
|
const path = url.map((subPath) => encodeURI(
|
||||||
subPath
|
subPath
|
||||||
// Transform numbers to string
|
// Transform numbers to string
|
||||||
.toString()
|
.toString()
|
||||||
// replace this special character with an escaped one
|
// replace this special character with an escaped one
|
||||||
.replace('?', '%3F')
|
.replace('?', '%3F')
|
||||||
// normalize the string
|
// normalize the string
|
||||||
.normalize('NFC')
|
.normalize('NFC')
|
||||||
// remove some special chars by nothing
|
// remove some special chars by nothing
|
||||||
// eslint-disable-next-line no-misleading-character-class
|
// eslint-disable-next-line no-misleading-character-class
|
||||||
.replace(/["'\u0300-\u036f]/gu, '')
|
.replace(/["'\u0300-\u036f]/gu, '')
|
||||||
)).join('/')
|
)).join('/')
|
||||||
return RequestWrapper.fetch<T>(`${BASE_URL}/${this.getLang()}/${path}`)
|
return RequestWrapper.fetch<T>(`${BASE_URL}/${this.getLang()}/${path}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './interfaces'
|
export * from './interfaces'
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"include": ["./src/tcgdex.node.ts"],
|
"include": ["./src/tcgdex.node.ts"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||||
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
"declaration": false, /* Generates corresponding '.d.ts' file. */
|
"declaration": false, /* Generates corresponding '.d.ts' file. */
|
||||||
"declarationDir": null,
|
"declarationDir": null,
|
||||||
"outDir": "./dist/modules", /* Redirect output structure to the directory. */
|
"outDir": "./dist/modules", /* Redirect output structure to the directory. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,66 +1,15 @@
|
|||||||
{
|
{
|
||||||
|
"extends": "./node_modules/@dzeio/config/tsconfig.base",
|
||||||
"include": ["./src/tcgdex.node.ts"],
|
"include": ["./src/tcgdex.node.ts"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Basic Options */
|
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
|
||||||
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
||||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
||||||
"declarationDir": "./dist/types", /* Folder where the declarations are*/
|
|
||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
||||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
||||||
"outDir": "./dist/cjs", /* Redirect output structure to the directory. */
|
|
||||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
||||||
// "composite": true, /* Enable project compilation */
|
|
||||||
// "tsBuildInfoFile": "", /* Specify file to store incremental compilation information */
|
|
||||||
// "removeComments": true, /* Do not emit comments to output. */
|
|
||||||
// "noEmit": true, /* Do not emit outputs. */
|
|
||||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
||||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
||||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
||||||
/* Strict Type-Checking Options */
|
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
|
||||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
||||||
"strictNullChecks": true, /* Enable strict null checks. */
|
|
||||||
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
||||||
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
||||||
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
||||||
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
||||||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
||||||
|
|
||||||
/* Additional Checks */
|
"target": "ES2015",
|
||||||
"noUnusedLocals": true, /* Report errors on unused locals. */
|
|
||||||
"noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
||||||
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
||||||
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
|
|
||||||
"resolveJsonModule": true,
|
"declaration": true,
|
||||||
/* Module Resolution Options */
|
"declarationDir": "./dist/types",
|
||||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
||||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
||||||
// "types": [], /* Type declaration files to be included in compilation. */
|
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
||||||
|
|
||||||
/* Source Map Options */
|
"outDir": "./dist/cjs",
|
||||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
"rootDir": "./src",
|
||||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
||||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
||||||
|
|
||||||
/* Experimental Options */
|
|
||||||
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
||||||
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
const path = require('path')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mode: 'production',
|
|
||||||
entry: './src/tcgdex.browser.ts',
|
|
||||||
output: {
|
|
||||||
path: path.resolve(__dirname, 'dist'),
|
|
||||||
filename: 'tcgdex.browser.js',
|
|
||||||
libraryTarget: 'umd',
|
|
||||||
library: 'TCGdex',
|
|
||||||
umdNamedDefine: true
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.ts']
|
|
||||||
},
|
|
||||||
optimization: {
|
|
||||||
minimize: true
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [{
|
|
||||||
test: /\.ts$/,
|
|
||||||
loader: 'ts-loader',
|
|
||||||
exclude: /node_modules/,
|
|
||||||
options: {
|
|
||||||
compilerOptions: {
|
|
||||||
sourceMap: false,
|
|
||||||
declaration: false,
|
|
||||||
declarationDir: null,
|
|
||||||
target: 'ES2016'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user