mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 18:45:09 +00:00
Compare commits
21 Commits
v2.3.0-bet
...
v2.4.2
Author | SHA1 | Date | |
---|---|---|---|
e172465258
|
|||
9940961e20
|
|||
f25be8b5f5
|
|||
641f7861b8 | |||
3db69e0537 | |||
1c36d6b93e | |||
10083223e2
|
|||
95196ce551
|
|||
81200aede7
|
|||
35642ffd57
|
|||
4435f930ec | |||
46b74170fa
|
|||
de916e09eb
|
|||
96bc9149c9
|
|||
f858bd5c79
|
|||
8a0dac5e27
|
|||
941fd925b8 | |||
3684c61812
|
|||
a2f7018aa4 | |||
7014e0c511
|
|||
b951f6d2d1
|
@ -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
|
||||||
|
4
.eslintignore
Normal file
4
.eslintignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
dist/
|
||||||
|
src/tcgdex.browser.ts
|
||||||
|
__tests__
|
||||||
|
*.js
|
5
.eslintrc.js
Normal file
5
.eslintrc.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: [
|
||||||
|
"./node_modules/@dzeio/config/eslint/typescript"
|
||||||
|
]
|
||||||
|
}
|
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
* text=auto eol=lf
|
44
.github/workflows/build.yml
vendored
Normal file
44
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
name: Build & Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
# Run on any pull request
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
# Follow current releases https://nodejs.org/en/about/releases/
|
||||||
|
node-version: [12.x, 14.x, 16.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
|
||||||
|
- name: Upload Coverage
|
||||||
|
if: matrix.node-version == '16.x'
|
||||||
|
uses: codecov/codecov-action@v1.0.13
|
||||||
|
with:
|
||||||
|
# Comma-separated list of files to upload
|
||||||
|
files: ./coverage/coverage-final.json
|
26
.github/workflows/code-quality.yml
vendored
Normal file
26
.github/workflows/code-quality.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
name: Code Quality Checks
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
# Run on any pull request
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup NodeJS
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '16.x'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: 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 }}
|
14
.gitignore
vendored
14
.gitignore
vendored
@ -1,6 +1,8 @@
|
|||||||
# Dev Files
|
# Dev Files
|
||||||
node_modules
|
node_modules
|
||||||
test.ts
|
test.ts
|
||||||
|
coverage
|
||||||
# Dist files
|
|
||||||
dist
|
# Dist files
|
||||||
|
dist
|
||||||
|
src/version.json
|
||||||
|
@ -6,3 +6,4 @@ webpack.config.js
|
|||||||
tsconfig.*
|
tsconfig.*
|
||||||
yarn.lock
|
yarn.lock
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
|
coverage
|
||||||
|
445
CHANGELOG.md
445
CHANGELOG.md
@ -1,208 +1,237 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
## [2.2.0] - 2021-06-19
|
## 2.4.1 - 2021-07-11
|
||||||
|
|
||||||
### Added
|
## Deprecated
|
||||||
|
|
||||||
- Added new fields
|
- Deprecated `Languages` Type
|
||||||
|
|
||||||
## [2.1.1] - 2021-05-31
|
## 2.4.0 - 2021-06-29
|
||||||
|
|
||||||
### Fixed
|
## Added
|
||||||
|
|
||||||
- Package building in the wrong version of ECMAScript
|
- Support for new languages
|
||||||
|
|
||||||
## [2.1.0] - 2021-05-31
|
## 2.3.1 - 2021-06-22
|
||||||
|
|
||||||
### Added
|
### Fixed
|
||||||
|
|
||||||
- new `fetch` function that manage all the API endpoints
|
- Cleaned dist folder
|
||||||
|
|
||||||
## [2.0.2-2.0.3] - 2021-05-28
|
## 2.3.0-2.3.1 - 2021-06-22
|
||||||
|
|
||||||
### Fixed
|
### Added
|
||||||
|
|
||||||
- `rotationMark` should have been named `regulationMark`
|
- Browser specialized build
|
||||||
|
- [#9](https://github.com/tcgdex/javascript-sdk/pull/9) Build/Unit/ESLint tests and coverage with Codecov using Github Action
|
||||||
## [2.0.1] - 2021-05-28
|
|
||||||
|
### Changed
|
||||||
### Changed
|
|
||||||
|
- [#10](https://github.com/tcgdex/javascript-sdk/pull/10) Simplified Request/Cache manager
|
||||||
- Hardcoded string values are now strings as they depends on the language
|
|
||||||
|
## [2.2.0] - 2021-06-19
|
||||||
## [2.0.0] - 2021-05-28
|
|
||||||
|
### Added
|
||||||
### Added
|
|
||||||
|
- Added new fields
|
||||||
- simple string endpoint typing
|
|
||||||
- Typing is exported through the main.d.ts file
|
## [2.1.1] - 2021-05-31
|
||||||
- `cardCount` field in the set interface
|
|
||||||
- a `rotationMark` to the card interface
|
### Fixed
|
||||||
|
|
||||||
### Changed
|
- Package building in the wrong version of ECMAScript
|
||||||
|
|
||||||
- Support new incoming datas
|
## [2.1.0] - 2021-05-31
|
||||||
- Point the SDK to the new V2
|
|
||||||
- Renamed `getExpansion(s)` to `getSerie(s)`
|
### Added
|
||||||
- Typing for the new SDK
|
|
||||||
- Functions now use `fetch` instead of `get` in their names
|
- new `fetch` function that manage all the API endpoints
|
||||||
- URL Normalization is now done by the SDK
|
|
||||||
|
## [2.0.2-2.0.3] - 2021-05-28
|
||||||
### Fixed
|
|
||||||
|
### Fixed
|
||||||
- `getSerie(s)` now point to the correct endpoint
|
|
||||||
|
- `rotationMark` should have been named `regulationMark`
|
||||||
### Removed
|
|
||||||
|
## [2.0.1] - 2021-05-28
|
||||||
- TranslationUtil as now translation are managed by the API
|
|
||||||
- the interfaces folder as every interfaces are now in `interfaces.d.ts`
|
### Changed
|
||||||
- `this.gbu`
|
|
||||||
- Translation files as they are now in the Compiler
|
- Hardcoded string values are now strings as they depends on the language
|
||||||
|
|
||||||
## [1.7.0] - 2021-01-31
|
## [2.0.0] - 2021-05-28
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- new Rarities
|
- simple string endpoint typing
|
||||||
|
- Typing is exported through the main.d.ts file
|
||||||
## [1.6.1] - 2021-01-31
|
- `cardCount` field in the set interface
|
||||||
|
- a `rotationMark` to the card interface
|
||||||
### Changed
|
|
||||||
|
### Changed
|
||||||
- tags are now optionnal
|
|
||||||
|
- Support new incoming datas
|
||||||
## [1.6.0] - 2021-01-08
|
- Point the SDK to the new V2
|
||||||
|
- Renamed `getExpansion(s)` to `getSerie(s)`
|
||||||
### Changed
|
- Typing for the new SDK
|
||||||
|
- Functions now use `fetch` instead of `get` in their names
|
||||||
- Errors are now handled to return `undefined`
|
- URL Normalization is now done by the SDK
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
- console.warn when using `getCards`
|
- TranslationUtil as now translation are managed by the API
|
||||||
|
- the interfaces folder as every interfaces are now in `interfaces.d.ts`
|
||||||
## [1.5.0] - 2021-01-08
|
- `this.gbu`
|
||||||
|
- Translation files as they are now in the Compiler
|
||||||
### Added
|
|
||||||
|
## [1.7.0] - 2021-01-31
|
||||||
- getSet can now not transform the API Date to a Javascript Date
|
|
||||||
|
### Added
|
||||||
## [1.4.2] - 2021-01-08
|
|
||||||
|
- new Rarities
|
||||||
### Added
|
|
||||||
|
## [1.6.1] - 2021-01-31
|
||||||
- new Tags
|
|
||||||
|
### Changed
|
||||||
### Changed
|
|
||||||
|
- tags are now optionnal
|
||||||
- rarities to have less strange rarities
|
|
||||||
-
|
## [1.6.0] - 2021-01-08
|
||||||
|
|
||||||
### Fixed
|
### Changed
|
||||||
|
|
||||||
- CORS blocked
|
- Errors are now handled to return `undefined`
|
||||||
|
|
||||||
|
### Removed
|
||||||
## [1.4.1] - 2020-04-24
|
|
||||||
|
- console.warn when using `getCards`
|
||||||
### Changed
|
|
||||||
|
## [1.5.0] - 2021-01-08
|
||||||
- Changed API url to the new one
|
|
||||||
|
### Added
|
||||||
## [1.4.0] - 2020-03-25
|
|
||||||
|
- getSet can now not transform the API Date to a Javascript Date
|
||||||
### Added
|
|
||||||
|
## [1.4.2] - 2021-01-08
|
||||||
- a `defaultLang` static field to customize the default lang
|
|
||||||
- a `getLang` function to get the current lang for the SDK
|
### Added
|
||||||
|
|
||||||
### Fixed
|
- new Tags
|
||||||
|
|
||||||
- Warnings for translations
|
### Changed
|
||||||
|
|
||||||
## [1.3.0] - 2020-03-18
|
- rarities to have less strange rarities
|
||||||
|
-
|
||||||
### Added
|
|
||||||
|
### Fixed
|
||||||
- A cache system
|
|
||||||
- some informations about differents tags on a card
|
- CORS blocked
|
||||||
- lvl on the card interface
|
|
||||||
|
|
||||||
### Removed
|
## [1.4.1] - 2020-04-24
|
||||||
|
|
||||||
- cardTypes on the card interface
|
### Changed
|
||||||
|
|
||||||
## [1.2.1] - 2020-03-14
|
- Changed API url to the new one
|
||||||
|
|
||||||
### Fixed
|
## [1.4.0] - 2020-03-25
|
||||||
|
|
||||||
- Fix items datas not in the correct interface
|
### Added
|
||||||
|
|
||||||
## [1.2.0] - 2020-03-14
|
- a `defaultLang` static field to customize the default lang
|
||||||
|
- a `getLang` function to get the current lang for the SDK
|
||||||
### Added
|
|
||||||
|
### Fixed
|
||||||
- Added The getCards endpoint to fetch the big list of card with an optionnal filter on the set
|
|
||||||
- Added The getExpansions endpoint to fetch the list of expansions
|
- Warnings for translations
|
||||||
- Added Some informations about cardTypes
|
|
||||||
- Updated DB to add support for items
|
## [1.3.0] - 2020-03-18
|
||||||
|
|
||||||
### Fixed
|
### Added
|
||||||
|
|
||||||
- Fix translation not getting the correct file
|
- A cache system
|
||||||
|
- some informations about differents tags on a card
|
||||||
|
- lvl on the card interface
|
||||||
## [1.0.8] - 2020-03-11
|
|
||||||
|
### Removed
|
||||||
### Changed
|
|
||||||
|
- cardTypes on the card interface
|
||||||
- Changed typing for some interfaces
|
|
||||||
|
## [1.2.1] - 2020-03-14
|
||||||
## [1.0.1-1.0.7] - 2020-03-11
|
|
||||||
|
### Fixed
|
||||||
### Changed
|
|
||||||
|
- Fix items datas not in the correct interface
|
||||||
- Renamed the class Name from `TCGDex` to `TCGdex`
|
|
||||||
- lang argument is now public so it can be changed while the SDK is active
|
## [1.2.0] - 2020-03-14
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- some typing for getCard and translationUtil
|
- Added The getCards endpoint to fetch the big list of card with an optionnal filter on the set
|
||||||
|
- Added The getExpansions endpoint to fetch the list of expansions
|
||||||
## [1.0.0] - 2020-03-11
|
- Added Some informations about cardTypes
|
||||||
|
- Updated DB to add support for items
|
||||||
### Added
|
|
||||||
|
### Fixed
|
||||||
- the getCard function to use with the fetch a card with it's id
|
|
||||||
- the getSet function to use with the fetch a set with it's id
|
- Fix translation not getting the correct file
|
||||||
- the getExpansion function to use with the fetch an expansion with it's id
|
|
||||||
- Constructor arg support for multiple langs
|
|
||||||
- TranslationUtil to go from the SDK value to a text value
|
## [1.0.8] - 2020-03-11
|
||||||
|
|
||||||
[Unreleased]: https://github.com/tcgdex/javascript-sdk/compare/v2.1.1...HEAD
|
### Changed
|
||||||
|
|
||||||
[2.1.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.1.1
|
- Changed typing for some interfaces
|
||||||
[2.1.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.1.0
|
|
||||||
[2.0.2-2.0.3]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.3
|
## [1.0.1-1.0.7] - 2020-03-11
|
||||||
[2.0.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.1
|
|
||||||
[2.0.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.0
|
### Changed
|
||||||
[1.7.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.7.0
|
|
||||||
[1.6.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.6.1
|
- Renamed the class Name from `TCGDex` to `TCGdex`
|
||||||
[1.6.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.6.0
|
- lang argument is now public so it can be changed while the SDK is active
|
||||||
[1.5.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.5.0
|
|
||||||
[1.4.2]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.2
|
### Added
|
||||||
[1.4.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.1
|
|
||||||
[1.4.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.0
|
- some typing for getCard and translationUtil
|
||||||
[1.3.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.3.0
|
|
||||||
[1.2.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.2.1
|
## [1.0.0] - 2020-03-11
|
||||||
[1.2.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.2.0
|
|
||||||
[1.0.8]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.0.8
|
### Added
|
||||||
[1.0.1-1.0.7]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.0.7
|
|
||||||
[1.0.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.0.0
|
- the getCard function to use with the fetch a card with it's id
|
||||||
|
- the getSet function to use with the fetch a set with it's id
|
||||||
|
- the getExpansion function to use with the fetch an expansion with it's id
|
||||||
|
- Constructor arg support for multiple langs
|
||||||
|
- TranslationUtil to go from the SDK value to a text value
|
||||||
|
|
||||||
|
[Unreleased]: https://github.com/tcgdex/javascript-sdk/compare/v2.3.1...HEAD
|
||||||
|
|
||||||
|
[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.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.1.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.1.1
|
||||||
|
[2.1.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.1.0
|
||||||
|
[2.0.2-2.0.3]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.3
|
||||||
|
[2.0.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.1
|
||||||
|
[2.0.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v2.0.0
|
||||||
|
[1.7.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.7.0
|
||||||
|
[1.6.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.6.1
|
||||||
|
[1.6.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.6.0
|
||||||
|
[1.5.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.5.0
|
||||||
|
[1.4.2]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.2
|
||||||
|
[1.4.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.1
|
||||||
|
[1.4.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.4.0
|
||||||
|
[1.3.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.3.0
|
||||||
|
[1.2.1]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.2.1
|
||||||
|
[1.2.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.2.0
|
||||||
|
[1.0.8]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.0.8
|
||||||
|
[1.0.1-1.0.7]: https://github.com/tcgdex/javascript-sdk/releases/tag/1.0.7
|
||||||
|
[1.0.0]: https://github.com/tcgdex/javascript-sdk/releases/tag/v1.0.0
|
||||||
|
122
README.md
122
README.md
@ -1,50 +1,72 @@
|
|||||||
# TCGdex JavaScript/TypeScript SDK
|
<p align="center">
|
||||||
|
<a href="http://npmjs.com/@tcgdex/sdk">
|
||||||
This is the SDK used to communicate with the Open source [TCGdex API](https://www.github.com/tcgdex/cards-database)
|
<img src="https://img.shields.io/npm/v/@tcgdex/sdk?style=flat-square" alt="NOM Version">
|
||||||
|
</a>
|
||||||
Full API/SDK documentation in progress at https://www.tcgdex.net/docs
|
<a href="http://npmjs.com/@tcgdex/sdk">
|
||||||
|
<img src="https://img.shields.io/npm/dw/@tcgdex/sdk?style=flat-square" alt="NPM Downloads">
|
||||||
## Install
|
</a>
|
||||||
|
<a href="https://app.codecov.io/gh/tcgdex/javascript-sdk/">
|
||||||
```bash
|
<img src="https://img.shields.io/codecov/c/github/tcgdex/javascript-sdk?style=flat-square&token=FR4BI94N4Q" alt="npm version">
|
||||||
yarn add @tcgdex/sdk
|
</a>
|
||||||
# or
|
<a href="https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md">
|
||||||
npm install @tcgdex/sdk
|
<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 href="https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md">
|
||||||
## Usage
|
<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>
|
||||||
_Note: a complete documentation is in progress_
|
<a href="https://discord.gg/NehYTAhsZE">
|
||||||
|
<img src="https://img.shields.io/discord/857231041261076491?color=%235865F2&label=Discord&style=flat-square" alt="Discord Link">
|
||||||
```javascript
|
</a>
|
||||||
import TCGdex from '@tcgdex/sdk'
|
</p>
|
||||||
|
|
||||||
// initialize the SDK
|
# TCGdex JavaScript/TypeScript SDK
|
||||||
const tcgdex = new TCGdex('en') // Lang code (Optionnal) (See interfaces.d.ts line 1 for supported languages)
|
|
||||||
|
Communicate with the Open Source TCGdex API in Javascript/Typescript using the SDK
|
||||||
// if you need to change the language
|
|
||||||
tcgdex.lang = 'fr'
|
Full API/SDK documentation in progress at https://www.tcgdex.net/docs
|
||||||
|
|
||||||
// get a Card using its global ID
|
## Getting Started
|
||||||
await tcgdex.fetch('cards', 'base1-1')
|
|
||||||
|
Install the SDK using:
|
||||||
// fetch a Card using it's local id and set name/ID
|
```bash
|
||||||
await tcgdex.fetch('sets', 'Base Set', 1)
|
yarn add @tcgdex/sdk
|
||||||
|
# or
|
||||||
// fetch a Set's informations using the set's name/ID
|
npm install @tcgdex/sdk
|
||||||
await tcgdex.fetch('sets', 'Sword & Shield')
|
```
|
||||||
|
|
||||||
// Fetch a serie using the serie's name/ID
|
## Usage
|
||||||
await tcgdex.fetch('series', 'Black & White')
|
|
||||||
|
_Note: a complete documentation is in progress_
|
||||||
// Fetch cards using other endpoints
|
|
||||||
/**
|
```javascript
|
||||||
* categories => the the different cards categories
|
import TCGdex from '@tcgdex/sdk'
|
||||||
* hp => fetch the different cards possible HPs
|
|
||||||
* illustrators => fetch all the cards illustrators
|
// initialize the SDK
|
||||||
* rarities => fetch the cards rarities
|
const tcgdex = new TCGdex('en') // Lang code (Optionnal) (See interfaces.ts line 1 for supported languages)
|
||||||
* retreats => fetch the cards using the retreat count
|
|
||||||
* types => fetch the cards using the Pokémon type(s)
|
// if you need to change the language
|
||||||
**/
|
tcgdex.lang = 'fr'
|
||||||
await tcgdex.fetch('categories')
|
|
||||||
```
|
// get a Card using its global ID
|
||||||
|
await tcgdex.fetch('cards', 'base1-1')
|
||||||
|
|
||||||
|
// fetch a Card using it's local id and set name/ID
|
||||||
|
await tcgdex.fetch('sets', 'Base Set', 1)
|
||||||
|
|
||||||
|
// fetch a Set's informations using the set's name/ID
|
||||||
|
await tcgdex.fetch('sets', 'Sword & Shield')
|
||||||
|
|
||||||
|
// Fetch a serie using the serie's name/ID
|
||||||
|
await tcgdex.fetch('series', 'Black & White')
|
||||||
|
|
||||||
|
// Fetch cards using other endpoints
|
||||||
|
/**
|
||||||
|
* categories => the the different cards categories
|
||||||
|
* hp => fetch the different cards possible HPs
|
||||||
|
* illustrators => fetch all the cards illustrators
|
||||||
|
* rarities => fetch the cards rarities
|
||||||
|
* retreats => fetch the cards using the retreat count
|
||||||
|
* types => fetch the cards using the Pokémon type(s)
|
||||||
|
**/
|
||||||
|
await tcgdex.fetch('categories')
|
||||||
|
```
|
||||||
|
66
__tests__/basic.test.js
Normal file
66
__tests__/basic.test.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
const TCGdex = require("../src/tcgdex").default
|
||||||
|
const fetch = require('node-fetch')
|
||||||
|
|
||||||
|
const fakeFetch = (response, status = 200) => jest.fn(() =>
|
||||||
|
Promise.resolve({
|
||||||
|
status: status,
|
||||||
|
json: () => Promise.resolve(response),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
test('Basic test', async () => {
|
||||||
|
const tcgdex = new TCGdex('en')
|
||||||
|
TCGdex.fetch = fakeFetch({ok: true})
|
||||||
|
const res = await tcgdex.fetch('cards', 'basic-test')
|
||||||
|
expect(res).toEqual({ok: true})
|
||||||
|
expect(TCGdex.fetch).toHaveBeenCalledTimes(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Cache test', async () => {
|
||||||
|
const tcgdex = new TCGdex('en')
|
||||||
|
TCGdex.fetch = fakeFetch({ok: 'a'})
|
||||||
|
const res1 = await tcgdex.fetch('cards', 'cache-test')
|
||||||
|
expect(res1).toEqual({ok: 'a'})
|
||||||
|
TCGdex.fetch = fakeFetch({ok: 'b'})
|
||||||
|
const res2 = await tcgdex.fetch('cards', 'cache-test')
|
||||||
|
expect(res2).toEqual({ok: 'a'})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('endpoint errors', async () => {
|
||||||
|
const tcgdex = new TCGdex('en')
|
||||||
|
TCGdex.fetch = fakeFetch({ok: 'a'})
|
||||||
|
await expect(tcgdex.fetch('non existing endpoint')).rejects.toThrow()
|
||||||
|
await expect(tcgdex.fetch()).rejects.toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('404 test', async () => {
|
||||||
|
const tcgdex = new TCGdex('en')
|
||||||
|
TCGdex.fetch = fakeFetch(undefined, 404)
|
||||||
|
expect(
|
||||||
|
await tcgdex.fetch('cards', '404-test')
|
||||||
|
).not.toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('test real endpoints', async () => {
|
||||||
|
const tcgdex = new TCGdex('en')
|
||||||
|
TCGdex.fetch = fetch
|
||||||
|
const endpoints = [
|
||||||
|
{endpoint: 'fetchCard', params: ['swsh1-1']},
|
||||||
|
{endpoint: 'fetchCard', params: ['1', 'Sword & Shield']},
|
||||||
|
{endpoint: 'fetchCards', params: ['swsh1']},
|
||||||
|
{endpoint: 'fetchCards', params: []},
|
||||||
|
{endpoint: 'fetchSet', params: ['swsh1']},
|
||||||
|
{endpoint: 'fetchSets', params: ['swsh']},
|
||||||
|
{endpoint: 'fetchSets', params: []},
|
||||||
|
{endpoint: 'fetchSeries', params: []},
|
||||||
|
{endpoint: 'fetchSerie', params: ['swsh']},
|
||||||
|
]
|
||||||
|
|
||||||
|
for await (const item of endpoints) {
|
||||||
|
expect(
|
||||||
|
await tcgdex[item.endpoint](...item.params)
|
||||||
|
).toBeDefined()
|
||||||
|
}
|
||||||
|
})
|
7
babel.config.js
Normal file
7
babel.config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
// Babel config for Jest
|
||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
['@babel/preset-env', {targets: {node: 'current'}}],
|
||||||
|
'@babel/preset-typescript'
|
||||||
|
],
|
||||||
|
};
|
15619
package-lock.json
generated
Normal file
15619
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
104
package.json
104
package.json
@ -1,44 +1,60 @@
|
|||||||
{
|
{
|
||||||
"name": "@tcgdex/sdk",
|
"name": "@tcgdex/sdk",
|
||||||
"version": "2.3.0-beta.2",
|
"version": "2.4.2",
|
||||||
"main": "./dist/cjs/tcgdex.node.js",
|
"main": "./dist/cjs/tcgdex.node.js",
|
||||||
"module": "./dist/modules/tcgdex.node.js",
|
"types": "./dist/types/tcgdex.d.ts",
|
||||||
"types": "./dist/types/tcgdex.d.ts",
|
"description": "Communicate with the Open Source TCGdex API in Javascript/Typescript using the SDK",
|
||||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||||
"license": "MIT",
|
"homepage": "https://github.com/tcgdex/javascript-sdk",
|
||||||
"devDependencies": {
|
"author": "Aviortheking",
|
||||||
"@parcel/packager-ts": "2.0.0-beta.2",
|
"keywords": [
|
||||||
"@types/node-fetch": "^2.5.10",
|
"tcgdex",
|
||||||
"awesome-typescript-loader": "^5.2.1",
|
"pokemon",
|
||||||
"ts-node": "^10.0.0",
|
"trading",
|
||||||
"typescript": "^4.1.3",
|
"card",
|
||||||
"webpack": "^5.40.0",
|
"tcg",
|
||||||
"webpack-nano": "^1.1.1"
|
"sdk",
|
||||||
},
|
"api",
|
||||||
"dependencies": {
|
"typescript",
|
||||||
"node-fetch": "^2.6.1",
|
"javascript",
|
||||||
"unfetch": "^4.2.0"
|
"typing"
|
||||||
},
|
],
|
||||||
"scripts": {
|
"license": "MIT",
|
||||||
"build": "yarn build:cjs && yarn build:browser && yarn build:es2015",
|
"devDependencies": {
|
||||||
"build:cjs": "tsc --project tsconfig.json",
|
"@babel/core": "^7.14.6",
|
||||||
"build:es2015": "tsc --project tsconfig.es2015.json",
|
"@babel/preset-env": "^7.14.7",
|
||||||
"build:browser": "wp --config webpack.config.js",
|
"@babel/preset-typescript": "^7.14.5",
|
||||||
"prepublishOnly": "yarn build"
|
"@dzeio/config": "^1.0.0",
|
||||||
},
|
"@types/node-fetch": "^2.5.10",
|
||||||
"files": [
|
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||||
"dist"
|
"@typescript-eslint/parser": "^4.28.0",
|
||||||
],
|
"eslint": "^7.29.0",
|
||||||
"sideEffects": false,
|
"jest": "^27.0.5",
|
||||||
"targets": {
|
"ts-loader": "^9.2.3",
|
||||||
"browser": {
|
"ts-node": "^10.0.0",
|
||||||
"context": "browser",
|
"typescript": "^4.1.3",
|
||||||
"engines": {
|
"webpack": "^5.40.0",
|
||||||
"browsers": "since 2017-06"
|
"webpack-nano": "^1.1.1"
|
||||||
},
|
},
|
||||||
"includeNodeModules": true,
|
"engines": {
|
||||||
"optimize": false,
|
"node": ">=12"
|
||||||
"scopeHoist": false
|
},
|
||||||
}
|
"dependencies": {
|
||||||
}
|
"isomorphic-unfetch": "^3.1.0",
|
||||||
}
|
"unfetch": "^4.2.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"prebuild": "node scripts/export-version-number.js",
|
||||||
|
"build": "npm run prebuild && npm run build:cjs && npm run build:browser && npm run build:es2015",
|
||||||
|
"build:cjs": "tsc --project tsconfig.json",
|
||||||
|
"build:es2015": "tsc --project tsconfig.es2015.json",
|
||||||
|
"build:browser": "wp --config webpack.config.js",
|
||||||
|
"prepublishOnly": "npm run build",
|
||||||
|
"lint": "eslint",
|
||||||
|
"test": "jest --coverage"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"sideEffects": false
|
||||||
|
}
|
||||||
|
4
scripts/export-version-number.js
Normal file
4
scripts/export-version-number.js
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
const { version } = require('../package.json')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
fs.writeFileSync('./src/version.json', JSON.stringify({version}))
|
@ -1,51 +1,31 @@
|
|||||||
import TCGdex from './tcgdex'
|
import TCGdex from './tcgdex'
|
||||||
|
import { version } from './version.json'
|
||||||
|
|
||||||
export default class RequestWrapper {
|
export default class Request {
|
||||||
private static cache: Array<Request<any>> = []
|
|
||||||
|
|
||||||
public static getRequest<T>(url: string) {
|
// 1 hour of TTL by default
|
||||||
let req = this.cache.find((req) => req.url === url) as Request<T>|undefined
|
public static ttl = 1000 * 60 * 60
|
||||||
if (!req) {
|
|
||||||
req = new Request<T>(url)
|
|
||||||
this.cache.push(req)
|
|
||||||
}
|
|
||||||
return req
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Request<T = any> {
|
private static cache: Record<string, {response: any, time: number}> = {}
|
||||||
public static ttl = 1000 * 60 * 60 // 1 hour
|
|
||||||
|
|
||||||
private response?: T
|
public static async fetch<T>(url: string): Promise<T | undefined> {
|
||||||
private fetched?: Date
|
let request = this.cache[url]
|
||||||
|
const now = new Date().getTime()
|
||||||
public constructor(
|
if (!request || now - request.time > this.ttl) {
|
||||||
public url: string // url is public for quick url test
|
const unfetch = TCGdex.fetch
|
||||||
) {}
|
const resp = await unfetch(url, {
|
||||||
|
headers: {
|
||||||
public async get(): Promise<T | undefined> {
|
'user-agent': `@tcgdex/javascript-sdk/${version}`
|
||||||
const now = new Date()
|
}
|
||||||
// if reponse was already fetched and TTL was not passed
|
})
|
||||||
if (
|
if (resp.status !== 200) {
|
||||||
this.fetched &&
|
return undefined
|
||||||
this.response &&
|
|
||||||
now.getTime() - this.fetched.getTime() < Request.ttl
|
|
||||||
) {
|
|
||||||
return this.response
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch Response
|
|
||||||
const unfetch = TCGdex.fetch
|
|
||||||
const resp = await unfetch(this.url, {
|
|
||||||
headers: {
|
|
||||||
'user-agent': `@tcgdex/javascript-sdk/${TCGdex.VERSION}`
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
if (resp.status !== 200) {
|
this.cache[url] = { response: await resp.json(), time: now }
|
||||||
return undefined
|
request = this.cache[url]
|
||||||
}
|
}
|
||||||
this.response = await resp.json()
|
return request.response
|
||||||
this.fetched = now
|
|
||||||
return this.response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
export type SupportedLanguages = 'en' | 'fr'
|
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 {
|
||||||
@ -28,14 +31,16 @@ export interface SetResume {
|
|||||||
logo?: string
|
logo?: string
|
||||||
symbol?: string
|
symbol?: string
|
||||||
cardCount: {
|
cardCount: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* total of number of cards
|
* total of number of cards
|
||||||
*/
|
*/
|
||||||
total: number
|
total: number
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* number of cards officialy (on the bottom of each cards)
|
* number of cards officialy (on the bottom of each cards)
|
||||||
*/
|
*/
|
||||||
official: number
|
official: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +58,7 @@ export interface Set extends SetResume {
|
|||||||
* card is banned from the set it will still be true
|
* card is banned from the set it will still be true
|
||||||
*/
|
*/
|
||||||
legal: {
|
legal: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ability to play in standard tournaments
|
* Ability to play in standard tournaments
|
||||||
*/
|
*/
|
||||||
@ -65,26 +71,32 @@ export interface Set extends SetResume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cardCount: {
|
cardCount: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* total of number of cards
|
* total of number of cards
|
||||||
*/
|
*/
|
||||||
total: number
|
total: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* number of cards officialy (on the bottom of each cards)
|
* number of cards officialy (on the bottom of each cards)
|
||||||
*/
|
*/
|
||||||
official: number
|
official: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* number of cards having a normal version
|
* number of cards having a normal version
|
||||||
*/
|
*/
|
||||||
normal: number
|
normal: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* number of cards having an reverse version
|
* number of cards having an reverse version
|
||||||
*/
|
*/
|
||||||
reverse: number
|
reverse: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* number of cards having an holo version
|
* number of cards having an holo version
|
||||||
*/
|
*/
|
||||||
holo: number
|
holo: number
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of possible cards
|
* Number of possible cards
|
||||||
*/
|
*/
|
||||||
@ -159,8 +171,9 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Pokemon Types
|
* Pokemon Types
|
||||||
|
* ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
||||||
*/
|
*/
|
||||||
types?: Array<string> // ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
types?: Array<string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pokemon Sub Evolution
|
* Pokemon Sub Evolution
|
||||||
@ -257,7 +270,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
|
|
||||||
retreat?: number
|
retreat?: number
|
||||||
|
|
||||||
//Trainer/Energy
|
// Trainer/Energy
|
||||||
effect?: string
|
effect?: string
|
||||||
|
|
||||||
// Trainer Only
|
// Trainer Only
|
||||||
@ -277,6 +290,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
|||||||
* Note: all cards are avaialable to play in unlimited tournaments
|
* Note: all cards are avaialable to play in unlimited tournaments
|
||||||
*/
|
*/
|
||||||
legal: {
|
legal: {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ability to play in standard tournaments
|
* Ability to play in standard tournaments
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import TCGdex from './tcgdex'
|
import TCGdex from './tcgdex'
|
||||||
import fetch from 'node-fetch'
|
import fetch from 'isomorphic-unfetch'
|
||||||
|
|
||||||
TCGdex.fetch = fetch as any
|
TCGdex.fetch = fetch as any
|
||||||
|
|
||||||
|
@ -8,16 +8,14 @@ export default class TCGdex {
|
|||||||
|
|
||||||
public static fetch: typeof fetch
|
public static fetch: typeof fetch
|
||||||
|
|
||||||
public static readonly VERSION = "2.2.0"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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() {
|
public getLang(): SupportedLanguages {
|
||||||
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ export default class TCGdex {
|
|||||||
/**
|
/**
|
||||||
* @deprecated use `this.fetch('sets', set)`
|
* @deprecated use `this.fetch('sets', set)`
|
||||||
*/
|
*/
|
||||||
public async fetchSet(set: string) {
|
public async fetchSet(set: string): Promise<Set | undefined> {
|
||||||
return this.fetch('sets', set)
|
return this.fetch('sets', set)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,11 +84,13 @@ export default class TCGdex {
|
|||||||
* @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'
|
||||||
@ -98,28 +98,33 @@ export default class TCGdex {
|
|||||||
* @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'}
|
||||||
@ -127,6 +132,7 @@ export default class TCGdex {
|
|||||||
* @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'}
|
||||||
@ -134,6 +140,7 @@ export default class TCGdex {
|
|||||||
* @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'}
|
||||||
@ -143,7 +150,7 @@ export default class TCGdex {
|
|||||||
*/
|
*/
|
||||||
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
|
||||||
@ -158,8 +165,8 @@ export default class TCGdex {
|
|||||||
*/
|
*/
|
||||||
private makeRequest<T = any>(...url: Array<string | number>) {
|
private makeRequest<T = any>(...url: Array<string | number>) {
|
||||||
// Normalize path
|
// Normalize path
|
||||||
const path = url.map((v) => encodeURI(
|
const path = url.map((subPath) => encodeURI(
|
||||||
v
|
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
|
||||||
@ -167,10 +174,12 @@ export default class TCGdex {
|
|||||||
// normalize the string
|
// normalize the string
|
||||||
.normalize('NFC')
|
.normalize('NFC')
|
||||||
// remove some special chars by nothing
|
// remove some special chars by nothing
|
||||||
.replace(/["'\u0300-\u036f]/g, "")
|
// eslint-disable-next-line no-misleading-character-class
|
||||||
|
.replace(/["'\u0300-\u036f]/gu, '')
|
||||||
)).join('/')
|
)).join('/')
|
||||||
return RequestWrapper.getRequest<T>(`${BASE_URL}/${this.getLang()}/${path}`).get()
|
return RequestWrapper.fetch<T>(`${BASE_URL}/${this.getLang()}/${path}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export * from './interfaces'
|
export * from './interfaces'
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
"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. */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,15 @@ module.exports = {
|
|||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [{
|
||||||
test: /\.ts$/,
|
test: /\.ts$/,
|
||||||
loader: 'awesome-typescript-loader',
|
loader: 'ts-loader',
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
options: {
|
options: {
|
||||||
sourceMap: false,
|
compilerOptions: {
|
||||||
declarationDir: false,
|
sourceMap: false,
|
||||||
target: 'ES2016'
|
declaration: false,
|
||||||
|
declarationDir: null,
|
||||||
|
target: 'ES2016'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user