mirror of
https://github.com/tcgdex/javascript-sdk.git
synced 2025-07-13 02:25:10 +00:00
Compare commits
90 Commits
v2.4.4
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
3f865e1895 | |||
f5dd4cb88c | |||
9b9ff2f028 | |||
ce64a95f4e | |||
460f101026 | |||
b3ba7820a3
|
|||
1f3aae5401 | |||
e501faa823 | |||
e08fd98269 | |||
54a4b729b3 | |||
26af3b0779 | |||
bf54ab3809 | |||
f2621890e1 | |||
4364da480f | |||
0cc8577fe0 | |||
0f2ad36e8c | |||
74de8961ef | |||
98c80fcd20 | |||
c392b27cac | |||
dc5e41a638 | |||
09d8b28a66
|
|||
4507bbd651
|
|||
8a89aefe73 | |||
8df969c1db
|
|||
2177e9c088 | |||
a32f42975a | |||
0148979d7d
|
|||
ea357c9080
|
|||
5e998d3658
|
|||
ed883c06eb | |||
1ecaa048eb | |||
39cd15ead3 | |||
ca5ae0aa57 | |||
cffae6cc28 | |||
5e03f38476 | |||
05134f5b12 | |||
8a0dec867e | |||
75636a9195 | |||
bd33dafe8a | |||
39fb14070d | |||
6ae3b09dc9 | |||
8d13d1dba4 | |||
840c8c3106 | |||
ee4f1be353 | |||
7e4c0eae42 | |||
3d08ab4bfa | |||
3441cc2c60 | |||
9b2e09d766 | |||
3ebde59a84 | |||
e18cbabf70 | |||
1c6c7dacc4 | |||
445b3a5ea6 | |||
7148fc7522 | |||
cde8b24230 | |||
1d21ff650e | |||
749fba9878 | |||
4895c5b857 | |||
eda53611b2 | |||
76ab92a7db | |||
585d893557 | |||
157c27222e | |||
026d4018f8 | |||
ccfae56ced | |||
87be749603 | |||
f56e977900 | |||
e5550e474e | |||
a7c24353a2 | |||
2e5fdd45e4 | |||
2ab0df81c1 | |||
5fbfa4d84a | |||
693160865c | |||
0e735f3a77 | |||
b97dfb4420 | |||
c18f933e40 | |||
fb60710e5e | |||
edf994c241 | |||
eb905a866a | |||
5f41185d4f | |||
183efdb51e | |||
dbad45d71d | |||
f733634499 | |||
9e636c407e | |||
87531f14ff | |||
52342f9dcf | |||
2eb68457f0 | |||
14b4aa7138 | |||
496c04fc4c
|
|||
3d8ef329f7 | |||
21088c4a02 | |||
4fdde0a962 |
3
.github/FUNDING.yml
vendored
Normal file
3
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [tcgdex]
|
32
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
32
.github/ISSUE_TEMPLATE/bug.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: Bug
|
||||
description: Use this template if you have found a bug in the SDK
|
||||
title: "bug: "
|
||||
labels: [bug]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this Form!
|
||||
- type: textarea
|
||||
id: happening
|
||||
attributes:
|
||||
label: What is Hapening
|
||||
placeholder: "Ex: When using this function the SDK crash..."
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: happen
|
||||
attributes:
|
||||
label: Please explain what should happen
|
||||
description: If you selected Other or new Data Type please put it as the first line
|
||||
placeholder: "Ex: The SDK should not crash"
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproducre
|
||||
attributes:
|
||||
label: Please give us a way to reproduce
|
||||
description: You can list a way or give us access to a minimal Github repo to reproduce it
|
||||
placeholder: "Ex: https://github.com/tcgdex/javascript-sdk-error-idk"
|
||||
validations:
|
||||
required: true
|
16
.github/ISSUE_TEMPLATE/enhancement.yml
vendored
Normal file
16
.github/ISSUE_TEMPLATE/enhancement.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
name: Enhancement
|
||||
description: Use this template if you have an Idea that will enhance the SDK
|
||||
title: "enhancement: "
|
||||
labels: [enhancement]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this Form!
|
||||
- type: textarea
|
||||
id: explain
|
||||
attributes:
|
||||
label: Please explain in more details what idea you have
|
||||
placeholder: "Ex: I would love to see this or this..."
|
||||
validations:
|
||||
required: true
|
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
5
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
<!--
|
||||
Thanks for your Pull Request, Please provide the related Issue using "Fix #0" or describe the change(s) you made.
|
||||
The issue title must follow Conventional Commit (verified by Github Actions) conventionalcommits.org.
|
||||
More informations at https://github.com/tcgdex/cards-database/blob/master/CONTRIBUTING.md
|
||||
-->
|
22
.github/dependabot.yml
vendored
Normal file
22
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
versioning-strategy: lockfile-only
|
||||
commit-message:
|
||||
prefix: build
|
||||
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
commit-message:
|
||||
prefix: build
|
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
@ -14,18 +14,20 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# Follow current releases https://nodejs.org/en/about/releases/
|
||||
node-version: [12.x, 14.x, 16.x]
|
||||
# Follow current releases https://github.com/nodejs/release#release-schedule
|
||||
node-version: [18.x, 20.x, 21.x, 22.x]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
@ -37,8 +39,8 @@ jobs:
|
||||
run: npm run test
|
||||
|
||||
- name: Upload Coverage
|
||||
if: matrix.node-version == '16.x'
|
||||
uses: codecov/codecov-action@v1.0.13
|
||||
if: matrix.node-version == '22.x'
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
# Comma-separated list of files to upload
|
||||
files: ./coverage/coverage-final.json
|
||||
|
4
.github/workflows/code-quality.yml
vendored
4
.github/workflows/code-quality.yml
vendored
@ -12,10 +12,10 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v2
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '16.x'
|
||||
|
||||
|
29
.github/workflows/publish.yml
vendored
29
.github/workflows/publish.yml
vendored
@ -1,19 +1,22 @@
|
||||
name: publish
|
||||
name: Publish the Package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+*'
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
build:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v2
|
||||
- name: Setup Publishing to NPMJS
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '16.x'
|
||||
node-version: '20.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Install dependencies
|
||||
@ -22,7 +25,17 @@ jobs:
|
||||
- name: Build
|
||||
run: npm run build
|
||||
|
||||
- name: Publish
|
||||
- name: Publish on NPM
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Setup Publishing to Github Packages
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
registry-url: 'https://npm.pkg.github.com'
|
||||
|
||||
- name: Publish on Github
|
||||
run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.REPO_TOKEN }}
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,4 +5,4 @@ coverage
|
||||
|
||||
# Dist files
|
||||
dist
|
||||
src/version.json
|
||||
src/version.js
|
||||
|
48
CHANGELOG.md
48
CHANGELOG.md
@ -7,6 +7,54 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## 2.5.1 - 2023-07-18
|
||||
|
||||
### Fixed
|
||||
|
||||
- ModuleJS exports not working as intended
|
||||
|
||||
## 2.5.0 - 2023-06-28
|
||||
|
||||
### Added
|
||||
|
||||
- Support for both ModuleJS and CommonJS
|
||||
|
||||
## 2.4.9 - 2022-09-26
|
||||
|
||||
### Fixed
|
||||
|
||||
- package not loading on browser
|
||||
|
||||
## 2.4.8 - 2022-09-26
|
||||
|
||||
### Fixed
|
||||
|
||||
- fix version number not correctly exposting
|
||||
|
||||
## 2.4.7 - 2022-09-26
|
||||
|
||||
### Fixed
|
||||
|
||||
- Compatibility with Angular
|
||||
|
||||
## 2.4.6 - 2022-01-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- Updated node-fetch for CVE-2022-0235
|
||||
|
||||
## 2.4.5 - 2021-10-11
|
||||
|
||||
### Added
|
||||
|
||||
- Added new endpoint
|
||||
|
||||
## 2.4.4 - 2021-08-12
|
||||
|
||||
### Added
|
||||
|
||||
- New logo field in serie
|
||||
|
||||
## 2.4.3 - 2021-07-19
|
||||
|
||||
### Added
|
||||
|
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,128 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, religion, or sexual identity
|
||||
and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the
|
||||
overall community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or
|
||||
advances of any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email
|
||||
address, without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
the `contact@tcgdex.net` email or on Discord to `Avior#3872`.
|
||||
All complaints will be reviewed and investigated promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series
|
||||
of actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or
|
||||
permanent ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within
|
||||
the community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.0, available at
|
||||
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||
|
||||
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||
enforcement ladder](https://github.com/mozilla/diversity).
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
https://www.contributor-covenant.org/faq. Translations are available at
|
||||
https://www.contributor-covenant.org/translations.
|
191
CONTRIBUTING.md
Normal file
191
CONTRIBUTING.md
Normal file
@ -0,0 +1,191 @@
|
||||
<!-- omit in toc -->
|
||||
|
||||
# Contributing to TCGdex
|
||||
|
||||
First off, thanks for taking the time to contribute! ❤️
|
||||
|
||||
All types of contributions are encouraged and valued. See the [Table of Contents](#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions. 🎉
|
||||
|
||||
> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
|
||||
>
|
||||
> - Star the project
|
||||
> - Tweet about it
|
||||
> - Refer this project in your project's readme
|
||||
> - Mention the project at local meetups and tell your friends/colleagues
|
||||
<!-- omit in toc -->
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Code of Conduct](#code-of-conduct)
|
||||
- [I Have a Question](#i-have-a-question)
|
||||
- [I Want To Contribute](#i-want-to-contribute)
|
||||
- [Reporting Issues](#reporting-issues)
|
||||
- [Suggesting Enhancements](#suggesting-enhancements)
|
||||
- [Your First Code Contribution](#your-first-code-contribution)
|
||||
- [Improving The Documentation](#improving-the-documentation)
|
||||
- [Styleguides](#styleguides)
|
||||
- [Coding Guidlines](#coding-guidelines)
|
||||
- [Commit Messages](#commit-messages)
|
||||
- [Join The Project Team](#join-the-project-team)
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project and everyone participating in it is governed by the
|
||||
[TCGdex Code of Conduct](https://github.com/tcgdex/javascript-sdk/blob/master/CODE_OF_CONDUCT.md).
|
||||
By participating, you are expected to uphold this code. Please report unacceptable behavior to <contact@tcgdex.net>.
|
||||
|
||||
## I Have a Question
|
||||
|
||||
> If you want to ask a question, we assume that you have read the available Documentation at <https://www.tcgdex.dev>.
|
||||
The best way to ask questions is to join our Discord server at <https://discord.gg/NehYTAhsZE>.
|
||||
|
||||
You can also ask them on the Github Repository, it is best to search for existing [Issues](https://github.com/tcgdex/javascript-sdk/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in a new issue. It is also advisable to search the internet for answers first.
|
||||
|
||||
If you then still feel the need to ask a question and need clarification, we recommend the following:
|
||||
|
||||
- Open an [Issue](https://github.com/tcgdex/javascript-sdk/issues/new).
|
||||
- Provide as much context as you can about what you're running into.
|
||||
- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
|
||||
|
||||
We will then take care of the issue as soon as possible.
|
||||
|
||||
<!--
|
||||
You might want to create a separate issue tag for questions and include it in this description. People should then tag their issues accordingly.
|
||||
Depending on how large the project is, you may want to outsource the questioning, e.g. to Stack Overflow or Gitter. You may add additional contact and information possibilities:
|
||||
- IRC
|
||||
- Slack
|
||||
- Gitter
|
||||
- Stack Overflow tag
|
||||
- Blog
|
||||
- FAQ
|
||||
- Roadmap
|
||||
- E-Mail List
|
||||
- Forum
|
||||
-->
|
||||
|
||||
## I Want To Contribute
|
||||
|
||||
> ### Legal Notice <!-- omit in toc -->
|
||||
>
|
||||
> When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
|
||||
### Reporting Issues
|
||||
|
||||
<!-- omit in toc -->
|
||||
|
||||
#### Before Submitting an Issue Report
|
||||
|
||||
A good issue report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.
|
||||
|
||||
- Determine if your issue is not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://www.tcgdex.dev). If you are looking for support, you might want to check [this section](#i-have-a-question)).
|
||||
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already an issue report existing for your bug or error in the [bug tracker](https://github.com/tcgdex/javascript-sdk/issues).
|
||||
- Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
|
||||
- Collect information about the bug:
|
||||
- Stack trace (Traceback)
|
||||
- OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
|
||||
- Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
|
||||
- Possibly your input and the output
|
||||
- Can you reliably reproduce the issue? And can you also reproduce it with older versions?
|
||||
|
||||
<!-- omit in toc -->
|
||||
|
||||
#### How Do I Submit a Good Bug Report?
|
||||
|
||||
> You must never report security related issues, vulnerabilities or bugs to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to <security@tcgdex.net>.
|
||||
<!-- You may add a PGP key to allow the messages to be sent encrypted as well. -->
|
||||
|
||||
We use GitHub issues to track bugs and errors. If you run into an issue with the project:
|
||||
|
||||
- Open an [Issue](https://github.com/tcgdex/javascript-sdk/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
|
||||
- Explain the behavior you would expect and the actual behavior.
|
||||
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
|
||||
- Provide the information you collected in the previous section.
|
||||
|
||||
Once it's filed:
|
||||
|
||||
- The project team will label the issue accordingly.
|
||||
- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced.
|
||||
- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](#your-first-code-contribution).
|
||||
|
||||
<!-- You might want to create an issue template for bugs and errors that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
|
||||
|
||||
### Suggesting Enhancements
|
||||
|
||||
This section guides you through submitting an enhancement suggestion for TCGdex, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions.
|
||||
|
||||
<!-- omit in toc -->
|
||||
|
||||
#### Before Submitting an Enhancement
|
||||
|
||||
- Make sure that you are using the latest version.
|
||||
- Read the [documentation](https://www.tcgdex.dev) carefully and find out if the functionality is already covered, maybe by an individual configuration.
|
||||
- Perform a [search](https://github.com/tcgdex/javascript-sdk/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
|
||||
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
|
||||
|
||||
<!-- omit in toc -->
|
||||
|
||||
#### How Do I Submit a Good Enhancement Suggestion?
|
||||
|
||||
Enhancement suggestions are tracked as [GitHub issues](https://github.com/tcgdex/javascript-sdk/issues).
|
||||
|
||||
- Use a **clear and descriptive title** for the issue to identify the suggestion.
|
||||
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
|
||||
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
|
||||
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux. <!-- this should only be included if the project has a GUI -->
|
||||
- **Explain why this enhancement would be useful** to most TCGdex users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
|
||||
|
||||
<!-- You might want to create an issue template for enhancement suggestions that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
|
||||
|
||||
### Your First Code Contribution
|
||||
|
||||
_note: Follow the different styleguides listed below when contributing_
|
||||
|
||||
- Fork 🍴 the project. _see the `fork` button at the top right of the screen_
|
||||
- make the changes you want in your repository.
|
||||
- Create a Pull request here https://github.com/tcgdex/javascript-sdk/compare by selecting your repository patch with our `master` branch _If it's not finished put WIP: before_
|
||||
- we don't like ❌, so if your pull request has its automated checks ending with the red cross, please double check your changes until it show the awesome 🟢, or ask for help !
|
||||
- If your pull request is ready for review remove WIP: put it s ready for review and we will handle the rest !
|
||||
|
||||
### Improving The Documentation
|
||||
|
||||
The documentation is updated in the Documentation repository at <https://github.com/tcgdex/documentation>
|
||||
|
||||
## Styleguides
|
||||
|
||||
### Coding Guidelines
|
||||
|
||||
Install the plugin `.editorconfig` in your dev environment if it's not already done and thats it !
|
||||
|
||||
for those who don't want to install it the basic are these:
|
||||
- Respect PSR12
|
||||
|
||||
### Commit Messages
|
||||
|
||||
We follow the [Conventional Commit specification](conventionalcommits.org) and are using the [Angular format](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit) with some changes.
|
||||
|
||||
In short, please name your Pull Requests/Commits following this format
|
||||
```
|
||||
<type>(<scope>): <short summary>
|
||||
<BLANK LINE>
|
||||
<body>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
- `type` MUST be one of
|
||||
- build: Changes affecting the CI at `.github/workflows` or `Dockerfile`
|
||||
- ci: same as build
|
||||
- docs: Changes affecting the differents Documents
|
||||
- feat: a new feature being added
|
||||
- fix: fixes
|
||||
- pref: Performance related fixes
|
||||
- refactor: Misc code changes
|
||||
- test: same as `ci`
|
||||
- the field `(<scope>)` is optional
|
||||
- `short summary` MUST follow thoses rules
|
||||
- Capitalize the first letter
|
||||
- use the imperative, present tense: "Change" not "Changed" nor "Changes"
|
||||
- `<footer>` and `<body>` are both optional
|
||||
|
||||
## Attribution
|
||||
|
||||
This guide is based on [Contribution Gen]((https://github.com/bttger/contributing-gen)) and was adapted by the TCGdex community !
|
235
README.md
235
README.md
@ -1,78 +1,157 @@
|
||||
<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/actions/workflows/build.yml">
|
||||
<img src="https://img.shields.io/github/workflow/status/tcgdex/javascript-sdk/Build%20&%20Test?style=flat-square" alt="the TCGdex JAvascript SDK is released under the MIT license." />
|
||||
</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
|
||||
```
|
||||
|
||||
or in the web browser
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2/dist/tcgdex.browser.js"></script>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
_Note: a complete documentation is in progress_
|
||||
|
||||
```javascript
|
||||
// only if using with NPM/Yarn
|
||||
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')
|
||||
```
|
||||
<p align="center">
|
||||
<a href="https://www.tcgdex.net">
|
||||
<img src="https://www.tcgdex.net/assets/og.png" width="90%" alt="TCGdex Main Image">
|
||||
</a>
|
||||
</p>
|
||||
<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/dm/@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/stargazers">
|
||||
<img src="https://img.shields.io/github/stars/tcgdex/javascript-sdk?style=flat-square" alt="Github stars">
|
||||
</a>
|
||||
<a href="https://github.com/tcgdex/javascript-sdk/actions/workflows/build.yml">
|
||||
<img src="https://img.shields.io/github/actions/workflow/status/tcgdex/javascript-sdk/build.yml?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
|
||||
|
||||
The Javascript/Typescript SDK provides a convenient access with the Open Source TCGdex API.
|
||||
|
||||
The SDK is available in ESM and CommonJS and should be automaticly chosen.
|
||||
|
||||
## Documentation
|
||||
|
||||
_The full API/SDK documentation in progress at [API Documentation - TCGdex](https://www.tcgdex.dev)_
|
||||
|
||||
### Getting Started
|
||||
|
||||
#### How To install
|
||||
|
||||
**In the browser**
|
||||
|
||||
To use the SDK in the browser, simply add the following script tag to your
|
||||
HTML pages:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2/dist/tcgdex.browser.js"></script>
|
||||
```
|
||||
|
||||
You cna also download the script from [JSDelivr](https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2/dist/tcgdex.browser.js) by right clicking the link and selecting save link as.
|
||||
|
||||
**In Node.js**
|
||||
|
||||
Simply type the following into a terminal window:
|
||||
|
||||
```bash
|
||||
npm install @tcgdex/sdk
|
||||
```
|
||||
|
||||
#### Usage
|
||||
|
||||
_Note: a complete documentation is available at [TCGdex.dev](https://www.tcgdex.dev)_
|
||||
|
||||
**Example: Fetch a Card**
|
||||
|
||||
_in Browser_
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/@tcgdex/sdk@2.4.9/dist/tcgdex.browser.js"></script>
|
||||
<script>
|
||||
// Instantiate the SDK
|
||||
const tcgdex = new TCGdex('en');
|
||||
|
||||
// go into an async context
|
||||
;(async () => {
|
||||
// Card will be Furret from the Darkness Ablaze Set
|
||||
const card = await tcgdex.fetch('cards', 'swsh3-136');
|
||||
})();
|
||||
</script>
|
||||
```
|
||||
|
||||
_in NodeJS (in an async context)_
|
||||
|
||||
```typescript
|
||||
// Import the SDK in Typescript or moduleJS
|
||||
import TCGdex from '@tcgdex/sdk'
|
||||
|
||||
// import the SDK in commonJS
|
||||
const TCGdex = require('@tcgdex/sdk').default
|
||||
|
||||
// Instantiate the SDK
|
||||
const tcgdex = new TCGdex('en');
|
||||
|
||||
// go into an async context
|
||||
(async () => {
|
||||
// Card will be Furret from the Darkness Ablaze Set
|
||||
const card = await tcgdex.fetch('cards', 'swsh3-136');
|
||||
|
||||
// You can also get the same result using
|
||||
const card = await tcgdex.fetch('sets', 'Darkness Ablaze', 136);
|
||||
})();
|
||||
|
||||
```
|
||||
|
||||
**Other Examples**
|
||||
|
||||
```javascript
|
||||
// fetch a Set's informations using the set's name or ID
|
||||
await tcgdex.fetch('sets', 'Darkness Ablaze')
|
||||
|
||||
// Fetch a serie using the serie's name or ID
|
||||
await tcgdex.fetch('series', 'Sword & Shield')
|
||||
|
||||
// Fetch cards possible pokemon cards HP
|
||||
await tcgdex.fetch('hp');
|
||||
|
||||
// Fetch Cards with the specific number of HP
|
||||
await tcgdex.fetch('hp', 110);
|
||||
|
||||
// Fetch cards possible illustrators
|
||||
await tcgdex.fetch('illustrators');
|
||||
|
||||
// Fetch Cards with the specific illustrator
|
||||
await tcgdex.fetch('illustrators', 'tetsuya koizumi');
|
||||
```
|
||||
|
||||
**Other Endpoints**
|
||||
|
||||
_They work like the two (`hp` and `illustrators`) abose_
|
||||
|
||||
- categories: the the different cards categories
|
||||
- energy-types: Fetch different types of energies
|
||||
- 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
|
||||
- stages: fetch differents cards stages
|
||||
- suffixes: fetch differents cards suffixes
|
||||
- trainer-types: fetch trainer cards types
|
||||
- dex-ids: fetch pokemon Global Pokédex IDS
|
||||
- types: fetch the cards using the Pokémon type(s)
|
||||
|
||||
## Contributing
|
||||
|
||||
See [CONTRIBUTING.md](https://github.com/tcgdex/javascript-sdk/blob/master/CONTRIBUTING.md)
|
||||
|
||||
TL::DR
|
||||
|
||||
- Fork
|
||||
|
||||
- Commit your changes
|
||||
|
||||
- Pull Request on this Repository
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the IT License. A copy of the license is available at [LICENSE.md](https://github.com/tcgdex/javascript-sdk/blob/master/LICENSE.md)
|
||||
|
@ -1,5 +1,7 @@
|
||||
const TCGdex = require("../src/tcgdex").default
|
||||
const fetch = require('node-fetch')
|
||||
/// <reference types="jest" />
|
||||
|
||||
const { default: TCGdex, Query } = require("../src/tcgdex")
|
||||
import fetch from 'node-fetch'
|
||||
|
||||
const fakeFetch = (response, status = 200) => jest.fn(() =>
|
||||
Promise.resolve({
|
||||
@ -8,59 +10,141 @@ const fakeFetch = (response, status = 200) => jest.fn(() =>
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
|
||||
test('Basic test', async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fakeFetch({ok: true})
|
||||
TCGdex.fetch = fakeFetch({ ok: true })
|
||||
const res = await tcgdex.fetch('cards', 'basic-test')
|
||||
expect(res).toEqual({ok: true})
|
||||
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'})
|
||||
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 () => {
|
||||
test(`404 error`, 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()
|
||||
}
|
||||
expect(
|
||||
await tcgdex.card.get('404-error')
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
test(`test getting full set from list`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (await tcgdex.set.list())[0].getSet()
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
test(`test getting full serie from list`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (await tcgdex.serie.list())[0].getSerie()
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
test(`test getting full card from list`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (await tcgdex.card.list())[0].getCard()
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
|
||||
test(`test get set from card`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (await tcgdex.card.get('swsh1-136')).getSet()
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
test(`test get serie from set`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (await tcgdex.set.get('swsh1')).getSerie()
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
test(`advanced query system`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
(await tcgdex.card.list(
|
||||
Query.create()
|
||||
.equal('name', 'Pikachu')
|
||||
.greaterOrEqualThan('hp', 60)
|
||||
.lesserThan('hp', 70)
|
||||
.contains('localId', '5')
|
||||
.not.contains('localId', 'tg')
|
||||
.not.equal('id', 'cel25-5')
|
||||
.sort('localId', 'ASC')
|
||||
.paginate(3, 2)
|
||||
)).length
|
||||
).toBe(2)
|
||||
})
|
||||
|
||||
const endpoints = [
|
||||
{ endpoint: 'card', params: ['swsh1-136'] },
|
||||
{ endpoint: 'set', params: ['swsh1'] },
|
||||
{ endpoint: 'serie', params: ['swsh'] },
|
||||
{ endpoint: 'type', params: ['fire'] },
|
||||
{ endpoint: 'retreat', params: ['1'] },
|
||||
{ endpoint: 'rarity', params: ['common'] },
|
||||
{ endpoint: 'illustrator', params: [''] },
|
||||
{ endpoint: 'hp', params: ['30'] },
|
||||
{ endpoint: 'categorie', params: ['pokemon'] },
|
||||
{ endpoint: 'dexID', params: ['1'] },
|
||||
{ endpoint: 'energyType', params: ['normal'] },
|
||||
{ endpoint: 'regulationMark', params: ['f'] },
|
||||
{ endpoint: 'stage', params: ['basic'] },
|
||||
{ endpoint: 'suffixe', params: ['ex'] },
|
||||
{ endpoint: 'trainerType', params: ['item'] },
|
||||
{ endpoint: 'variant', params: ['normal'] },
|
||||
]
|
||||
|
||||
for (const endpoint of endpoints) {
|
||||
test(`test real ${endpoint.endpoint} endpoint list`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (tcgdex[endpoint.endpoint]).list()
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
test(`test real ${endpoint.endpoint} endpoint item`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect(
|
||||
await (tcgdex[endpoint.endpoint]).get(endpoint.params[0])
|
||||
).toBeTruthy()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
test(`random card/set/serie`, async () => {
|
||||
const tcgdex = new TCGdex('en')
|
||||
TCGdex.fetch = fetch
|
||||
|
||||
expect((await tcgdex.random.card())).toBeTruthy()
|
||||
expect((await tcgdex.random.set())).toBeTruthy()
|
||||
expect((await tcgdex.random.serie())).toBeTruthy()
|
||||
})
|
||||
|
66
__tests__/deprecated.test.js
Normal file
66
__tests__/deprecated.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()
|
||||
}
|
||||
})
|
11850
package-lock.json
generated
11850
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
64
package.json
64
package.json
@ -1,9 +1,22 @@
|
||||
{
|
||||
"name": "@tcgdex/sdk",
|
||||
"version": "2.4.4",
|
||||
"main": "./dist/cjs/tcgdex.node.js",
|
||||
"module": "./dist/modules/tcgdex.node.js",
|
||||
"types": "./dist/types/tcgdex.d.ts",
|
||||
"version": "2.6.0-beta.4",
|
||||
"main": "./dist/tcgdex.node.js",
|
||||
"module": "./dist/tcgdex.node.mjs",
|
||||
"types": "./dist/tcgdex.node.d.ts",
|
||||
"browser": "./dist/tcgdex.browser.global.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": {
|
||||
"types": "./dist/tcgdex.node.d.ts",
|
||||
"default": "./dist/tcgdex.node.js"
|
||||
},
|
||||
"import": {
|
||||
"types": "./dist/tcgdex.node.d.mts",
|
||||
"default": "./dist/tcgdex.node.mjs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"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",
|
||||
@ -18,36 +31,36 @@
|
||||
"api",
|
||||
"typescript",
|
||||
"javascript",
|
||||
"typing"
|
||||
"typing",
|
||||
"browser",
|
||||
"node"
|
||||
],
|
||||
"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",
|
||||
"esbuild": "^0.12.15",
|
||||
"eslint": "^7.29.0",
|
||||
"jest": "^27.0.5",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.1.3"
|
||||
"@babel/core": "^7",
|
||||
"@babel/preset-env": "^7",
|
||||
"@babel/preset-typescript": "^7",
|
||||
"@dzeio/config": "^1",
|
||||
"@types/node-fetch": "^2",
|
||||
"@typescript-eslint/eslint-plugin": "^5",
|
||||
"@typescript-eslint/parser": "^5",
|
||||
"eslint": "^8",
|
||||
"jest": "^29",
|
||||
"tsup": "^7",
|
||||
"typescript": "^5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-unfetch": "^3.1.0",
|
||||
"unfetch": "^4.2.0"
|
||||
"@cachex/memory": "^1",
|
||||
"@cachex/web-storage": "^1",
|
||||
"@dzeio/object-util": "^1",
|
||||
"isomorphic-unfetch": "^3"
|
||||
},
|
||||
"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": "esbuild ./src/tcgdex.browser.ts --bundle --minify --sourcemap --target=es2016,chrome90,firefox78,safari14,ios13,edge90 --outfile=dist/tcgdex.browser.js",
|
||||
"build": "rm -rf dist && tsup ./src/tcgdex.node.ts --format cjs,esm --dts --clean && tsup ./src/tcgdex.browser.ts --format iife --global-name TCGdex --sourcemap",
|
||||
"prepublishOnly": "npm run build",
|
||||
"lint": "eslint",
|
||||
"test": "jest --coverage"
|
||||
@ -55,5 +68,8 @@
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"sideEffects": false
|
||||
"sideEffects": false,
|
||||
"jest": {
|
||||
"testTimeout": 30000
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
const { version } = require('../package.json')
|
||||
const fs = require('fs')
|
||||
|
||||
fs.writeFileSync('./src/version.json', JSON.stringify({version}))
|
||||
fs.writeFileSync('./src/version.js', `export const version = '${version}'`)
|
||||
|
88
src/Query.ts
Normal file
88
src/Query.ts
Normal file
@ -0,0 +1,88 @@
|
||||
export default class Query {
|
||||
public params: Array<{ key: string, value: string | number | boolean }> = []
|
||||
|
||||
public not: {
|
||||
equal: (key: string, value: string) => Query
|
||||
contains: (key: string, value: string) => Query
|
||||
includes: (key: string, value: string) => Query
|
||||
like: (key: string, value: string) => Query
|
||||
isNull: (key: string) => Query
|
||||
} = {
|
||||
equal: (key: string, value: string) => {
|
||||
this.params.push({ key: key, value: `neq:${value}` })
|
||||
return this
|
||||
},
|
||||
contains: (key: string, value: string) => {
|
||||
this.params.push({ key: key, value: `not:${value}` })
|
||||
return this
|
||||
},
|
||||
includes: (key: string, value: string) => this.not.contains(key, value),
|
||||
like: (key: string, value: string) => this.not.contains(key, value),
|
||||
isNull: (key: string) => {
|
||||
this.params.push({ key: key, value: 'notnull:' })
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
public static create(): Query {
|
||||
return new Query()
|
||||
}
|
||||
|
||||
public includes(key: string, value: string): this {
|
||||
return this.contains(key, value)
|
||||
}
|
||||
|
||||
public like(key: string, value: string): this {
|
||||
return this.contains(key, value)
|
||||
}
|
||||
|
||||
public contains(key: string, value: string): this {
|
||||
this.params.push({ key: key, value: value })
|
||||
return this
|
||||
}
|
||||
|
||||
public equal(key: string, value: string): this {
|
||||
this.params.push({ key: key, value: `eq:${value}` })
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public sort(key: string, order: 'ASC' | 'DESC'): this {
|
||||
this.params.push({ key: 'sort:field', value: key })
|
||||
this.params.push({ key: 'sort:order', value: order })
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public greaterOrEqualThan(key: string, value: number) {
|
||||
this.params.push({ key: key, value: `gte:${value}` })
|
||||
return this
|
||||
}
|
||||
|
||||
public lesserOrEqualThan(key: string, value: number) {
|
||||
this.params.push({ key: key, value: `lte:${value}` })
|
||||
return this
|
||||
}
|
||||
|
||||
public greaterThan(key: string, value: number) {
|
||||
this.params.push({ key: key, value: `gt:${value}` })
|
||||
return this
|
||||
}
|
||||
|
||||
public lesserThan(key: string, value: number) {
|
||||
this.params.push({ key: key, value: `lt:${value}` })
|
||||
return this
|
||||
}
|
||||
|
||||
public isNull(key: string) {
|
||||
this.params.push({ key: key, value: 'null:' })
|
||||
return this
|
||||
}
|
||||
|
||||
public paginate(page: number, itemsPerPage: number): this {
|
||||
this.params.push({ key: 'pagination:page', value: page })
|
||||
this.params.push({ key: 'pagination:itemsPerPage', value: itemsPerPage })
|
||||
|
||||
return this
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
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
|
||||
}
|
||||
|
||||
}
|
26
src/endpoints/Endpoint.ts
Normal file
26
src/endpoints/Endpoint.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import type { Endpoints } from '../interfaces'
|
||||
import Model from '../models/Model'
|
||||
import type Query from '../Query'
|
||||
import type TCGdex from '../tcgdex'
|
||||
|
||||
export default class Endpoint<Item extends Model, List extends Model> {
|
||||
public constructor(
|
||||
protected readonly tcgdex: TCGdex,
|
||||
protected readonly itemModel: new (sdk: TCGdex) => Item,
|
||||
protected readonly listModel: new (sdk: TCGdex) => List,
|
||||
protected readonly endpoint: Endpoints
|
||||
) { }
|
||||
|
||||
public async get(id: string | number): Promise<Item | null> {
|
||||
const res = await this.tcgdex.fetch(this.endpoint as 'cards', id as string)
|
||||
if (!res) {
|
||||
return null
|
||||
}
|
||||
return Model.build(new this.itemModel(this.tcgdex), res)
|
||||
}
|
||||
|
||||
public async list(query?: Query): Promise<Array<List>> {
|
||||
const res = await this.tcgdex.fetchWithQuery([this.endpoint], query?.params)
|
||||
return (res as Array<object> ?? []).map((it) => Model.build(new this.listModel(this.tcgdex), it))
|
||||
}
|
||||
}
|
24
src/endpoints/SimpleEndpoint.ts
Normal file
24
src/endpoints/SimpleEndpoint.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import type { Endpoints } from '../interfaces'
|
||||
import Model from '../models/Model'
|
||||
import type Query from '../Query'
|
||||
import type TCGdex from '../tcgdex'
|
||||
|
||||
export default class SimpleEndpoint<Item extends Model, List extends string | number> {
|
||||
public constructor(
|
||||
protected readonly tcgdex: TCGdex,
|
||||
protected readonly itemModel: new (sdk: TCGdex) => Item,
|
||||
protected readonly endpoint: Endpoints
|
||||
) {}
|
||||
|
||||
public async get(id: string | number): Promise<Item | null> {
|
||||
const res = await this.tcgdex.fetch(this.endpoint as 'cards', id as string)
|
||||
if (!res) {
|
||||
return null
|
||||
}
|
||||
return Model.build(new this.itemModel(this.tcgdex), res)
|
||||
}
|
||||
|
||||
public async list(query?: Query): Promise<Array<List>> {
|
||||
return await this.tcgdex.fetchWithQuery([this.endpoint], query?.params) ?? []
|
||||
}
|
||||
}
|
9
src/interfaces.ts → src/interfaces.d.ts
vendored
9
src/interfaces.ts → src/interfaces.d.ts
vendored
@ -310,3 +310,12 @@ export interface StringEndpoint {
|
||||
name: string
|
||||
cards: Array<CardResume>
|
||||
}
|
||||
|
||||
export type Quality = 'low' | 'high'
|
||||
|
||||
export type Extension = 'jpg' | 'webp' | 'png'
|
||||
|
||||
export type Endpoints = 'cards' | 'categories' | 'dex-ids' | 'energy-types' |
|
||||
'hp' | 'illustrators' | 'rarities' | 'regulation-marks' |
|
||||
'retreats' | 'series' | 'sets' | 'stages' | 'suffixes' |
|
||||
'trainer-types' | 'types' | 'variants' | 'random'
|
198
src/models/Card.ts
Normal file
198
src/models/Card.ts
Normal file
@ -0,0 +1,198 @@
|
||||
import CardResume from './CardResume'
|
||||
import type { Variants } from './Other'
|
||||
import type TCGdexSet from './Set'
|
||||
import type SetResume from './SetResume'
|
||||
|
||||
// TODO: sort elements by alphabetical order
|
||||
export default class Card extends CardResume {
|
||||
/**
|
||||
* Card illustrator
|
||||
*/
|
||||
public illustrator?: string
|
||||
|
||||
/**
|
||||
* Card Rarity
|
||||
*
|
||||
* - None https://www.tcgdex.net/database/sm/smp/SM01
|
||||
* - Common https://www.tcgdex.net/database/xy/xy9/1
|
||||
* - Uncommon https://www.tcgdex.net/database/xy/xy9/2
|
||||
* - Rare https://www.tcgdex.net/database/xy/xy9/3
|
||||
* - Ultra Rare
|
||||
* - Secret Rare
|
||||
*/
|
||||
public rarity!: string
|
||||
|
||||
/**
|
||||
* Card Category
|
||||
*
|
||||
* - Pokemon
|
||||
* - Trainer
|
||||
* - Energy
|
||||
*/
|
||||
public category!: string
|
||||
|
||||
/**
|
||||
* Card Variants (Override Set Variants)
|
||||
*/
|
||||
public variants?: Variants
|
||||
|
||||
/**
|
||||
* Card Set
|
||||
*/
|
||||
public set!: SetResume
|
||||
|
||||
/**
|
||||
* Pokemon only elements
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pokemon Pokedex ID
|
||||
*/
|
||||
public dexId?: Array<number>
|
||||
|
||||
/**
|
||||
* Pokemon HP
|
||||
*/
|
||||
public hp?: number
|
||||
|
||||
/**
|
||||
* Pokemon Types
|
||||
* ex for multiple https://www.tcgdex.net/database/ex/ex13/17
|
||||
*/
|
||||
public types?: Array<string>
|
||||
|
||||
/**
|
||||
* Pokemon Sub Evolution
|
||||
*/
|
||||
public evolveFrom?: string
|
||||
|
||||
/**
|
||||
* Pokemon Weight
|
||||
*/
|
||||
public weight?: string
|
||||
|
||||
/**
|
||||
* Pokemon Description
|
||||
*/
|
||||
public description?: string
|
||||
|
||||
/**
|
||||
* Level of the Pokemon
|
||||
*
|
||||
* NOTE: can be equal to 'X' when the pokemon is a LEVEL-UP one
|
||||
*/
|
||||
public level?: number | string
|
||||
|
||||
/**
|
||||
* Pokemon Stage
|
||||
*
|
||||
* - Basic https://www.tcgdex.net/database/xy/xy9/1
|
||||
* - BREAK https://www.tcgdex.net/database/xy/xy9/18
|
||||
* - LEVEL-UP https://www.tcgdex.net/database/dp/dp1/121
|
||||
* - MEGA https://www.tcgdex.net/database/xy/xy1/2
|
||||
* - RESTORED https://www.tcgdex.net/database/bw/bw5/53
|
||||
* - Stage1 https://www.tcgdex.net/database/xy/xy9/2
|
||||
* - Stage2 https://www.tcgdex.net/database/xy/xy9/3
|
||||
* - VMAX https://www.tcgdex.net/database/swsh/swsh1/50
|
||||
*/
|
||||
public stage?: string
|
||||
|
||||
/**
|
||||
* Card Suffix
|
||||
*
|
||||
* - EX https://www.tcgdex.net/database/ex/ex2/94
|
||||
* - GX https://www.tcgdex.net/database/sm/sm12/4
|
||||
* - V https://www.tcgdex.net/database/swsh/swsh1/1
|
||||
* - Legend https://www.tcgdex.net/database/hgss/hgss1/114
|
||||
* - Prime https://www.tcgdex.net/database/hgss/hgss2/85
|
||||
* - SP https://www.tcgdex.net/database/pl/pl1/7
|
||||
* - TAG TEAM-GX https://www.tcgdex.net/database/sm/sm12/226
|
||||
*/
|
||||
public suffix?: string
|
||||
|
||||
/**
|
||||
* Pokemon Held Item
|
||||
*
|
||||
* ex https://www.tcgdex.net/database/dp/dp2/75
|
||||
*/
|
||||
public item?: {
|
||||
name: string
|
||||
effect: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Pokemon Abilities
|
||||
*
|
||||
* multi abilities ex https://www.tcgdex.net/database/ex/ex15/10
|
||||
*/
|
||||
public abilities?: Array<{
|
||||
type: string
|
||||
name: string
|
||||
effect: string
|
||||
}>
|
||||
|
||||
/**
|
||||
* Pokemon Attacks
|
||||
*/
|
||||
public attacks?: Array<{
|
||||
cost?: Array<string>
|
||||
name: string
|
||||
effect?: string
|
||||
damage?: string | number
|
||||
}>
|
||||
|
||||
/**
|
||||
* Pokemon Weaknesses
|
||||
*/
|
||||
public weaknesses?: Array<{
|
||||
type: string
|
||||
value?: string
|
||||
}>
|
||||
|
||||
public resistances?: Array<{
|
||||
type: string
|
||||
value?: string
|
||||
}>
|
||||
|
||||
public retreat?: number
|
||||
|
||||
// Trainer/Energy
|
||||
public effect?: string
|
||||
|
||||
// Trainer Only
|
||||
public trainerType?: string
|
||||
|
||||
// Energy Only
|
||||
public energyType?: string
|
||||
|
||||
/**
|
||||
* Define the rotation mark on cards >= Sword & Shield
|
||||
*/
|
||||
public regulationMark?: string
|
||||
|
||||
/**
|
||||
* Card ability to be played in official tournaments
|
||||
*
|
||||
* Note: all cards are avaialable to play in unlimited tournaments
|
||||
*/
|
||||
public legal!: {
|
||||
|
||||
/**
|
||||
* Ability to play in standard tournaments
|
||||
*/
|
||||
standard: boolean
|
||||
|
||||
/**
|
||||
* Ability to play in expanded tournaments
|
||||
*/
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
public override async getCard(): Promise<Card> {
|
||||
return this
|
||||
}
|
||||
|
||||
public async getSet(): Promise<TCGdexSet> {
|
||||
return (await this.sdk.set.get(this.set.id))!
|
||||
}
|
||||
}
|
47
src/models/CardResume.ts
Normal file
47
src/models/CardResume.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import type { Extension, Quality } from '../interfaces'
|
||||
import type Card from './Card'
|
||||
import Model from './Model'
|
||||
|
||||
export default class CardResume extends Model {
|
||||
/**
|
||||
* Globally unique card ID based on the set ID and the cards ID within the set
|
||||
*/
|
||||
public id!: string
|
||||
|
||||
/**
|
||||
* Card image url without the extension and quality
|
||||
*
|
||||
* @see {@link getImageURL}
|
||||
*/
|
||||
public image?: string
|
||||
|
||||
/**
|
||||
* ID indexing this card within its set, usually just its number
|
||||
*/
|
||||
public localId!: string
|
||||
|
||||
/**
|
||||
* Card Name (Including the suffix if next to card name)
|
||||
*/
|
||||
public name!: string
|
||||
|
||||
/**
|
||||
* the the Card Image full URL
|
||||
*
|
||||
* @param {Quality} quality the quality you want your image to be in
|
||||
* @param {Extension} extension extension you want you image to be
|
||||
* @return the full card URL
|
||||
*/
|
||||
public getImageURL(quality: Quality = 'high', extension: Extension = 'png'): string {
|
||||
return `${this.image}/${quality}.${extension}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full Card
|
||||
*
|
||||
* @return the full card if available
|
||||
*/
|
||||
public async getCard(): Promise<Card> {
|
||||
return (await this.sdk.card.get(this.id))!
|
||||
}
|
||||
}
|
28
src/models/Model.ts
Normal file
28
src/models/Model.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
import type TCGdex from '../tcgdex'
|
||||
|
||||
export default abstract class Model {
|
||||
|
||||
public constructor(
|
||||
protected readonly sdk: TCGdex
|
||||
) { }
|
||||
|
||||
/**
|
||||
* build a model depending on the data given
|
||||
* @param model the model to build
|
||||
* @param data the data to fill it with
|
||||
*/
|
||||
public static build<T extends Model>(model: T, data?: object): T {
|
||||
if (!data) {
|
||||
throw new Error('data is necessary.')
|
||||
}
|
||||
model.fill(data)
|
||||
return model
|
||||
}
|
||||
|
||||
protected fill(obj: object) {
|
||||
objectLoop(obj, (value, key) => {
|
||||
(this as object)[key] = value
|
||||
})
|
||||
}
|
||||
}
|
6
src/models/Other.d.ts
vendored
Normal file
6
src/models/Other.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export interface Variants {
|
||||
normal?: boolean
|
||||
reverse?: boolean
|
||||
holo?: boolean
|
||||
firstEdition?: boolean
|
||||
}
|
21
src/models/Serie.ts
Normal file
21
src/models/Serie.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
import Model from './Model'
|
||||
import SerieResume from './SerieResume'
|
||||
import SetResume from './SetResume'
|
||||
|
||||
export default class Serie extends SerieResume {
|
||||
public sets!: Array<SetResume>
|
||||
|
||||
protected fill(obj: object): void {
|
||||
objectLoop(obj, (value, key) => {
|
||||
switch (key) {
|
||||
case 'sets':
|
||||
this.sets = (value as Array<any>).map((it) => Model.build(new SetResume(this.sdk), it))
|
||||
break
|
||||
default:
|
||||
this[key] = value
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
24
src/models/SerieResume.ts
Normal file
24
src/models/SerieResume.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import type { Extension } from '../interfaces'
|
||||
import Model from './Model'
|
||||
import type Serie from './Serie'
|
||||
|
||||
export default class SerieResume extends Model {
|
||||
public id!: string
|
||||
public name!: string
|
||||
public logo?: string
|
||||
|
||||
/**
|
||||
* the the Card Image full URL
|
||||
*
|
||||
* @param {Quality} quality the quality you want your image to be in
|
||||
* @param {Extension} extension extension you want you image to be
|
||||
* @return the full card URL
|
||||
*/
|
||||
public getImageURL(extension: Extension = 'png'): string {
|
||||
return `${this.logo}.${extension}`
|
||||
}
|
||||
|
||||
public async getSerie(): Promise<Serie> {
|
||||
return (await this.sdk.serie.get(this.id))!
|
||||
}
|
||||
}
|
89
src/models/Set.ts
Normal file
89
src/models/Set.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
import CardResume from './CardResume'
|
||||
import Model from './Model'
|
||||
import type { Variants } from './Other'
|
||||
import type SerieResume from './SerieResume'
|
||||
|
||||
// biome-ignore lint/suspicious/noShadowRestrictedNames: <explanation>
|
||||
export default class Set extends Model {
|
||||
public id!: string
|
||||
public name!: string
|
||||
public logo?: string
|
||||
public symbol?: string
|
||||
public serie!: SerieResume
|
||||
public tcgOnline?: string
|
||||
public variants?: Variants
|
||||
|
||||
public releaseDate!: string
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public legal!: {
|
||||
|
||||
/**
|
||||
* Ability to play in standard tournaments
|
||||
*/
|
||||
standard: boolean
|
||||
|
||||
/**
|
||||
* Ability to play in expanded tournaments
|
||||
*/
|
||||
expanded: boolean
|
||||
}
|
||||
|
||||
public 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
|
||||
*/
|
||||
firstEd?: number
|
||||
}
|
||||
|
||||
public cards!: Array<CardResume>
|
||||
|
||||
public async getSerie() {
|
||||
return this.sdk.serie.get(this.serie.id)
|
||||
}
|
||||
|
||||
protected fill(obj: object): void {
|
||||
objectLoop(obj, (value, key) => {
|
||||
switch (key) {
|
||||
case 'cards':
|
||||
this.cards = (value as Array<any>).map((it) => Model.build(new CardResume(this.sdk), it))
|
||||
break
|
||||
default:
|
||||
this[key] = value
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
25
src/models/SetResume.ts
Normal file
25
src/models/SetResume.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import Model from './Model'
|
||||
import type TCGdexSet from './Set'
|
||||
|
||||
export default class SetResume extends Model {
|
||||
public id!: string
|
||||
public name!: string
|
||||
public logo?: string
|
||||
public symbol?: string
|
||||
public cardCount!: {
|
||||
|
||||
/**
|
||||
* total of number of cards
|
||||
*/
|
||||
total: number
|
||||
|
||||
/**
|
||||
* number of cards officialy (on the bottom of each cards)
|
||||
*/
|
||||
official: number
|
||||
}
|
||||
|
||||
public async getSet(): Promise<TCGdexSet> {
|
||||
return (await this.sdk.set.get(this.id))!
|
||||
}
|
||||
}
|
21
src/models/StringEndpoint.ts
Normal file
21
src/models/StringEndpoint.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { objectLoop } from '@dzeio/object-util'
|
||||
import CardResume from './CardResume'
|
||||
import Model from './Model'
|
||||
|
||||
export default class StringEndpoint extends Model {
|
||||
public name!: string
|
||||
public cards!: Array<CardResume>
|
||||
|
||||
protected fill(obj: object): void {
|
||||
objectLoop(obj, (value, key) => {
|
||||
switch (key) {
|
||||
case 'cards':
|
||||
this.cards = (value as Array<any>).map((it) => Model.build(new CardResume(this.sdk), it))
|
||||
break
|
||||
default:
|
||||
this[key] = value
|
||||
break
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import TCGdex from './tcgdex'
|
||||
import unfetch from 'unfetch'
|
||||
|
||||
TCGdex.fetch = window.fetch ?? unfetch as any
|
||||
TCGdex.fetch = window.fetch
|
||||
|
||||
(global ?? window).TCGdex = TCGdex
|
||||
export default TCGdex
|
||||
|
273
src/tcgdex.ts
273
src/tcgdex.ts
@ -1,24 +1,161 @@
|
||||
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'
|
||||
import type CacheInterface from '@cachex/core'
|
||||
import LocalStorageCache from '@cachex/web-storage'
|
||||
import MemoryCache from '@cachex/memory'
|
||||
import Query from './Query'
|
||||
import Endpoint from './endpoints/Endpoint'
|
||||
import SimpleEndpoint from './endpoints/SimpleEndpoint'
|
||||
import type {
|
||||
Card,
|
||||
CardResume,
|
||||
Endpoints,
|
||||
Serie,
|
||||
SerieList,
|
||||
SetList,
|
||||
StringEndpoint,
|
||||
SupportedLanguages,
|
||||
Set as TCGdexSet
|
||||
} from './interfaces'
|
||||
import CardModel from './models/Card'
|
||||
import CardResumeModel from './models/CardResume'
|
||||
import Model from './models/Model'
|
||||
import SerieModel from './models/Serie'
|
||||
import SerieResume from './models/SerieResume'
|
||||
import SetModel from './models/Set'
|
||||
import SetResumeModel from './models/SetResume'
|
||||
import StringEndpointModel from './models/StringEndpoint'
|
||||
import { ENDPOINTS, detectContext } from './utils'
|
||||
import { version } from './version'
|
||||
|
||||
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
|
||||
/**
|
||||
* How the remote data is going to be fetched
|
||||
*/
|
||||
public static fetch: typeof fetch = fetch
|
||||
|
||||
/**
|
||||
* @deprecated to change the lang use `this.lang`
|
||||
* @deprecated to change the lang use {@link TCGdex.getLang} and {@link TCGdex.setLang}
|
||||
*/
|
||||
public static defaultLang: SupportedLanguages = 'en'
|
||||
|
||||
public constructor(public lang?: SupportedLanguages) {}
|
||||
/**
|
||||
* the previously hidden caching system used by TCGdex to not kill the API
|
||||
*/
|
||||
public cache: CacheInterface =
|
||||
detectContext() === 'browser' ? new LocalStorageCache('tcgdex-cache') : new MemoryCache()
|
||||
|
||||
/**
|
||||
* the default cache TTL, only subsequent requests will have their ttl changed
|
||||
*/
|
||||
public cacheTTL = 60 * 60
|
||||
|
||||
// random card/set/serie endpoints
|
||||
public readonly random = {
|
||||
card: async (): Promise<CardModel> => {
|
||||
const res = await this.fetch('random', 'card')
|
||||
return Model.build(new CardModel(this), res)
|
||||
},
|
||||
set: async (): Promise<SetModel> => {
|
||||
const res = await this.fetch('random', 'set')
|
||||
return Model.build(new SetModel(this), res)
|
||||
},
|
||||
serie: async (): Promise<SerieModel> => {
|
||||
const res = await this.fetch('random', 'serie')
|
||||
return Model.build(new SerieModel(this), res)
|
||||
}
|
||||
}
|
||||
|
||||
public readonly card = new Endpoint(this, CardModel, CardResumeModel, 'cards')
|
||||
public readonly set = new Endpoint(this, SetModel, SetResumeModel, 'sets')
|
||||
public readonly serie = new Endpoint(this, SerieModel, SerieResume, 'series')
|
||||
|
||||
public readonly type = new SimpleEndpoint(this, StringEndpointModel, 'types')
|
||||
public readonly retreat = new SimpleEndpoint(this, StringEndpointModel, 'retreats')
|
||||
public readonly rarity = new SimpleEndpoint(this, StringEndpointModel, 'rarities')
|
||||
public readonly illustrator = new SimpleEndpoint(this, StringEndpointModel, 'illustrators')
|
||||
public readonly hp = new SimpleEndpoint(this, StringEndpointModel, 'hp')
|
||||
public readonly categorie = new SimpleEndpoint(this, StringEndpointModel, 'categories')
|
||||
public readonly dexID = new SimpleEndpoint(this, StringEndpointModel, 'dex-ids')
|
||||
public readonly energyType = new SimpleEndpoint(this, StringEndpointModel, 'energy-types')
|
||||
public readonly regulationMark = new SimpleEndpoint(this, StringEndpointModel, 'regulation-marks')
|
||||
public readonly stage = new SimpleEndpoint(this, StringEndpointModel, 'stages')
|
||||
public readonly suffixe = new SimpleEndpoint(this, StringEndpointModel, 'suffixes')
|
||||
public readonly trainerType = new SimpleEndpoint(this, StringEndpointModel, 'trainer-types')
|
||||
public readonly variant = new SimpleEndpoint(this, StringEndpointModel, 'variants')
|
||||
|
||||
private lang: SupportedLanguages = 'en'
|
||||
private endpointURL = 'https://api.tcgdex.net/v2'
|
||||
|
||||
public constructor(lang: SupportedLanguages = 'en') {
|
||||
this.setLang(lang)
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use the constructor parameter or {@link TCGdex.setLang} when in an instance
|
||||
*/
|
||||
public static setDefaultLang(lang: SupportedLanguages) {
|
||||
TCGdex.defaultLang = lang
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link TCGdex.setLang} when in an instance
|
||||
*/
|
||||
public static getDefaultLang(): SupportedLanguages {
|
||||
return TCGdex.defaultLang
|
||||
}
|
||||
|
||||
/**
|
||||
* the endpoint URL
|
||||
* ex: `https://api.tcgdex.net/v2`
|
||||
* @param endpoint the url
|
||||
*/
|
||||
public setEndpoint(endpoint: string) {
|
||||
this.endpointURL = endpoint
|
||||
}
|
||||
public getEndpoint(): string {
|
||||
return this.endpointURL
|
||||
}
|
||||
|
||||
/**
|
||||
* set the current cache methodology
|
||||
* @param cache the cache to use
|
||||
*/
|
||||
public setCache(cache: CacheInterface) {
|
||||
this.cache = cache
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current cache methodology
|
||||
* @param cache the cache to use
|
||||
*/
|
||||
public getCache(): CacheInterface {
|
||||
return this.cache
|
||||
}
|
||||
|
||||
/**
|
||||
* the endpoint URL
|
||||
* ex: `https://api.tcgdex.net/v2`
|
||||
* @param endpoint the url
|
||||
*/
|
||||
public setCacheTTL(seconds: number) {
|
||||
this.cacheTTL = seconds
|
||||
}
|
||||
/**
|
||||
* get the current useed cache ttl in seconds
|
||||
* @returns the cache ttl in seconds
|
||||
*/
|
||||
public getCacheTTL(): number {
|
||||
return this.cacheTTL
|
||||
}
|
||||
|
||||
public getLang(): SupportedLanguages {
|
||||
return this.lang ?? TCGdex.defaultLang ?? 'en'
|
||||
}
|
||||
|
||||
public setLang(lang: SupportedLanguages) {
|
||||
this.lang = lang
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to easily fetch a card using both it's global id and it's local ID
|
||||
* @param id the card global/local ID
|
||||
@ -47,7 +184,7 @@ export default class TCGdex {
|
||||
/**
|
||||
* @deprecated use `this.fetch('sets', set)`
|
||||
*/
|
||||
public async fetchSet(set: string): Promise<Set | undefined> {
|
||||
public async fetchSet(set: string): Promise<TCGdexSet | undefined> {
|
||||
return this.fetch('sets', set)
|
||||
}
|
||||
|
||||
@ -104,7 +241,14 @@ export default class TCGdex {
|
||||
* @param endpoint_0 'sets'
|
||||
* @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<TCGdexSet | undefined>
|
||||
|
||||
/**
|
||||
* Fetch a random element
|
||||
* @param endpoint_0 'random'
|
||||
* @param endpoint_1 {'set' | 'card' | 'serie'} the type of random element you want to get
|
||||
*/
|
||||
public async fetch(...endpoint: ['random', 'set' | 'card' | 'serie']): Promise<Card | TCGdexSet | Serie | undefined>
|
||||
|
||||
/**
|
||||
* Fetch every sets
|
||||
@ -127,19 +271,19 @@ export default class TCGdex {
|
||||
|
||||
/**
|
||||
* Fetch cards depending on a specific filter
|
||||
* @param endpoint_0 {'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'}
|
||||
* Possible value 'categories' | 'hp' | 'illustrators' | 'rarities' | 'retreats' | 'types'
|
||||
* @param endpoint_0 {'categories' | 'dex-ids' | 'energy-types' | 'hp' | 'illustrators' | 'rarities' | 'regulation-marks' | 'retreats' | 'stages' | 'suffixes' | 'trainer-types' | 'types' | 'variants'}
|
||||
* Possible value 'categories' | 'dex-ids' | 'energy-types' | 'hp' | 'illustrators' | 'rarities' | 'regulation-marks' | 'retreats' | 'stages' | 'suffixes' | 'trainer-types' | 'types' | 'variants'
|
||||
* @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' | 'dex-ids' | 'energy-types' | 'hp' | 'illustrators' | 'rarities' | 'regulation-marks' | 'retreats' | 'stages' | 'suffixes' | 'trainer-types' | 'types' | 'variants', string]): Promise<StringEndpoint | undefined>
|
||||
|
||||
/**
|
||||
* Fetch cards depending on a specific filter
|
||||
* @param endpoint_0 {'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'}
|
||||
* Possible value 'hp' | 'retreats' | 'categories' | 'illustrators' | 'rarities' | 'types'
|
||||
* @param endpoint_0 {'categories' | 'dex-ids' | 'energy-types' | 'hp' | 'illustrators' | 'rarities' | 'regulation-marks' | 'retreats' | 'stages' | 'suffixes' | 'trainer-types' | 'types' | 'variants'}
|
||||
* Possible value 'categories' | 'dex-ids' | 'energy-types' | 'hp' | 'illustrators' | 'rarities' | 'regulation-marks' | 'retreats' | 'stages' | 'suffixes' | 'trainer-types' | 'types' | 'variants'
|
||||
* @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: 'categories' | 'dex-ids' | 'energy-types' | 'hp' | 'illustrators' | 'rarities' | 'regulation-marks' | 'retreats' | 'stages' | 'suffixes' | 'trainer-types' | 'types' | 'variants'): Promise<Array<string> | undefined>
|
||||
|
||||
/**
|
||||
* Fetch The differents endpoints depending on the first argument
|
||||
@ -148,7 +292,7 @@ export default class TCGdex {
|
||||
* @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> {
|
||||
public async fetch<T = object>(...endpoint: Array<Endpoints | string>): Promise<T | undefined> {
|
||||
if (endpoint.length === 0) {
|
||||
throw new Error('endpoint to fetch is empty!')
|
||||
}
|
||||
@ -157,29 +301,104 @@ export default class TCGdex {
|
||||
if (!ENDPOINTS.includes(baseEndpoint)) {
|
||||
throw new Error(`unknown endpoint to fetch! (${baseEndpoint})`)
|
||||
}
|
||||
return this.makeRequest(baseEndpoint, ...endpoint)
|
||||
return this.actualFetch<T>(this.getFullURL([baseEndpoint, ...endpoint]))
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to make the request and normalize the whole path
|
||||
* @param endpoint the endpoint to fetch
|
||||
* @param query the query
|
||||
*/
|
||||
private makeRequest<T = any>(...url: Array<string | number>) {
|
||||
public async fetchWithQuery<T = object>(
|
||||
endpoint: [Endpoints, ...Array<string>],
|
||||
query?: Array<{ key: string, value: string | number | boolean }>
|
||||
): Promise<T | undefined> {
|
||||
if (endpoint.length === 0) {
|
||||
throw new Error('endpoint to fetch is empty!')
|
||||
}
|
||||
const baseEndpoint = endpoint[0].toLowerCase() as Endpoints
|
||||
if (!ENDPOINTS.includes(baseEndpoint)) {
|
||||
throw new Error(`unknown endpoint to fetch! (${baseEndpoint})`)
|
||||
}
|
||||
return this.actualFetch<T>(this.getFullURL(endpoint, query))
|
||||
}
|
||||
|
||||
/**
|
||||
* format the final URL
|
||||
*/
|
||||
private getFullURL(
|
||||
url: Array<string | number>,
|
||||
searchParams?: Array<{ key: string, value: string | number | boolean }>
|
||||
): string {
|
||||
// Normalize path
|
||||
const path = url.map((subPath) => encodeURI(
|
||||
subPath
|
||||
let path = url.map(this.encode).join('/')
|
||||
|
||||
// handle the Search Params
|
||||
if (searchParams) {
|
||||
path += '?' + searchParams.map((it) => `${this.encode(it.key)}=${this.encode(it.value)}`).join('&')
|
||||
}
|
||||
|
||||
// return with the endpoint and all the shit
|
||||
return `${this.getEndpoint()}/${this.getLang()}/${path}`
|
||||
}
|
||||
|
||||
private async actualFetch<T = object>(path: string): Promise<T | undefined> {
|
||||
// get and return the cached value if available
|
||||
const cached = this.cache.get(path)
|
||||
if (cached) {
|
||||
return cached as T
|
||||
}
|
||||
|
||||
// the actual Fetch :D
|
||||
const resp = await TCGdex.fetch(path, {
|
||||
headers: {
|
||||
'user-agent': `@tcgdex/javascript-sdk/${version}`
|
||||
}
|
||||
})
|
||||
|
||||
// throw if a server-side error is occured
|
||||
if (resp.status >= 500) {
|
||||
try {
|
||||
const json = JSON.stringify(await resp.json())
|
||||
throw new Error(json)
|
||||
} catch {
|
||||
throw new Error('TCGdex Server responded with an invalid error :(')
|
||||
}
|
||||
}
|
||||
|
||||
// response is not valid :O
|
||||
if (resp.status !== 200) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
// parse, put to cache and return
|
||||
const json = await resp.json()
|
||||
this.cache.set(path, json, this.cacheTTL)
|
||||
return json as T
|
||||
}
|
||||
|
||||
/**
|
||||
* encode a string to be used in an url
|
||||
* @param str the string to encode to URL
|
||||
* @returns the encoded string
|
||||
*/
|
||||
private encode(str: string | number | boolean): string {
|
||||
return encodeURI(
|
||||
str
|
||||
// Transform numbers to string
|
||||
.toString()
|
||||
// replace this special character with an escaped one
|
||||
.replace('?', '%3F')
|
||||
// normalize the string
|
||||
.normalize('NFC')
|
||||
// remove some special chars by nothing
|
||||
// remove some special chars
|
||||
// eslint-disable-next-line no-misleading-character-class
|
||||
.replace(/["'\u0300-\u036f]/gu, '')
|
||||
)).join('/')
|
||||
return RequestWrapper.fetch<T>(`${BASE_URL}/${this.getLang()}/${path}`)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export * from './interfaces'
|
||||
|
||||
export * from './models/Card'
|
||||
export {
|
||||
Query
|
||||
}
|
||||
|
20
src/utils.ts
Normal file
20
src/utils.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import type { Endpoints } from './interfaces'
|
||||
|
||||
/**
|
||||
* detect the current running context ofthe program
|
||||
*/
|
||||
export function detectContext(): 'browser' | 'server' {
|
||||
try {
|
||||
const isBrowser = !!window
|
||||
return isBrowser ? 'browser' : 'server'
|
||||
} catch {
|
||||
return 'server'
|
||||
}
|
||||
}
|
||||
|
||||
export const ENDPOINTS: Array<Endpoints> = [
|
||||
'cards', 'categories', 'dex-ids', 'energy-types',
|
||||
'hp', 'illustrators', 'rarities', 'regulation-marks',
|
||||
'retreats', 'series', 'sets', 'stages', 'suffixes',
|
||||
'trainer-types', 'types', 'variants', 'random'
|
||||
] as const
|
@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["./src/tcgdex.node.ts"],
|
||||
"compilerOptions": {
|
||||
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"declaration": false, /* Generates corresponding '.d.ts' file. */
|
||||
"declarationDir": null,
|
||||
"outDir": "./dist/modules", /* Redirect output structure to the directory. */
|
||||
}
|
||||
}
|
@ -1,15 +1,10 @@
|
||||
{
|
||||
"extends": "./node_modules/@dzeio/config/tsconfig.base",
|
||||
"include": ["./src/tcgdex.node.ts"],
|
||||
"compilerOptions": {
|
||||
|
||||
"target": "ES2015",
|
||||
|
||||
"declaration": true,
|
||||
"declarationDir": "./dist/types",
|
||||
|
||||
"outDir": "./dist/cjs",
|
||||
"rootDir": "./src",
|
||||
|
||||
}
|
||||
"outDir": "dist",
|
||||
"strictNullChecks": true
|
||||
},
|
||||
"exclude": [
|
||||
"__tests__"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user