@i0p1/standard-result
v1.0.1
Published
A standardized result type for TypeScript
Downloads
171
Maintainers
Readme
Standard Result
A standardized result type for TypeScript with full CommonJS and ES Module support.
Installation
npm install standard-resultUsage
TypeScript / ES Module
import { createResult, type Result, type BaseOptions } from "standard-result";
// Create a success result
const successResult = createResult({
status: "success",
data: { userId: 123 },
message: "User created successfully",
});
// Create an error result
const errorResult = createResult({
status: "error",
message: "User not found",
});CommonJS
const { createResult } = require("standard-result");
const result = createResult({
status: "success",
data: { value: 42 },
});API
Types
Status:"error" | "success"Level:"error" | "success" | "warn" | "info"BaseOptions: Configuration object for creating resultsResult<O>: The result type with inferred properties
Functions
createResult<O extends BaseOptions>(options: O): Result<O>
Creates a standardized result object with the following properties:
status: The status of the resultlevel: The severity level (defaults to status if not specified)timestamp: ISO timestamp stringdata: Optional data payloadmessage: Optional message string
License
MIT
