Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Feb 19, 2023
0 parents commit d5dcaf6
Show file tree
Hide file tree
Showing 20 changed files with 12,780 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.js
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-floating-promises": "warn"
}
}
42 changes: 42 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI/CD

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

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"
- run: npm ci
- run: npm run lint
- run: npm run test

cd:
if: ${{ github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
needs: [ci]
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"
- run: npm ci
- run: npm run build
- name: Release
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run semantic-release
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# macOS
.DS_Store
.AppleDouble
.LSOverride

node_modules
yarn.lock
dist
.env*
*.pem
.npmrc

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Exclude .example files
!*.example

# ESLint
.eslintcache

# TypeScript stuff
*.tsbuildinfo
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx commitlint --edit "${1}"
4 changes: 4 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

exec < /dev/tty && npx cz --hook || true
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"trailingComma": "es5",
"printWidth": 100,
"useTabs": true,
"arrowParens": "always",
"tabWidth": 2,
"semi": true,
"singleQuote": false,
"quoteProps": "consistent"
}
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint"]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"eslint.validate": ["typescript"],
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll.eslint": true
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Edoardo Ranghieri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# [ulid-uuid-converter](https://github.com/TheEdoRan/ulid-uuid-converter)

> A tiny zero dependency library for ULID to UUID conversion and vice versa.
## Installation

```sh
npm i ulid-uuid-converter
```

## Usage

```typescript
const ulid = UUIDtoULID("0186675b-9439-536e-1c4c-561c280fa87b");
// outputs: 01GSKNQ51SADQ1RK2P3GM0ZA3V

const uuid = ULIDtoUUID("01GSKNQ51SADQ1RK2P3GM0ZA3V");
// outputs: 0186675b-9439-536e-1c4c-561c280fa87b
```

### Options

You can pass an optional second argument with `nullOnInvalidInput` to both functions. With this option the function behavior changes: instead of throwing, it will return `null` if a bad input is passed as argument.

| Option | Type | Default | Description |
| ------------------ | --------- | ------- | ---------------------------------------------- |
| nullOnInvalidInput | `boolean` | `false` | Return `null` instead of throwing on bad input |

### Example

```typescript
// these will throw!
const ulid = UUIDtoULID("bad string");
const uuid = ULIDtoUUID("another bad string");

// these will return null instead of throwing
const ulid = UUIDtoULID("bad string", { nullOnInvalidInput: true });
const uuid = ULIDtoUUID("another bad string", { nullOnInvalidInput: true });
```

## Credits

Big thanks to [devbanana](https://github.com/devbanana) for the [Crockford's Base32](https://github.com/devbanana/crockford-base32) encoding and decoding functions.

## License

This project is licensed under the [MIT License](https://github.com/TheEdoRan/ulid-uuid-converter/blob/main/LICENSE).
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = { extends: ["@commitlint/config-conventional"] };
12 changes: 12 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from "@jest/types";

const config: Config.InitialOptions = {
verbose: true,
rootDir: "./src",
testMatch: ["**/__tests__/**/*.test.ts"],
transform: {
"^.+\\.ts$": "ts-jest",
},
};

export default config;
Loading

0 comments on commit d5dcaf6

Please sign in to comment.