{"_id":"@akikungz/warpper-ts","_rev":"4-53c431ba76edd492b1aefd5dc59f9fbc","name":"@akikungz/warpper-ts","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.0":{"name":"@akikungz/warpper-ts","version":"1.0.0","keywords":[],"author":"","license":"ISC","_id":"@akikungz/warpper-ts@1.0.0","maintainers":[{"name":"akikungz","email":"akikungz@proton.me"}],"dist":{"shasum":"0f1dbda9d2a511c9c8629b53141cd50d2604f8b9","tarball":"https://registry.npmjs.org/@akikungz/warpper-ts/-/warpper-ts-1.0.0.tgz","fileCount":6,"integrity":"sha512-oc1jIDmru44xX1IeJTPUTLfQ1BQ+ZdRxzJkQG/1F1jzfq8GrevG4/Rd90e4HBzZBVDMzk84SvPgAZkYiAEmJjQ==","signatures":[{"sig":"MEUCIDXPoJ9l4UAuHTBUQJeJ9TX4n1VXJDNH+1+5kD1sQcS0AiEA5wYLtMLusgLYlES61lr9063WbBxJctK+Sj7tLMnkhmQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":4790},"main":"dist/index.js","type":"commonjs","scripts":{"test":"jest","build":"tsc"},"_npmUser":{"name":"akikungz","email":"akikungz@proton.me"},"_npmVersion":"11.5.1","description":"","directories":{},"_nodeVersion":"24.7.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.4","typescript":"^5.9.2","@types/jest":"^30.0.0","@types/node":"^24.5.2"},"_npmOperationalInternal":{"tmp":"tmp/warpper-ts_1.0.0_1759167807034_0.35488934097314195","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@akikungz/warpper-ts","version":"1.0.1","keywords":["typescript","wrapper","utility"],"author":{"name":"akikungz"},"license":"ISC","_id":"@akikungz/warpper-ts@1.0.1","maintainers":[{"name":"akikungz","email":"akikungz@proton.me"}],"homepage":"https://github.com/akikungz/warpper-ts#readme","bugs":{"url":"https://github.com/akikungz/warpper-ts/issues"},"dist":{"shasum":"28a3b89d15abd609b5b38d0c1e37434bef53bf6e","tarball":"https://registry.npmjs.org/@akikungz/warpper-ts/-/warpper-ts-1.0.1.tgz","fileCount":10,"integrity":"sha512-xQ6gfnJhGiEpc3t9UkinD0itV8mUhtG3tvIamer2ZzRQ6LsS8QckDJDK3TcTN5XSn8nssjrnx+SqUcIY/mGnGA==","signatures":[{"sig":"MEUCIA7o9CkHOrZSlbqN7DdRh/U7EDjmzLxaneGEoucnC+uBAiEAu8bNgh3Acboz+v0qAgqrrWhltSxJBhfMkPVf0qI39Tg=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12835},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"e34bb29996341835c7000cfbe762fafcef429677","scripts":{"test":"jest","build":"tsc","clean":"rm -rf dist","prepare":"npm run build","prepublishOnly":"npm run clean && npm run build && npm test"},"_npmUser":{"name":"akikungz","email":"akikungz@proton.me"},"repository":{"url":"git+https://github.com/akikungz/warpper-ts.git","type":"git"},"_npmVersion":"11.5.1","description":"A TypeScript wrapper utility","directories":{},"_nodeVersion":"24.7.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.4","typescript":"^5.9.2","@types/jest":"^30.0.0","@types/node":"^24.5.2"},"_npmOperationalInternal":{"tmp":"tmp/warpper-ts_1.0.1_1759168785963_0.7455452908480806","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@akikungz/warpper-ts","version":"1.0.3","keywords":["typescript","wrapper","utility"],"author":{"name":"akikungz"},"license":"ISC","_id":"@akikungz/warpper-ts@1.0.3","maintainers":[{"name":"akikungz","email":"akikungz@proton.me"}],"homepage":"https://github.com/akikungz/warpper-ts#readme","bugs":{"url":"https://github.com/akikungz/warpper-ts/issues"},"dist":{"shasum":"d665643a6d14adfbc1169753b674443b1829952e","tarball":"https://registry.npmjs.org/@akikungz/warpper-ts/-/warpper-ts-1.0.3.tgz","fileCount":10,"integrity":"sha512-q4JwgN+1Fd+BAKehj8NTyFGHl63knmevU2hXZ76bCiKQmNIQAhqxbTQJseQzOe1e0Uut491Q1TgFmMkNwM3f2w==","signatures":[{"sig":"MEUCIQCokG2HTphJpFVZ+7a1WvHf6XgCRUTFhTM8WnSROhYcVgIgUlBkG9py7YvHhuGbwxgO/r5EJNKKZNU2by64wOk426Y=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12841},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"341bdbd36176c98de523d736ae2d1ef0643c8f43","scripts":{"test":"jest","build":"tsc","clean":"rm -rf dist","prepare":"npm run build","prepublishOnly":"npm run clean && npm run build && npm test"},"_npmUser":{"name":"akikungz","email":"akikungz@proton.me"},"repository":{"url":"git+https://github.com/akikungz/warpper-ts.git","type":"git"},"_npmVersion":"11.5.1","description":"A TypeScript wrapper utility","directories":{},"_nodeVersion":"24.7.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.2.0","ts-jest":"^29.4.4","typescript":"^5.9.2","@types/jest":"^30.0.0","@types/node":"^24.5.2"},"_npmOperationalInternal":{"tmp":"tmp/warpper-ts_1.0.3_1759169503983_0.5673394339347981","host":"s3://npm-registry-packages-npm-production"}},"1.0.4":{"name":"@akikungz/warpper-ts","version":"1.0.4","description":"A TypeScript wrapper utility","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"test":"jest","build":"tsc","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run build && npm test","prepare":"npm run build"},"keywords":["typescript","wrapper","utility"],"author":{"name":"akikungz"},"license":"ISC","type":"commonjs","repository":{"type":"git","url":"git+https://github.com/akikungz/warpper-ts.git"},"bugs":{"url":"https://github.com/akikungz/warpper-ts/issues"},"homepage":"https://github.com/akikungz/warpper-ts#readme","publishConfig":{"access":"public"},"devDependencies":{"@types/jest":"^30.0.0","@types/node":"^24.5.2","jest":"^30.2.0","ts-jest":"^29.4.4","typescript":"^5.9.2"},"_id":"@akikungz/warpper-ts@1.0.4","gitHead":"7d7f610805e279f441257d2a752b1483942a7108","_nodeVersion":"24.7.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-C1IhLrCl+SmIsdJGL0DxjWm/PmcP7Ai95vWQ1stPQ8hKxBEPaqh12QmEGTkO4gFAr/QDNy73yIABg7GGo8Izjw==","shasum":"79864df793a53a703c9e4f196104e61609bc491b","tarball":"https://registry.npmjs.org/@akikungz/warpper-ts/-/warpper-ts-1.0.4.tgz","fileCount":10,"unpackedSize":12949,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGwGjaXNODX3Hs2EAqCLpovrMWiHAxwhAZ0BjJTV05qcAiAfb40pYkYlZ68Jey5hMp5ukjzTUuFR4l3Xv6vRxmaBKQ=="}]},"_npmUser":{"name":"akikungz","email":"akikungz@proton.me"},"directories":{},"maintainers":[{"name":"akikungz","email":"akikungz@proton.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/warpper-ts_1.0.4_1759172981003_0.3781342170666169"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-29T17:43:26.928Z","modified":"2025-09-29T19:09:41.699Z","1.0.0":"2025-09-29T17:43:27.226Z","1.0.1":"2025-09-29T17:59:46.159Z","1.0.3":"2025-09-29T18:11:44.202Z","1.0.4":"2025-09-29T19:09:41.179Z"},"bugs":{"url":"https://github.com/akikungz/warpper-ts/issues"},"author":{"name":"akikungz"},"license":"ISC","homepage":"https://github.com/akikungz/warpper-ts#readme","keywords":["typescript","wrapper","utility"],"repository":{"type":"git","url":"git+https://github.com/akikungz/warpper-ts.git"},"description":"A TypeScript wrapper utility","maintainers":[{"name":"akikungz","email":"akikungz@proton.me"}],"readme":"# warpper-ts\r\n\r\nA TypeScript wrapper utility package that provides error-safe function execution. Instead of throwing exceptions, it returns a tuple with either an error or result, similar to Go's error handling pattern.\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @akikungz/warpper-ts\r\n```\r\n\r\n## Usage\r\n\r\n### Basic Import\r\n\r\n```typescript\r\nimport { warpper } from '@akikungz/warpper-ts';\r\n```\r\n\r\n### Simple Functions\r\n\r\n```typescript\r\n// Synchronous function\r\nconst [error, result] = await warpper(() => 42);\r\nif (error) {\r\n  console.error('Error:', error.message);\r\n} else {\r\n  console.log('Result:', result); // 42\r\n}\r\n```\r\n\r\n### Async Functions\r\n\r\n```typescript\r\n// Asynchronous function\r\nconst [error, data] = await warpper(async () => {\r\n  const response = await fetch('https://api.example.com/data');\r\n  return response.json();\r\n});\r\n\r\nif (error) {\r\n  console.error('API call failed:', error.message);\r\n} else {\r\n  console.log('Data received:', data);\r\n}\r\n```\r\n\r\n### Functions with Parameters\r\n\r\n```typescript\r\n// Function with parameters\r\nconst divide = (a: number, b: number) => {\r\n  if (b === 0) throw new Error('Division by zero');\r\n  return a / b;\r\n};\r\n\r\nconst [error, result] = await warpper(divide, [10, 2]);\r\nif (error) {\r\n  console.error('Division failed:', error.message);\r\n} else {\r\n  console.log('Result:', result); // 5\r\n}\r\n```\r\n\r\n### Error Handling\r\n\r\n```typescript\r\n// Function that throws an error\r\nconst riskyFunction = () => {\r\n  throw new Error('Something went wrong!');\r\n};\r\n\r\nconst [error, result] = await warpper(riskyFunction);\r\nconsole.log(error?.message); // \"Something went wrong!\"\r\nconsole.log(result); // null\r\n```\r\n\r\n### Real-world Example\r\n\r\n```typescript\r\nimport { warpper } from '@akikungz/warpper-ts';\r\nimport fs from 'fs/promises';\r\n\r\nasync function readConfigFile(filename: string) {\r\n  const [readError, content] = await warpper(fs.readFile, [filename, 'utf8']);\r\n  if (readError) {\r\n    return [readError, null];\r\n  }\r\n\r\n  const [parseError, config] = await warpper(JSON.parse, [content]);\r\n  if (parseError) {\r\n    return [new Error(`Invalid JSON in ${filename}: ${parseError.message}`), null];\r\n  }\r\n\r\n  return [null, config];\r\n}\r\n\r\n// Usage\r\nconst [error, config] = await readConfigFile('config.json');\r\nif (error) {\r\n  console.error('Failed to load config:', error.message);\r\n  process.exit(1);\r\n} else {\r\n  console.log('Config loaded successfully:', config);\r\n}\r\n```\r\n\r\n### TypeScript Support\r\n\r\nThe package includes full TypeScript support with proper type inference:\r\n\r\n```typescript\r\n// Type inference works automatically\r\nconst [error, num] = await warpper(() => 42);\r\n// num is inferred as number\r\n\r\nconst [error, str] = await warpper(async () => 'hello');\r\n// str is inferred as string\r\n\r\n// Custom error types\r\nclass CustomError extends Error {\r\n  code: number;\r\n  constructor(message: string, code: number) {\r\n    super(message);\r\n    this.code = code;\r\n  }\r\n}\r\n\r\nconst throwCustomError = () => {\r\n  throw new CustomError('Custom error', 404);\r\n};\r\n\r\nconst [error, result] = await warpper<typeof throwCustomError, CustomError>(throwCustomError);\r\n// error is typed as CustomError | null\r\n```\r\n\r\n## API Reference\r\n\r\n### `warpper<TFunction, TError, TResult>(callback, args?)`\r\n\r\nExecutes a callback function and returns a promise that resolves with a tuple containing an error (if any) and the result.\r\n\r\n#### Parameters\r\n\r\n- `callback: TFunction` - The function to execute\r\n- `args?: Parameters<TFunction>` - Optional array of arguments to pass to the callback function\r\n\r\n#### Returns\r\n\r\n`Promise<[TError | null, TResult]>` - A tuple where:\r\n- First element: Error object if the function throws, `null` if successful\r\n- Second element: Function result if successful, `null` if an error occurred\r\n\r\n#### Type Parameters\r\n\r\n- `TFunction extends (...args: any[]) => any` - The callback function type\r\n- `TError extends Error = Error` - The expected error type (defaults to Error)\r\n- `TResult` - The return type (automatically inferred from TFunction)\r\n\r\n## GitHub Actions Setup\r\n\r\nThis repository includes automated CI/CD workflows using GitHub Actions for testing and publishing to npm.\r\n\r\n### Workflows\r\n\r\n1. **CI Workflow** (`.github/workflows/ci.yml`)\r\n   - Runs on push/PR to main/master branches\r\n   - Tests against Node.js versions 18.x, 20.x, and 22.x\r\n   - Runs tests and builds the package\r\n\r\n2. **Publish Workflow** (`.github/workflows/publish.yml`)\r\n   - Triggers when a GitHub release is published\r\n   - Runs tests, builds, and publishes to npm\r\n\r\n3. **Version and Release Workflow** (`.github/workflows/version-and-release.yml`)\r\n   - Auto-bumps version based on conventional commits\r\n   - Creates GitHub releases automatically\r\n\r\n### Setup Instructions\r\n\r\n#### 1. NPM Token Setup\r\n\r\nTo enable automatic publishing to npm, you need to set up an NPM token:\r\n\r\n1. Go to [npmjs.com](https://www.npmjs.com) and log in\r\n2. Go to Access Tokens in your account settings\r\n3. Create a new token with \"Automation\" type\r\n4. In your GitHub repository, go to Settings → Secrets and variables → Actions\r\n5. Create a new repository secret named `NPM_TOKEN` with your token value\r\n\r\n#### 2. Repository Permissions\r\n\r\nMake sure your repository has the following permissions:\r\n\r\n1. Go to Settings → Actions → General\r\n2. Set \"Workflow permissions\" to \"Read and write permissions\"\r\n3. Check \"Allow GitHub Actions to create and approve pull requests\"\r\n\r\n#### 3. Branch Protection (Optional but Recommended)\r\n\r\n1. Go to Settings → Branches\r\n2. Add a branch protection rule for `main` (or `master`)\r\n3. Require status checks to pass before merging\r\n4. Require branches to be up to date before merging\r\n\r\n### How It Works\r\n\r\n#### Automatic Testing\r\n- Every push or pull request triggers the CI workflow\r\n- Tests run on multiple Node.js versions\r\n- Build verification ensures the package compiles correctly\r\n\r\n#### Automatic Publishing\r\n- Create a new release on GitHub (either manually or automatically)\r\n- The publish workflow will automatically:\r\n  - Run tests\r\n  - Build the package\r\n  - Publish to npm with the version from package.json\r\n\r\n#### Automatic Versioning (Optional)\r\n- The version-and-release workflow can automatically bump versions based on commit messages\r\n- Use conventional commit messages:\r\n  - `feat:` for minor version bumps\r\n  - `fix:` for patch version bumps\r\n  - `BREAKING CHANGE:` for major version bumps\r\n\r\n### Manual Release Process\r\n\r\n1. Update the version in `package.json`:\r\n   ```bash\r\n   npm version patch  # or minor, major\r\n   ```\r\n\r\n2. Push the changes:\r\n   ```bash\r\n   git push\r\n   git push --tags\r\n   ```\r\n\r\n3. Create a release on GitHub:\r\n   - Go to Releases → Create a new release\r\n   - Choose the tag you just pushed\r\n   - Add release notes\r\n   - Publish the release\r\n\r\n4. The publish workflow will automatically run and publish to npm\r\n\r\n### Local Development\r\n\r\n```bash\r\n# Install dependencies\r\nnpm install\r\n\r\n# Run tests\r\nnpm test\r\n\r\n# Build the package\r\nnpm run build\r\n\r\n# Test publishing (dry run)\r\nnpm publish --dry-run\r\n```\r\n\r\n## Package Information\r\n\r\n- **Name**: `@akikungz/warpper-ts`\r\n- **Registry**: npm (public)\r\n- **Built with**: TypeScript\r\n- **Tested with**: Jest\r\n\r\n## Contributing\r\n\r\n1. Fork the repository\r\n2. Create a feature branch\r\n3. Make your changes\r\n4. Run tests: `npm test`\r\n5. Build the package: `npm run build`\r\n6. Submit a pull request\r\n\r\nThe CI workflow will automatically test your changes across multiple Node.js versions.","readmeFilename":"README.md"}