From 1f8ae71b812fc9cfc2d58a8f8d90e10db604a72f Mon Sep 17 00:00:00 2001
From: Colten Krauter <18080897+coltenkrauter@users.noreply.github.com>
Date: Sun, 3 Nov 2024 15:20:13 -0700
Subject: [PATCH] feat: package json interface
---
README.md | 87 ++++++++++++++++---
package-lock.json | 4 +-
package.json | 2 +-
src/index.ts | 123 +--------------------------
src/misc.ts | 121 ++++++++++++++++++++++++++
src/package-json.ts | 82 ++++++++++++++++++
test/{basic.test.ts => misc.test.ts} | 0
test/package-json.test.ts | 112 ++++++++++++++++++++++++
8 files changed, 394 insertions(+), 137 deletions(-)
create mode 100644 src/misc.ts
create mode 100644 src/package-json.ts
rename test/{basic.test.ts => misc.test.ts} (100%)
create mode 100644 test/package-json.test.ts
diff --git a/README.md b/README.md
index 96944a3..255c26b 100644
--- a/README.md
+++ b/README.md
@@ -1,28 +1,89 @@
-# Typescript Core
-A TypeScript Repository that stands as a starting point for all other TypeScript repositories.
+
-## Husky
+
+![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.
+
+
+# @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.
-
-
+
+
+
+
+
+
diff --git a/package-lock.json b/package-lock.json
index c74bbfb..01dfb40 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "@krauters/structures",
- "version": "0.0.0",
+ "version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@krauters/structures",
- "version": "0.0.0",
+ "version": "0.1.0",
"license": "ISC",
"devDependencies": {
"@jest/globals": "^29.7.0",
diff --git a/package.json b/package.json
index a593c5c..3f84d10 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "@krauters/structures",
"description": "Common TypeScript types, enums, and interfaces to standardize structures across projects.",
- "version": "0.0.0",
+ "version": "0.1.0",
"main": "dist/index.js",
"type": "commonjs",
"scripts": {
diff --git a/src/index.ts b/src/index.ts
index 9dcc31b..1913e61 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -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'
diff --git a/src/misc.ts b/src/misc.ts
new file mode 100644
index 0000000..9dcc31b
--- /dev/null
+++ b/src/misc.ts
@@ -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 = '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',
+}
diff --git a/src/package-json.ts b/src/package-json.ts
new file mode 100644
index 0000000..0bbf112
--- /dev/null
+++ b/src/package-json.ts
@@ -0,0 +1,82 @@
+export interface PackageJsonType {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ [key: string]: any
+ author?: Person | string
+ bin?: Bin | string
+ browser?: Browser | string
+ bugs?: Bugs | string
+ bundledDependencies?: string[]
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ config?: Record
+ contributors?: Person[] | string[]
+ cpu?: string[]
+ dependencies?: Dependencies
+ description?: string
+ devDependencies?: Dependencies
+ directories?: Directories
+ engines?: Engines
+ files?: string[]
+ homepage?: string
+ keywords?: string[]
+ license?: string
+ main?: string
+ man?: string | string[]
+ module?: string
+ name: string
+ optionalDependencies?: Dependencies
+ os?: string[]
+ peerDependencies?: Dependencies
+ private?: boolean
+ publishConfig?: PublishConfig
+ repository?: Repository | string
+ scripts?: Scripts
+ type?: 'commonjs' | 'module'
+ types?: string
+ version: string
+}
+
+export interface Bugs {
+ email?: string
+ url?: string
+}
+
+export interface Person {
+ email?: string
+ name?: string
+ url?: string
+}
+
+export interface Repository {
+ type: string
+ url: string
+}
+
+export type Scripts = Record
+
+export type Dependencies = Record
+
+export type Browser = Record
+
+export type Bin = Record
+
+export interface Directories {
+ bin?: string
+ doc?: string
+ example?: string
+ lib?: string
+ man?: string
+}
+
+export interface Engines {
+ [engine: string]: string | undefined
+ node?: string
+ npm?: string
+ yarn?: string
+}
+
+export interface PublishConfig {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ [key: string]: any
+ access?: 'public' | 'restricted'
+ registry?: string
+}
diff --git a/test/basic.test.ts b/test/misc.test.ts
similarity index 100%
rename from test/basic.test.ts
rename to test/misc.test.ts
diff --git a/test/package-json.test.ts b/test/package-json.test.ts
new file mode 100644
index 0000000..a58d189
--- /dev/null
+++ b/test/package-json.test.ts
@@ -0,0 +1,112 @@
+import { describe, it, expect } from '@jest/globals'
+import { PackageJsonType, Person, Repository, Bugs, PublishConfig, Dependencies } from '../src/package-json'
+
+describe('PackageJsonType Structure', () => {
+ it('should define correct structure for author field', () => {
+ const author: Person = {
+ name: 'John Doe',
+ email: 'johndoe@example.com',
+ url: 'https://example.com',
+ }
+ expect(author).toEqual({
+ name: 'John Doe',
+ email: 'johndoe@example.com',
+ url: 'https://example.com',
+ })
+ })
+
+ it('should define correct structure for repository field', () => {
+ const repository: Repository = {
+ type: 'git',
+ url: 'https://github.com/example/repo.git',
+ }
+ expect(repository).toEqual({
+ type: 'git',
+ url: 'https://github.com/example/repo.git',
+ })
+ })
+
+ it('should define correct structure for bugs field', () => {
+ const bugs: Bugs = {
+ url: 'https://github.com/example/repo/issues',
+ email: 'support@example.com',
+ }
+ expect(bugs).toEqual({
+ url: 'https://github.com/example/repo/issues',
+ email: 'support@example.com',
+ })
+ })
+
+ it('should define correct structure for publishConfig field', () => {
+ const publishConfig: PublishConfig = {
+ access: 'public',
+ registry: 'https://registry.npmjs.org/',
+ }
+ expect(publishConfig).toEqual({
+ access: 'public',
+ registry: 'https://registry.npmjs.org/',
+ })
+ })
+
+ it('should define correct structure for dependencies', () => {
+ const dependencies: Dependencies = {
+ typescript: '^4.0.0',
+ jest: '^26.6.0',
+ }
+ expect(dependencies).toEqual({
+ typescript: '^4.0.0',
+ jest: '^26.6.0',
+ })
+ })
+
+ it('should define correct structure for PackageJsonType', () => {
+ const packageJson: PackageJsonType = {
+ name: '@example/package',
+ version: '1.0.0',
+ description: 'An example package',
+ author: {
+ name: 'John Doe',
+ email: 'johndoe@example.com',
+ },
+ repository: {
+ type: 'git',
+ url: 'https://github.com/example/repo.git',
+ },
+ license: 'MIT',
+ scripts: {
+ build: 'tsc',
+ test: 'jest',
+ },
+ dependencies: {
+ typescript: '^4.0.0',
+ },
+ devDependencies: {
+ jest: '^26.6.0',
+ },
+ }
+ expect(packageJson).toEqual({
+ name: '@example/package',
+ version: '1.0.0',
+ description: 'An example package',
+ author: {
+ name: 'John Doe',
+ email: 'johndoe@example.com',
+ },
+ repository: {
+ type: 'git',
+ url: 'https://github.com/example/repo.git',
+ },
+ license: 'MIT',
+ scripts: {
+ build: 'tsc',
+ test: 'jest',
+ },
+ dependencies: {
+ typescript: '^4.0.0',
+ },
+ devDependencies: {
+ jest: '^26.6.0',
+ },
+ })
+ })
+})