mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 02:25:10 +00:00
Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
f25be8b5f5
|
|||
641f7861b8 | |||
3db69e0537 | |||
1c36d6b93e | |||
10083223e2
|
|||
95196ce551
|
|||
81200aede7
|
|||
35642ffd57
|
|||
4435f930ec | |||
46b74170fa
|
|||
de916e09eb
|
|||
96bc9149c9
|
|||
f858bd5c79
|
|||
8a0dac5e27
|
|||
941fd925b8 | |||
3684c61812
|
|||
a2f7018aa4 | |||
7014e0c511
|
|||
b951f6d2d1
|
|||
babd4e5f85
|
|||
efe5957946
|
|||
f19298e20d
|
|||
4789c15c7d
|
|||
f28fa11710
|
|||
95c48e530e
|
|||
c3791959be
|
|||
a3537a1af7 | |||
4da8131d11 | |||
8405302286 | |||
b1d97a4278 | |||
b004321f40 | |||
b3d34182a2 | |||
1b1bcfbb84 |
@ -5,4 +5,8 @@ indent_style = tab
|
||||
indent_size = 4
|
||||
charset = utf-8
|
||||
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 }}
|
16
.gitignore
vendored
16
.gitignore
vendored
@ -1,8 +1,8 @@
|
||||
node_modules
|
||||
|
||||
# Dist files
|
||||
*.js
|
||||
*.d.ts
|
||||
!interfaces.d.ts
|
||||
!main.d.ts
|
||||
test.ts
|
||||
# Dev Files
|
||||
node_modules
|
||||
test.ts
|
||||
coverage
|
||||
|
||||
# Dist files
|
||||
dist
|
||||
src/version.json
|
||||
|
@ -1,8 +1,9 @@
|
||||
src
|
||||
.editorconfig
|
||||
.gitignore
|
||||
.npmignore
|
||||
tsconfig.json
|
||||
*.ts
|
||||
webpack.config.js
|
||||
tsconfig.*
|
||||
yarn.lock
|
||||
test.js
|
||||
test.d.ts
|
||||
CHANGELOG.md
|
||||
coverage
|
||||
|
@ -1,186 +1,237 @@
|
||||
# Changelog
|
||||
|
||||
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/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]()
|
||||
|
||||
## [2.0.2-2.0.3] - 2021-05-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- `rotationMark` should have been named `regulationMark`
|
||||
|
||||
## [2.0.1] - 2021-05-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Hardcoded string values are now strings as they depends on the language
|
||||
|
||||
## [2.0.0] - 2021-05-28
|
||||
|
||||
### Added
|
||||
|
||||
- simple string endpoint typing
|
||||
- Typing is exported through the main.d.ts file
|
||||
- `cardCount` field in the set interface
|
||||
- a `rotationMark` to the card interface
|
||||
|
||||
### Changed
|
||||
|
||||
- Support new incoming datas
|
||||
- Point the SDK to the new V2
|
||||
- Renamed `getExpansion(s)` to `getSerie(s)`
|
||||
- Typing for the new SDK
|
||||
- Functions now use `fetch` instead of `get` in their names
|
||||
- URL Normalization is now done by the SDK
|
||||
|
||||
### Fixed
|
||||
|
||||
- `getSerie(s)` now point to the correct endpoint
|
||||
|
||||
### Removed
|
||||
|
||||
- TranslationUtil as now translation are managed by the API
|
||||
- the interfaces folder as every interfaces are now in `interfaces.d.ts`
|
||||
- `this.gbu`
|
||||
- Translation files as they are now in the Compiler
|
||||
|
||||
## [1.7.0] - 2021-01-31
|
||||
|
||||
### Added
|
||||
|
||||
- new Rarities
|
||||
|
||||
## [1.6.1] - 2021-01-31
|
||||
|
||||
### Changed
|
||||
|
||||
- tags are now optionnal
|
||||
|
||||
## [1.6.0] - 2021-01-08
|
||||
|
||||
### Changed
|
||||
|
||||
- Errors are now handled to return `undefined`
|
||||
|
||||
### Removed
|
||||
|
||||
- console.warn when using `getCards`
|
||||
|
||||
## [1.5.0] - 2021-01-08
|
||||
|
||||
### Added
|
||||
|
||||
- getSet can now not transform the API Date to a Javascript Date
|
||||
|
||||
## [1.4.2] - 2021-01-08
|
||||
|
||||
### Added
|
||||
|
||||
- new Tags
|
||||
|
||||
### Changed
|
||||
|
||||
- rarities to have less strange rarities
|
||||
-
|
||||
|
||||
### Fixed
|
||||
|
||||
- CORS blocked
|
||||
|
||||
|
||||
## [1.4.1] - 2020-04-24
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed API url to the new one
|
||||
|
||||
## [1.4.0] - 2020-03-25
|
||||
|
||||
### Added
|
||||
|
||||
- a `defaultLang` static field to customize the default lang
|
||||
- a `getLang` function to get the current lang for the SDK
|
||||
|
||||
### Fixed
|
||||
|
||||
- Warnings for translations
|
||||
|
||||
## [1.3.0] - 2020-03-18
|
||||
|
||||
### Added
|
||||
|
||||
- A cache system
|
||||
- some informations about differents tags on a card
|
||||
- lvl on the card interface
|
||||
|
||||
### Removed
|
||||
|
||||
- cardTypes on the card interface
|
||||
|
||||
## [1.2.1] - 2020-03-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix items datas not in the correct interface
|
||||
|
||||
## [1.2.0] - 2020-03-14
|
||||
|
||||
### Added
|
||||
|
||||
- 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
|
||||
- Added Some informations about cardTypes
|
||||
- Updated DB to add support for items
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix translation not getting the correct file
|
||||
|
||||
|
||||
## [1.0.8] - 2020-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed typing for some interfaces
|
||||
|
||||
## [1.0.1-1.0.7] - 2020-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Renamed the class Name from `TCGDex` to `TCGdex`
|
||||
- lang argument is now public so it can be changed while the SDK is active
|
||||
|
||||
### Added
|
||||
|
||||
- some typing for getCard and translationUtil
|
||||
|
||||
## [1.0.0] - 2020-03-11
|
||||
|
||||
### Added
|
||||
|
||||
- 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
|
||||
|
||||
[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
|
||||
# Changelog
|
||||
|
||||
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/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## 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
|
||||
|
||||
### Fixed
|
||||
|
||||
- Cleaned dist folder
|
||||
|
||||
## 2.3.0-2.3.1 - 2021-06-22
|
||||
|
||||
### Added
|
||||
|
||||
- Browser specialized build
|
||||
- [#9](https://github.com/tcgdex/javascript-sdk/pull/9) Build/Unit/ESLint tests and coverage with Codecov using Github Action
|
||||
|
||||
### Changed
|
||||
|
||||
- [#10](https://github.com/tcgdex/javascript-sdk/pull/10) Simplified Request/Cache manager
|
||||
|
||||
## [2.2.0] - 2021-06-19
|
||||
|
||||
### Added
|
||||
|
||||
- Added new fields
|
||||
|
||||
## [2.1.1] - 2021-05-31
|
||||
|
||||
### Fixed
|
||||
|
||||
- Package building in the wrong version of ECMAScript
|
||||
|
||||
## [2.1.0] - 2021-05-31
|
||||
|
||||
### Added
|
||||
|
||||
- new `fetch` function that manage all the API endpoints
|
||||
|
||||
## [2.0.2-2.0.3] - 2021-05-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- `rotationMark` should have been named `regulationMark`
|
||||
|
||||
## [2.0.1] - 2021-05-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Hardcoded string values are now strings as they depends on the language
|
||||
|
||||
## [2.0.0] - 2021-05-28
|
||||
|
||||
### Added
|
||||
|
||||
- simple string endpoint typing
|
||||
- Typing is exported through the main.d.ts file
|
||||
- `cardCount` field in the set interface
|
||||
- a `rotationMark` to the card interface
|
||||
|
||||
### Changed
|
||||
|
||||
- Support new incoming datas
|
||||
- Point the SDK to the new V2
|
||||
- Renamed `getExpansion(s)` to `getSerie(s)`
|
||||
- Typing for the new SDK
|
||||
- Functions now use `fetch` instead of `get` in their names
|
||||
- URL Normalization is now done by the SDK
|
||||
|
||||
### Removed
|
||||
|
||||
- TranslationUtil as now translation are managed by the API
|
||||
- the interfaces folder as every interfaces are now in `interfaces.d.ts`
|
||||
- `this.gbu`
|
||||
- Translation files as they are now in the Compiler
|
||||
|
||||
## [1.7.0] - 2021-01-31
|
||||
|
||||
### Added
|
||||
|
||||
- new Rarities
|
||||
|
||||
## [1.6.1] - 2021-01-31
|
||||
|
||||
### Changed
|
||||
|
||||
- tags are now optionnal
|
||||
|
||||
## [1.6.0] - 2021-01-08
|
||||
|
||||
### Changed
|
||||
|
||||
- Errors are now handled to return `undefined`
|
||||
|
||||
### Removed
|
||||
|
||||
- console.warn when using `getCards`
|
||||
|
||||
## [1.5.0] - 2021-01-08
|
||||
|
||||
### Added
|
||||
|
||||
- getSet can now not transform the API Date to a Javascript Date
|
||||
|
||||
## [1.4.2] - 2021-01-08
|
||||
|
||||
### Added
|
||||
|
||||
- new Tags
|
||||
|
||||
### Changed
|
||||
|
||||
- rarities to have less strange rarities
|
||||
-
|
||||
|
||||
### Fixed
|
||||
|
||||
- CORS blocked
|
||||
|
||||
|
||||
## [1.4.1] - 2020-04-24
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed API url to the new one
|
||||
|
||||
## [1.4.0] - 2020-03-25
|
||||
|
||||
### Added
|
||||
|
||||
- a `defaultLang` static field to customize the default lang
|
||||
- a `getLang` function to get the current lang for the SDK
|
||||
|
||||
### Fixed
|
||||
|
||||
- Warnings for translations
|
||||
|
||||
## [1.3.0] - 2020-03-18
|
||||
|
||||
### Added
|
||||
|
||||
- A cache system
|
||||
- some informations about differents tags on a card
|
||||
- lvl on the card interface
|
||||
|
||||
### Removed
|
||||
|
||||
- cardTypes on the card interface
|
||||
|
||||
## [1.2.1] - 2020-03-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix items datas not in the correct interface
|
||||
|
||||
## [1.2.0] - 2020-03-14
|
||||
|
||||
### Added
|
||||
|
||||
- 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
|
||||
- Added Some informations about cardTypes
|
||||
- Updated DB to add support for items
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix translation not getting the correct file
|
||||
|
||||
|
||||
## [1.0.8] - 2020-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Changed typing for some interfaces
|
||||
|
||||
## [1.0.1-1.0.7] - 2020-03-11
|
||||
|
||||
### Changed
|
||||
|
||||
- Renamed the class Name from `TCGDex` to `TCGdex`
|
||||
- lang argument is now public so it can be changed while the SDK is active
|
||||
|
||||
### Added
|
||||
|
||||
- some typing for getCard and translationUtil
|
||||
|
||||
## [1.0.0] - 2020-03-11
|
||||
|
||||
### Added
|
||||
|
||||
- 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
|
||||
|
||||
This is the SDK used to communicate with the Open source [TCGdex API](https://www.github.com/tcgdex/cards-database)
|
||||
|
||||
Full API/SDK documentation in progress at https://www.tcgdex.net/docs
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
yarn add @tcgdex/sdk
|
||||
# or
|
||||
npm install @tcgdex/sdk
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
_Note: a complete documentation is in progress_
|
||||
|
||||
```javascript
|
||||
import TCGdex from '@tcgdex/sdk'
|
||||
|
||||
// initialize the SDK
|
||||
const tcgdex = new TCGdex('en') // Lang code (Optionnal) (See interfaces.d.ts line 1 for supported languages)
|
||||
|
||||
// if you need to change the language
|
||||
tcgdex.lang = 'fr'
|
||||
|
||||
// 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')
|
||||
```
|
||||
<p align="center">
|
||||
<a href="http://npmjs.com/@tcgdex/sdk">
|
||||
<img src="https://img.shields.io/npm/v/@tcgdex/sdk?style=flat-square" alt="NOM Version">
|
||||
</a>
|
||||
<a href="http://npmjs.com/@tcgdex/sdk">
|
||||
<img src="https://img.shields.io/npm/dw/@tcgdex/sdk?style=flat-square" alt="NPM Downloads">
|
||||
</a>
|
||||
<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">
|
||||
</a>
|
||||
<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." />
|
||||
</a>
|
||||
<a href="https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md">
|
||||
<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 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>
|
||||
|
||||
# TCGdex JavaScript/TypeScript SDK
|
||||
|
||||
Communicate with the Open Source TCGdex API in Javascript/Typescript using the SDK
|
||||
|
||||
Full API/SDK documentation in progress at https://www.tcgdex.net/docs
|
||||
|
||||
## Getting Started
|
||||
|
||||
Install the SDK using:
|
||||
```bash
|
||||
yarn add @tcgdex/sdk
|
||||
# or
|
||||
npm install @tcgdex/sdk
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
_Note: a complete documentation is in progress_
|
||||
|
||||
```javascript
|
||||
import TCGdex from '@tcgdex/sdk'
|
||||
|
||||
// initialize the SDK
|
||||
const tcgdex = new TCGdex('en') // Lang code (Optionnal) (See interfaces.ts line 1 for supported languages)
|
||||
|
||||
// if you need to change the language
|
||||
tcgdex.lang = 'fr'
|
||||
|
||||
// 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')
|
||||
```
|
||||
|
51
Request.ts
51
Request.ts
@ -1,51 +0,0 @@
|
||||
import fetch from 'isomorphic-unfetch'
|
||||
import pkg from './package.json'
|
||||
|
||||
export default class RequestWrapper {
|
||||
private static cache: Array<Request<any>> = []
|
||||
|
||||
public static getRequest<T>(url: string) {
|
||||
let req = this.cache.find((req) => req.url === url) as Request<T>|undefined
|
||||
if (!req) {
|
||||
req = new Request<T>(url)
|
||||
this.cache.push(req)
|
||||
}
|
||||
return req
|
||||
}
|
||||
}
|
||||
|
||||
export class Request<T = any> {
|
||||
public static ttl = 1000 * 60 * 60 // 1 hour
|
||||
|
||||
private response?: T
|
||||
private fetched?: Date
|
||||
|
||||
public constructor(
|
||||
public url: string // url is public for quick url test
|
||||
) {}
|
||||
|
||||
public async get(): Promise<T | undefined> {
|
||||
const now = new Date()
|
||||
// if reponse was already fetched and TTL was not passed
|
||||
if (
|
||||
this.fetched &&
|
||||
this.response &&
|
||||
now.getTime() - this.fetched.getTime() < Request.ttl
|
||||
) {
|
||||
return this.response
|
||||
}
|
||||
|
||||
// Fetch Response
|
||||
const resp = await fetch(this.url, {
|
||||
headers: {
|
||||
'user-agent': `${pkg.name}/${pkg.version}`
|
||||
}
|
||||
})
|
||||
if (resp.status !== 200) {
|
||||
return undefined
|
||||
}
|
||||
this.response = await resp.json()
|
||||
this.fetched = now
|
||||
return this.response
|
||||
}
|
||||
}
|
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'
|
||||
],
|
||||
};
|
4
main.d.ts
vendored
4
main.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import TCGdex from './tcgdex'
|
||||
export * from './interfaces'
|
||||
|
||||
export default TCGdex
|
15619
package-lock.json
generated
Normal file
15619
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
86
package.json
86
package.json
@ -1,26 +1,60 @@
|
||||
{
|
||||
"name": "@tcgdex/sdk",
|
||||
"version": "2.1.0",
|
||||
"main": "./tcgdex.js",
|
||||
"types": "./main.d.ts",
|
||||
"repository": "https://github.com/tcgdex/javascript-sdk.git",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node-fetch": "^2.5.10",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-unfetch": "^3.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --project tsconfig.json",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"files": [
|
||||
"*.js",
|
||||
"*.d.ts",
|
||||
"**/*.js",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
}
|
||||
{
|
||||
"name": "@tcgdex/sdk",
|
||||
"version": "2.4.1",
|
||||
"main": "./dist/cjs/tcgdex.node.js",
|
||||
"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",
|
||||
"homepage": "https://github.com/tcgdex/javascript-sdk",
|
||||
"author": "Aviortheking",
|
||||
"keywords": [
|
||||
"tcgdex",
|
||||
"pokemon",
|
||||
"trading",
|
||||
"card",
|
||||
"tcg",
|
||||
"sdk",
|
||||
"api",
|
||||
"typescript",
|
||||
"javascript",
|
||||
"typing"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.14.6",
|
||||
"@babel/preset-env": "^7.14.7",
|
||||
"@babel/preset-typescript": "^7.14.5",
|
||||
"@dzeio/config": "^1.0.0",
|
||||
"@types/node-fetch": "^2.5.10",
|
||||
"@typescript-eslint/eslint-plugin": "^4.28.0",
|
||||
"@typescript-eslint/parser": "^4.28.0",
|
||||
"eslint": "^7.29.0",
|
||||
"jest": "^27.0.5",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.1.3",
|
||||
"webpack": "^5.40.0",
|
||||
"webpack-nano": "^1.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"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}))
|
31
src/Request.ts
Normal file
31
src/Request.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import TCGdex from './tcgdex'
|
||||
import { version } from './version.json'
|
||||
|
||||
export default class Request {
|
||||
|
||||
// 1 hour of TTL by default
|
||||
public static ttl = 1000 * 60 * 60
|
||||
|
||||
private static cache: Record<string, {response: any, time: number}> = {}
|
||||
|
||||
public static async fetch<T>(url: string): Promise<T | undefined> {
|
||||
let request = this.cache[url]
|
||||
const now = new Date().getTime()
|
||||
if (!request || now - request.time > this.ttl) {
|
||||
const unfetch = TCGdex.fetch
|
||||
const resp = await unfetch(url, {
|
||||
headers: {
|
||||
'user-agent': `@tcgdex/javascript-sdk/${version}`
|
||||
}
|
||||
})
|
||||
if (resp.status !== 200) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
this.cache[url] = { response: await resp.json(), time: now }
|
||||
request = this.cache[url]
|
||||
}
|
||||
return request.response
|
||||
}
|
||||
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
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>>
|
||||
|
||||
interface SerieResume {
|
||||
export interface SerieResume {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
@ -22,20 +25,22 @@ export type SetList = Array<SetResume>
|
||||
export type SerieList = Array<SerieResume>
|
||||
export type CardList = Array<CardResume>
|
||||
|
||||
interface SetResume {
|
||||
export interface SetResume {
|
||||
id: string
|
||||
name: string
|
||||
logo?: string
|
||||
symbol?: string
|
||||
cardCount: {
|
||||
|
||||
/**
|
||||
* total of number of cards
|
||||
*/
|
||||
total: number
|
||||
/**
|
||||
total: number
|
||||
|
||||
/**
|
||||
* number of cards officialy (on the bottom of each cards)
|
||||
*/
|
||||
official: number
|
||||
official: number
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,32 +51,52 @@ export interface Set extends SetResume {
|
||||
|
||||
releaseDate: string
|
||||
|
||||
legal?: {
|
||||
/**
|
||||
* Designate if the set is usable in tournaments
|
||||
*
|
||||
* Note: this is specific to the set and if a
|
||||
* card is banned from the set it will still be true
|
||||
*/
|
||||
legal: {
|
||||
|
||||
/**
|
||||
* Ability to play in standard tournaments
|
||||
*/
|
||||
standard: boolean
|
||||
|
||||
/**
|
||||
* Ability to play in expanded tournaments
|
||||
*/
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
cardCount: {
|
||||
|
||||
/**
|
||||
* total of number of cards
|
||||
*/
|
||||
total: number
|
||||
|
||||
/**
|
||||
* number of cards officialy (on the bottom of each cards)
|
||||
*/
|
||||
official: number
|
||||
|
||||
/**
|
||||
* number of cards having a normal version
|
||||
*/
|
||||
normal: number
|
||||
|
||||
/**
|
||||
* number of cards having an reverse version
|
||||
*/
|
||||
reverse: number
|
||||
|
||||
/**
|
||||
* number of cards having an holo version
|
||||
*/
|
||||
holo: number
|
||||
|
||||
/**
|
||||
* Number of possible cards
|
||||
*/
|
||||
@ -81,7 +106,7 @@ export interface Set extends SetResume {
|
||||
cards: CardList
|
||||
}
|
||||
|
||||
interface CardResume {
|
||||
export interface CardResume {
|
||||
id: string
|
||||
localId: string
|
||||
|
||||
@ -146,8 +171,9 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -244,7 +270,7 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
||||
|
||||
retreat?: number
|
||||
|
||||
//Trainer/Energy
|
||||
// Trainer/Energy
|
||||
effect?: string
|
||||
|
||||
// Trainer Only
|
||||
@ -257,6 +283,24 @@ export interface Card<SetType extends SetResume = SetResume> extends CardResume
|
||||
* Define the rotation mark on cards >= Sword & Shield
|
||||
*/
|
||||
regulationMark?: string
|
||||
|
||||
/**
|
||||
* Card ability to be played in official tournaments
|
||||
*
|
||||
* Note: all cards are avaialable to play in unlimited tournaments
|
||||
*/
|
||||
legal: {
|
||||
|
||||
/**
|
||||
* Ability to play in standard tournaments
|
||||
*/
|
||||
standard: boolean
|
||||
|
||||
/**
|
||||
* Ability to play in expanded tournaments
|
||||
*/
|
||||
expanded: boolean
|
||||
}
|
||||
}
|
||||
|
||||
export type StringEndpointList = Array<string>
|
6
src/tcgdex.browser.ts
Normal file
6
src/tcgdex.browser.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import TCGdex from './tcgdex'
|
||||
import unfetch from 'unfetch'
|
||||
|
||||
TCGdex.fetch = window.fetch ?? unfetch as any
|
||||
|
||||
module.exports = TCGdex
|
7
src/tcgdex.node.ts
Normal file
7
src/tcgdex.node.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import TCGdex from './tcgdex'
|
||||
import fetch from 'isomorphic-unfetch'
|
||||
|
||||
TCGdex.fetch = fetch as any
|
||||
|
||||
export default TCGdex
|
||||
export * from './tcgdex'
|
@ -1,20 +1,21 @@
|
||||
import RequestWrapper from './Request'
|
||||
import { Serie, Set, Card, CardResume, SerieList, SetList, SupportedLanguages, StringEndpoint } from './interfaces'
|
||||
|
||||
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 BASE_URL = 'https://api.tcgdex.net/v2'
|
||||
|
||||
export default class TCGdex {
|
||||
|
||||
public static fetch: typeof fetch
|
||||
|
||||
/**
|
||||
* @deprecated to change the lang use `this.lang`
|
||||
*/
|
||||
public static defaultLang: SupportedLanguages = "en"
|
||||
public static defaultLang: SupportedLanguages = 'en'
|
||||
|
||||
public constructor(public lang?: SupportedLanguages) {}
|
||||
|
||||
public getLang() {
|
||||
public getLang(): SupportedLanguages {
|
||||
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ export default class TCGdex {
|
||||
/**
|
||||
* @deprecated use `this.fetch('sets', set)`
|
||||
*/
|
||||
public async fetchSet(set: string) {
|
||||
public async fetchSet(set: string): Promise<Set | undefined> {
|
||||
return this.fetch('sets', set)
|
||||
}
|
||||
|
||||
@ -83,11 +84,13 @@ export default class TCGdex {
|
||||
* @param endpoint_1 {string} the card global ID
|
||||
*/
|
||||
public async fetch(...type: ['cards', string]): Promise<Card | undefined>
|
||||
|
||||
/**
|
||||
* Fetch every cards in the database
|
||||
* @param endpoint_0 'cards'
|
||||
*/
|
||||
public async fetch(type: 'cards'): Promise<Array<CardResume> | undefined>
|
||||
|
||||
/**
|
||||
* Fetch a card using its local id and its set
|
||||
* @param endpoint_0 'sets'
|
||||
@ -95,28 +98,33 @@ export default class TCGdex {
|
||||
* @param endpoint_2 {string} the card local ID
|
||||
*/
|
||||
public async fetch(...endpoint: ['sets', string, string]): Promise<Card | undefined>
|
||||
|
||||
/**
|
||||
* Fetch a set
|
||||
* @param endpoint_0 'sets'
|
||||
* @param endpoint_1 {string} the set name or ID
|
||||
*/
|
||||
public async fetch(...endpoint: ['sets', string]): Promise<Set | undefined>
|
||||
|
||||
/**
|
||||
* Fetch every sets
|
||||
* @param endpoint_0 'sets'
|
||||
*/
|
||||
public async fetch(endpoint: 'sets'): Promise<SetList | undefined>
|
||||
|
||||
/**
|
||||
* Fetch a serie
|
||||
* @param endpoint_0 'series'
|
||||
* @param endpoint_1 {string} the serie name or ID
|
||||
*/
|
||||
public async fetch(...endpoint: ['series', string]): Promise<Serie | undefined>
|
||||
|
||||
/**
|
||||
* Fetch every series
|
||||
* @param endpoint_0 'series'
|
||||
*/
|
||||
public async fetch(endpoint: 'series'): Promise<SerieList | undefined>
|
||||
|
||||
/**
|
||||
* Fetch cards depending on a specific filter
|
||||
* @param endpoint_0 {'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'}
|
||||
@ -124,6 +132,7 @@ export default class TCGdex {
|
||||
* @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>
|
||||
|
||||
/**
|
||||
* Fetch cards depending on a specific filter
|
||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
||||
@ -131,9 +140,17 @@ export default class TCGdex {
|
||||
* @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>
|
||||
|
||||
/**
|
||||
* Fetch The differents endpoints depending on the first argument
|
||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | '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_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> {
|
||||
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
|
||||
const baseEndpoint = endpoint.shift().toLowerCase() as Endpoint
|
||||
@ -148,8 +165,8 @@ export default class TCGdex {
|
||||
*/
|
||||
private makeRequest<T = any>(...url: Array<string | number>) {
|
||||
// Normalize path
|
||||
const path = url.map((v) => encodeURI(
|
||||
v
|
||||
const path = url.map((subPath) => encodeURI(
|
||||
subPath
|
||||
// Transform numbers to string
|
||||
.toString()
|
||||
// replace this special character with an escaped one
|
||||
@ -157,8 +174,12 @@ export default class TCGdex {
|
||||
// normalize the string
|
||||
.normalize('NFC')
|
||||
// remove some special chars by nothing
|
||||
.replace(/["'\u0300-\u036f]/g, "")
|
||||
// eslint-disable-next-line no-misleading-character-class
|
||||
.replace(/["'\u0300-\u036f]/gu, '')
|
||||
)).join('/')
|
||||
return RequestWrapper.getRequest<T>(`${BASE_URL}/${this.getLang()}/${path}`).get()
|
||||
return RequestWrapper.fetch<T>(`${BASE_URL}/${this.getLang()}/${path}`)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export * from './interfaces'
|
11
tsconfig.es2015.json
Normal file
11
tsconfig.es2015.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["./src/tcgdex.node.ts"],
|
||||
"compilerOptions": {
|
||||
"target": "ES2020", /* 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'. */
|
||||
"declaration": false, /* Generates corresponding '.d.ts' file. */
|
||||
"declarationDir": null,
|
||||
"outDir": "./dist/modules", /* Redirect output structure to the directory. */
|
||||
}
|
||||
}
|
@ -1,67 +1,13 @@
|
||||
{
|
||||
"include": ["**/*.ts"],
|
||||
"exclude": ["translations"],
|
||||
"extends": "./node_modules/@dzeio/config/tsconfig.base",
|
||||
"include": ["./src/tcgdex.node.ts"],
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ESNext", /* 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": "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": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* 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 */
|
||||
"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,
|
||||
"declaration": true,
|
||||
"declarationDir": "./dist/types",
|
||||
|
||||
"resolveJsonModule": true,
|
||||
/* Module Resolution Options */
|
||||
// "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. */
|
||||
"outDir": "./dist/cjs",
|
||||
"rootDir": "./src",
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "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. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
webpack.config.js
Normal file
34
webpack.config.js
Normal file
@ -0,0 +1,34 @@
|
||||
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'
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
156
yarn.lock
156
yarn.lock
@ -1,156 +0,0 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@tsconfig/node10@^1.0.7":
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.7.tgz#1eb1de36c73478a2479cc661ef5af1c16d86d606"
|
||||
integrity sha512-aBvUmXLQbayM4w3A8TrjwrXs4DZ8iduJnuJLLRGdkWlyakCf1q6uHZJBzXoRA/huAEknG5tcUyQxN3A+In5euQ==
|
||||
|
||||
"@tsconfig/node12@^1.0.7":
|
||||
version "1.0.7"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.7.tgz#677bd9117e8164dc319987dd6ff5fc1ba6fbf18b"
|
||||
integrity sha512-dgasobK/Y0wVMswcipr3k0HpevxFJLijN03A8mYfEPvWvOs14v0ZlYTR4kIgMx8g4+fTyTFv8/jLCIfRqLDJ4A==
|
||||
|
||||
"@tsconfig/node14@^1.0.0":
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.0.tgz#5bd046e508b1ee90bc091766758838741fdefd6e"
|
||||
integrity sha512-RKkL8eTdPv6t5EHgFKIVQgsDapugbuOptNd9OOunN/HAkzmmTnZELx1kNCK0rSdUYGmiFMM3rRQMAWiyp023LQ==
|
||||
|
||||
"@tsconfig/node16@^1.0.1":
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1"
|
||||
integrity sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA==
|
||||
|
||||
"@types/node-fetch@^2.5.10":
|
||||
version "2.5.10"
|
||||
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.10.tgz#9b4d4a0425562f9fcea70b12cb3fcdd946ca8132"
|
||||
integrity sha512-IpkX0AasN44hgEad0gEF/V6EgR5n69VEqPEgnmoM8GsIGro3PowbWs4tR6IhxUTyPLpOn+fiGG6nrQhcmoCuIQ==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
form-data "^3.0.0"
|
||||
|
||||
"@types/node@*":
|
||||
version "15.6.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.6.1.tgz#32d43390d5c62c5b6ec486a9bc9c59544de39a08"
|
||||
integrity sha512-7EIraBEyRHEe7CH+Fm1XvgqU6uwZN8Q7jppJGcqjROMT29qhAuuOxYB1uEY5UMYQKEmA5D+5tBnhdaPXSsLONA==
|
||||
|
||||
arg@^4.1.0:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||
|
||||
asynckit@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
|
||||
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
|
||||
|
||||
buffer-from@^1.0.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
|
||||
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
|
||||
|
||||
combined-stream@^1.0.8:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
|
||||
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
|
||||
dependencies:
|
||||
delayed-stream "~1.0.0"
|
||||
|
||||
create-require@^1.1.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
|
||||
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619"
|
||||
integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk=
|
||||
|
||||
diff@^4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
||||
|
||||
form-data@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
|
||||
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
|
||||
dependencies:
|
||||
asynckit "^0.4.0"
|
||||
combined-stream "^1.0.8"
|
||||
mime-types "^2.1.12"
|
||||
|
||||
isomorphic-unfetch@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/isomorphic-unfetch/-/isomorphic-unfetch-3.1.0.tgz#87341d5f4f7b63843d468438128cb087b7c3e98f"
|
||||
integrity sha512-geDJjpoZ8N0kWexiwkX8F9NkTsXhetLPVbZFQ+JTW239QNOwvB0gniuR1Wc6f0AMTn7/mFGyXvHTifrCp/GH8Q==
|
||||
dependencies:
|
||||
node-fetch "^2.6.1"
|
||||
unfetch "^4.2.0"
|
||||
|
||||
make-error@^1.1.1:
|
||||
version "1.3.6"
|
||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
|
||||
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
|
||||
|
||||
mime-db@1.47.0:
|
||||
version "1.47.0"
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.47.0.tgz#8cb313e59965d3c05cfbf898915a267af46a335c"
|
||||
integrity sha512-QBmA/G2y+IfeS4oktet3qRZ+P5kPhCKRXxXnQEudYqUaEioAU1/Lq2us3D/t1Jfo4hE9REQPrbB7K5sOczJVIw==
|
||||
|
||||
mime-types@^2.1.12:
|
||||
version "2.1.30"
|
||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.30.tgz#6e7be8b4c479825f85ed6326695db73f9305d62d"
|
||||
integrity sha512-crmjA4bLtR8m9qLpHvgxSChT+XoSlZi8J4n/aIdn3z92e/U47Z0V/yl+Wh9W046GgFVAmoNR/fmdbZYcSSIUeg==
|
||||
dependencies:
|
||||
mime-db "1.47.0"
|
||||
|
||||
node-fetch@^2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
|
||||
source-map-support@^0.5.17:
|
||||
version "0.5.19"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
|
||||
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
|
||||
dependencies:
|
||||
buffer-from "^1.0.0"
|
||||
source-map "^0.6.0"
|
||||
|
||||
source-map@^0.6.0:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||
|
||||
ts-node@^10.0.0:
|
||||
version "10.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
|
||||
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
|
||||
dependencies:
|
||||
"@tsconfig/node10" "^1.0.7"
|
||||
"@tsconfig/node12" "^1.0.7"
|
||||
"@tsconfig/node14" "^1.0.0"
|
||||
"@tsconfig/node16" "^1.0.1"
|
||||
arg "^4.1.0"
|
||||
create-require "^1.1.0"
|
||||
diff "^4.0.1"
|
||||
make-error "^1.1.1"
|
||||
source-map-support "^0.5.17"
|
||||
yn "3.1.1"
|
||||
|
||||
typescript@^4.1.3:
|
||||
version "4.3.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
|
||||
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==
|
||||
|
||||
unfetch@^4.2.0:
|
||||
version "4.2.0"
|
||||
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.2.0.tgz#7e21b0ef7d363d8d9af0fb929a5555f6ef97a3be"
|
||||
integrity sha512-F9p7yYCn6cIW9El1zi0HI6vqpeIvBsr3dSuRO6Xuppb1u5rXpCPmMvLSyECLhybr9isec8Ohl0hPekMVrEinDA==
|
||||
|
||||
yn@3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
|
||||
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
|
Reference in New Issue
Block a user