kbisdk
v1.0.0
Published
A TypeScript SDK with CommonJS and ESM support
Maintainers
Readme
My SDK
A TypeScript SDK with CommonJS and ESM support, built with tsup and ready for npm publishing.
Features
- ✅ TypeScript support with full type definitions
- ✅ CommonJS and ESM builds
- ✅ Source maps included
- ✅ Tree-shaking friendly
- ✅ Zero dependencies
- ✅ TypeScript autocompletion
Installation
npm install my-sdkUsage
TypeScript
import { greet, add, multiply, createUser, isValidEmail, MySDK } from 'my-sdk';
// Simple functions
const message = greet('World'); // "Hello, World!"
const sum = await add(5, 3); // 8
const product = multiply(4, 7); // 28
// User creation
const user = createUser('John Doe', '[email protected]', 30);
console.log(user); // { name: 'John Doe', email: '[email protected]', age: 30, id: '...' }
// Email validation
const isValid = isValidEmail('[email protected]'); // true
// SDK class
const sdk = new MySDK({
apiKey: 'your-api-key',
baseUrl: 'https://api.example.com',
timeout: 10000
});
const response = await sdk.makeRequest('/users');JavaScript (CommonJS)
const { greet, add, multiply, createUser, isValidEmail, MySDK } = require('my-sdk');
// Use the same functions as above
const message = greet('World');
const sum = await add(5, 3);
// ... etcJavaScript (ESM)
import { greet, add, multiply, createUser, isValidEmail, MySDK } from 'my-sdk';
// Use the same functions as above
const message = greet('World');
const sum = await add(5, 3);
// ... etcAPI Reference
Functions
greet(name: string): string
Returns a greeting message.
add(a: number, b: number): Promise<number>
Adds two numbers asynchronously.
multiply(a: number, b: number): number
Multiplies two numbers.
createUser(name: string, email: string, age?: number): User
Creates a user object with a generated ID.
isValidEmail(email: string): boolean
Validates an email address format.
Classes
MySDK
Main SDK class for more complex operations.
Constructor:
new MySDK(config?: SDKConfig)
Methods:
getConfig(): SDKConfig- Get current configurationupdateConfig(newConfig: Partial<SDKConfig>): void- Update configurationmakeRequest(endpoint: string): Promise<unknown>- Make a mock API request
Types
User
interface User {
name: string;
email: string;
age?: number;
id: string;
}SDKConfig
interface SDKConfig {
apiKey?: string;
baseUrl?: string;
timeout?: number;
}Development
Prerequisites
- Node.js 16+
- npm
Setup
# Install dependencies
npm install
# Build the project
npm run build
# Watch mode for development
npm run dev
# Clean build directory
npm run cleanPublishing
# Build and publish to npm
npm run prepublishOnly
npm publishLicense
MIT
