dummy-ts-sdk
v1.1.2
Published
A TypeScript SDK for interacting with the Dummy API. This package provides a simple and type-safe interface for working with the API in Node.js or browser environments.
Downloads
8
Readme
Dummy TypeScript SDK
A TypeScript SDK for interacting with the Dummy API. This package provides a simple and type-safe interface for working with the API in Node.js or browser environments.
Features
- Written in TypeScript with full type declarations
- Compatible with both CommonJS and ES Modules
- Includes UMD build for browser environments
- Easily extendable to add more API endpoints
Installation
Install the SDK via npm:
npm install dummy-ts-sdkUsage
CommonJS
const { Library } = require("dummy-ts-sdk");
const sdk = new Library({
apiKey: "your-api-key",
baseUrl: "https://api.example.com",
});
sdk.posts.getPosts().then((posts) => console.log(posts));ES Modules
import { Library } from "dummy-ts-sdk";
const sdk = new Library({
apiKey: "your-api-key",
baseUrl: "https://api.example.com",
});
sdk.posts.getPosts().then((posts) => console.log(posts));Browser (via unpkg)
<script src="https://unpkg.com/[email protected]"></script>
<script>
const sdk = new dummyTsSdk.Library({
apiKey: "your-api-key",
baseUrl: "https://api.example.com",
});
sdk.posts.getPosts().then((posts) => console.log(posts));
</script>SDK Documentation
Library
The Library class is the main entry point for interacting with the Dummy API. It provides access to the following services:
posts: Methods for working with post-related endpointsusers: Methods for working with user-related endpoints
Example
const sdk = new Library({
apiKey: "your-api-key",
baseUrl: "https://api.example.com",
});
// Get a list of posts
sdk.posts.getPosts().then((posts) => console.log(posts));Configuration
To configure the SDK for your project, you can modify the tsconfig.json file or use the defaults. Here's a basic setup:
{
"compilerOptions": {
"target": "ES2017",
"module": "ESNext",
"outDir": "./dist"
}
}For more detailed configuration options and their explanations, see the full TypeScript Configuration Documentation.
TypeScript Configuration Documentation
Compiler Options
| Option | Value | Description |
| ---------------------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| target | "ES2017" | Specifies the ECMAScript target version. ES2017 provides a balance between modern features and compatibility. |
| module | "ESNext" | Specifies the module code generation. ESNext allows bundlers like Rollup or Webpack to decide which module system to use. |
| moduleResolution | "node" | Defines how TypeScript resolves modules. node is used for Node.js-style module resolution. |
| lib | ["ES2017", "DOM"] | Specifies the libraries to be included in the compilation. ES2017 includes modern JavaScript features, and DOM provides support for browser APIs. |
| declaration | true | Generates corresponding .d.ts (declaration) files for your TypeScript code, making your SDK usable with TypeScript consumers. |
| declarationMap | true | Generates .d.ts.map files to allow consumers to debug TypeScript files. Optional, can increase package size. |
| removeComments | true | Removes comments from the compiled output to reduce file size. |
| allowSyntheticDefaultImports | true | Allows default imports from modules that don’t have a default export, improving compatibility with non-ES modules. |
| esModuleInterop | true | Ensures compatibility between CommonJS and ES Modules by enabling default imports from CommonJS modules. |
| skipLibCheck | true | Skips type-checking for library files to improve build performance. Recommended for speeding up builds. |
| sourceMap | false | Disables generation of source maps for the JavaScript output, keeping the package lightweight. |
| outDir | "./dist" | Specifies the directory where the compiled JavaScript files are output. |
| baseUrl | "./" | Sets the base URL for resolving non-relative module imports. |
| strict | true | Enables strict type-checking options, which help catch potential errors early and enforce best practices. |
| incremental | true | Enables incremental builds for faster recompilation during development. |
Include and Exclude Patterns
| Option | Value | Description |
| ------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| include | ["src/**/*"] | Specifies the files to include in the compilation. Here, all files under the src directory are included. |
| exclude | ["node_modules", "dist", "test", "lib", "**/*spec.ts"] | Excludes directories and files that should not be part of the build. This includes test files, node modules, and output folders. |
