Skip to content

Commit

Permalink
Merge pull request #1 from krauters/package-json
Browse files Browse the repository at this point in the history
Package Json Interface
  • Loading branch information
coltenkrauter committed Nov 3, 2024
2 parents f341146 + 1f8ae71 commit 00cbf88
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 138 deletions.
87 changes: 74 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,89 @@
# Typescript Core
A TypeScript Repository that stands as a starting point for all other TypeScript repositories.
<div align="center">

## Husky
<a href="https://www.linkedin.com/in/coltenkrauter/" target="_blank"><img src="https://img.shields.io/badge/LinkedIn-%230077B5.svg?&style=flat-square&logo=linkedin&logoColor=white" alt="LinkedIn"></a>
![License](https://img.shields.io/github/license/krauters/structures)
![Visitors](https://visitor-badge.laobi.icu/badge?page_id=krauters.structures)

Husky helps manage Git hooks easily, automating things like running tests or linting before a commit is made. This ensures your code is in good shape.
![Version](https://img.shields.io/github/v/release/krauters/structures)
[![npm version](https://img.shields.io/npm/v/@krauters/structures.svg?style=flat-square)](https://www.npmjs.org/package/@krauters/structures)
![GitHub Stars](https://img.shields.io/github/stars/krauters/structures)
![Forks](https://img.shields.io/github/forks/krauters/structures)

Pre-commit hooks run scripts before a commit is finalized to catch issues or enforce standards. With Husky, setting up these hooks across your team becomes easy, keeping your codebase clean and consistent.
![GitHub Issues](https://img.shields.io/github/issues/krauters/structures)
![Open PRs](https://img.shields.io/github/issues-pr/krauters/structures)
![Commits per Month](https://img.shields.io/github/commit-activity/m/krauters/structures)
![Contributors](https://img.shields.io/github/contributors/krauters/structures)
![Last Commit](https://img.shields.io/github/last-commit/krauters/structures)

### Our Custom Pre-Commit Hook
[![Install Size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=@krauters/structures&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.now.sh/result?p=@krauters/structures)
![Code Size](https://img.shields.io/github/languages/code-size/krauters/structures)
![Repo Size](https://img.shields.io/github/repo-size/krauters/structures)

This project uses a custom pre-commit hook to run `npm run bundle`. This ensures that our bundled assets are always up to date before any commit (which is especially important for TypeScript GitHub Actions). Husky automates this, so no commits will go through without a fresh bundle, keeping everything streamlined.
</div>

# @krauters/structures

`@krauters/structures` is a TypeScript library providing robust and well-defined enums, interfaces, and types for common structures in modern applications. It’s built to simplify shared data modeling, enhance type safety, and support consistent code standards across projects.

## Usage

This library is particularly useful for projects needing a shared set of structures, enums, and data models. For instance:

```ts
import { HttpStatus, LanguageCode, Env } from '@krauters/structures'

// Example usage
const currentEnv: Env = Env.Production

if (currentEnv === Env.Development) {
console.log('Running in development mode')
}

function handleResponse(status: HttpStatus) {
if (status === HttpStatus.Ok) {
console.log('Request succeeded!')
} else if (status === HttpStatus.NotFound) {
console.error('Resource not found')
}
}
```

## Installation

Add `@krauters/structures` to your project:

```zsh
npm install @krauters/structures@latest
```

## Overview

`@krauters/structures` provides various enums and types for structuring application data. The core elements include:

- **Environment (Env)**: Enums for standard environment types like `Development`, `Production`, and `Pipeline`.
- **HTTP Status Codes (HttpStatus)**: Enums for common HTTP statuses (e.g., `Ok`, `NotFound`, `InternalServerError`).
- **Language Codes (LanguageCode)**: ISO language codes for major languages, making localization simple.
- **File Metadata (FileExtension, FileEncoding)**: Standard file extensions and encoding types for easier file handling.
- **Response Types (ResponseType)**: Defines response formats such as `json`, `blob`, and `text`.

These structures help keep code clean and predictable, while TypeScript’s type-checking reduces errors.

## Contributing

The goal of this project is to continually evolve and improve its core features, making it more efficient and easier to use. Development happens openly here on GitHub, and we’re thankful to the community for contributing bug fixes, enhancements, and fresh ideas. Whether you're fixing a small bug or suggesting a major improvement, your input is invaluable.
We’re always looking to improve this library. Contributions are welcome, whether it’s adding new structures, improving existing ones, or updating documentation. Please open an issue or pull request if you’d like to contribute!

## License

This project is licensed under the ISC License. Please see the [LICENSE](./LICENSE) file for more details.
Licensed under the ISC License. For more information, see the [LICENSE](./LICENSE) file.

## 🥂 Thanks Contributors
## 🥂 Thanks, Contributors!

Thanks for spending time on this project.
Special thanks to all who’ve helped improve this project.

<a href="https://github.com/krauters/typescript-core/graphs/contributors">
<img src="https://contrib.rocks/image?repo=krauters/typescript-core" />
<a href="https://github.com/krauters/structures/graphs/contributors">
<img src="https://contrib.rocks/image?repo=krauters/structures" />
</a>

<br />
<br />
<a href="https://www.buymeacoffee.com/coltenkrauter"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=coltenkrauter&button_colour=FFDD00&font_colour=```&font_family=Cookie&outline_colour=```&coffee_colour=ffffff" /></a>
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@krauters/structures",
"description": "Common TypeScript types, enums, and interfaces to standardize structures across projects.",
"version": "0.0.0",
"main": "dist/index.js",
"version": "1.0.2",
"main": "dist/src/index.js",
"type": "commonjs",
"scripts": {
"build": "tsc",
Expand All @@ -18,6 +18,7 @@
"keywords": [
"enums",
"interfaces",
"package-json",
"structures",
"typescript"
],
Expand Down
123 changes: 2 additions & 121 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,2 @@
export enum Env {
Alpha = 'Alpha',
Beta = 'Beta',
Development = 'Development',
Gamma = 'Gamma',
Pipeline = 'Pipeline',
Production = 'Production',
Unknown = 'Unknown',
}

export enum HttpStatus {
Accepted = 202,
BadGateway = 502,
BadRequest = 400,
Conflict = 409,
Created = 201,
Forbidden = 403,
GatewayTimeout = 504,
Gone = 410,
HttpVersionNotSupported = 505,
InternalServerError = 500,
MethodNotAllowed = 405,
NoContent = 204,
NotAcceptable = 406,
NotFound = 404,
NotImplemented = 501,
Ok = 200,
PartialContent = 206,
PaymentRequired = 402,
ResetContent = 205,
ServiceUnavailable = 503,
TooManyRequests = 429,
Unauthorized = 401,
UnavailableForLegalReasons = 451,
}

export enum HttpMethod {
DELETE = 'DELETE',
GET = 'GET',
HEAD = 'HEAD',
OPTIONS = 'OPTIONS',
PATCH = 'PATCH',
POST = 'POST',
PUT = 'PUT',
}

export enum HttpContentType {
Css = 'text/css',
FormUrlEncoded = 'application/x-www-form-urlencoded',
Html = 'text/html',
Javascript = 'application/javascript',
Json = 'application/json',
MultipartFormData = 'multipart/form-data',
TextPlain = 'text/plain',
Xml = 'application/xml',
}

export enum FileExtension {
CSS = 'css',
CSV = 'csv',
DLL = 'dll',
DOCX = 'docx',
EXE = 'exe',
HTML = 'html',
JPG = 'jpg',
JS = 'js',
JSON = 'json',
MKV = 'mkv',
MP3 = 'mp3',
MP4 = 'mp4',
PDF = 'pdf',
PNG = 'png',
RAR = 'rar',
TS = 'ts',
TXT = 'txt',
XML = 'xml',
ZIP = 'zip',
}

export enum FileEncoding {
ASCII = 'ascii',
Base64 = 'base64',
Binary = 'binary',
Hex = 'hex',
ISO88591 = 'iso-8859-1',
ISO88592 = 'iso-8859-2',
UCS2 = 'ucs2',
UTF16LE = 'utf16le',
UTF32 = 'utf32',
UTF8 = 'utf-8',
Windows1252 = 'windows-1252',
}

export enum LanguageCode {
Chinese = 'zh',
English = 'en',
French = 'fr',
German = 'de',
Hindi = 'hi',
Spanish = 'es',
}

export enum Status {
Active = 'Active',
Canceled = 'Canceled',
Completed = 'Completed',
Failed = 'Failed',
Inactive = 'Inactive',
Pending = 'Pending',
Suspended = 'Suspended',
}

export enum ResponseType {
ArrayBuffer = 'arraybuffer',
Blob = 'blob',
Document = 'document',
FormData = 'formdata',
Json = 'json',
Stream = 'stream',
Text = 'text',
}
export * from './misc'
export type * from './package-json'
121 changes: 121 additions & 0 deletions src/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
export enum Env {
Alpha = 'Alpha',
Beta = 'Beta',
Development = 'Development',
Gamma = 'Gamma',
Pipeline = 'Pipeline',
Production = 'Production',
Unknown = 'Unknown',
}

export enum HttpStatus {
Accepted = 202,
BadGateway = 502,
BadRequest = 400,
Conflict = 409,
Created = 201,
Forbidden = 403,
GatewayTimeout = 504,
Gone = 410,
HttpVersionNotSupported = 505,
InternalServerError = 500,
MethodNotAllowed = 405,
NoContent = 204,
NotAcceptable = 406,
NotFound = 404,
NotImplemented = 501,
Ok = 200,
PartialContent = 206,
PaymentRequired = 402,
ResetContent = 205,
ServiceUnavailable = 503,
TooManyRequests = 429,
Unauthorized = 401,
UnavailableForLegalReasons = 451,
}

export enum HttpMethod {
DELETE = 'DELETE',
GET = 'GET',
HEAD = 'HEAD',
OPTIONS = 'OPTIONS',
PATCH = 'PATCH',
POST = 'POST',
PUT = 'PUT',
}

export enum HttpContentType {
Css = 'text/css',
FormUrlEncoded = 'application/x-www-form-urlencoded',
Html = 'text/html',
Javascript = 'application/javascript',
Json = 'application/json',
MultipartFormData = 'multipart/form-data',
TextPlain = 'text/plain',
Xml = 'application/xml',
}

export enum FileExtension {
CSS = 'css',
CSV = 'csv',
DLL = 'dll',
DOCX = 'docx',
EXE = 'exe',
HTML = 'html',
JPG = 'jpg',
JS = 'js',
JSON = 'json',
MKV = 'mkv',
MP3 = 'mp3',
MP4 = 'mp4',
PDF = 'pdf',
PNG = 'png',
RAR = 'rar',
TS = 'ts',
TXT = 'txt',
XML = 'xml',
ZIP = 'zip',
}

export enum FileEncoding {
ASCII = 'ascii',
Base64 = 'base64',
Binary = 'binary',
Hex = 'hex',
ISO88591 = 'iso-8859-1',
ISO88592 = 'iso-8859-2',
UCS2 = 'ucs2',
UTF16LE = 'utf16le',
UTF32 = 'utf32',
UTF8 = 'utf8',
Windows1252 = 'windows-1252',
}

export enum LanguageCode {
Chinese = 'zh',
English = 'en',
French = 'fr',
German = 'de',
Hindi = 'hi',
Spanish = 'es',
}

export enum Status {
Active = 'Active',
Canceled = 'Canceled',
Completed = 'Completed',
Failed = 'Failed',
Inactive = 'Inactive',
Pending = 'Pending',
Suspended = 'Suspended',
}

export enum ResponseType {
ArrayBuffer = 'arraybuffer',
Blob = 'blob',
Document = 'document',
FormData = 'formdata',
Json = 'json',
Stream = 'stream',
Text = 'text',
}
Loading

0 comments on commit 00cbf88

Please sign in to comment.