Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
groups:
eslint:
patterns:
- "*eslint*"

- package-ecosystem: "github-actions"
directory: ".github/workflows"
schedule:
interval: "daily"
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build the package

on:
push:
branches:
- "main"
pull_request:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- run: npm ci
- run: npm run build
44 changes: 44 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint

on:
push:
branches: [main]
pull_request:

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- name: Lint GitHub Action workflows
uses: raven-actions/actionlint@v2
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- run: npm ci
- run: npm run lint:eslint
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- run: npm ci
- run: npm run lint:prettier
tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
- run: npm ci
- run: npm run lint:tsc
44 changes: 44 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release to npm

on:
push:
branches: [main]
paths:
- "package.json"

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
registry-url: "https://registry.npmjs.org/"

- name: Install dependencies
run: npm ci

- name: Compare package version
id: version_check
run: |
VERSION=$(jq -r '.version' package.json)
PREV_VERSION=$(git show HEAD~1:package.json | jq -r '.version')
echo "current=$VERSION" >> "$GITHUB_OUTPUT"
echo "previous=$PREV_VERSION" >> "$GITHUB_OUTPUT"
if [ "$VERSION" = "$PREV_VERSION" ]; then
echo "No version change. Skipping publish."
exit 0
fi

- name: Build
run: npm run build

- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog for @pdc/http-status-codes

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

## 1.0.0 - 2025-07-07

### Added

- Published the `HTTP_STATUS` constant which contains all current http status codes.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# http-status-codes
An organized collection of meaningfully named HTTP status code constants.
# HTTP Status Codes

This simple package provides an organized collection of meaningfully named HTTP status code constants.

## Installation

```sh
npm install http-status-codes
```

## Usage

Import the enums and use them in your code for clarity and type safety:

```js
import { HTTP_STATUS } from "http-status-codes-enum";

if (response.status === HTTP_STATUS.SUCCESSFUL.OK) {
// handle success
}

if (response.status === HTTP_STATUS.CLIENT_ERROR.NOT_FOUND) {
// handle 404
}
```

## Status Code Groups

- `INFORMATIONAL`: 1xx codes (e.g., CONTINUE, PROCESSING)
- `SUCCESSFUL`: 2xx codes (e.g., OK, CREATED)
- `REDIRECTION`: 3xx codes (e.g., MOVED_PERMANENTLY, FOUND)
- `CLIENT_ERROR`: 4xx codes (e.g., BAD_REQUEST, NOT_FOUND)
- `SERVER_ERROR`: 5xx codes (e.g., INTERNAL_SERVER_ERROR, SERVICE_UNAVAILABLE)

## API

All status codes are available as enums under the `HTTP_STATUS` object. Example:

```js
HTTP_STATUS.SUCCESSFUL.CREATED; // 201
HTTP_STATUS.CLIENT_ERROR.FORBIDDEN; // 403
```
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from "eslint/config";
import js from "@eslint/js";
import love from "eslint-config-love";
import tseslint from "typescript-eslint";
import prettier from "eslint-config-prettier";

export default defineConfig([
js.configs.recommended,
tseslint.configs.eslintRecommended,
tseslint.configs.recommendedTypeChecked,
tseslint.configs.strict,
love,
prettier,
]);
Loading