Skip to content

Commit

Permalink
Merge pull request #1 from hemilabs/shorten-it
Browse files Browse the repository at this point in the history
Add the first version of the code
  • Loading branch information
gabmontes authored Oct 16, 2024
2 parents 400811c + b1ef7be commit c7a7b60
Show file tree
Hide file tree
Showing 13 changed files with 7,629 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @gabmontes
34 changes: 34 additions & 0 deletions .github/workflows/js-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: JS Checks

on:
pull_request:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
run-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- run: npm ci
- run: npm run format:check
- run: npm run lint
- run: npm run knip
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm test
strategy:
matrix:
node-version: [16, 18, 20, 22]
19 changes: 19 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: NPM Publish

on:
release:
types:
- published

jobs:
publish-to-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- run: npm ci
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.eslintcache
.nyc_output
.vscode
coverage
node_modules
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lint-staged
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# crypto-shortener

Shorten crypto hashes, addresses with ellipsis.

## Installation

```sh
npm install crypto-shortener
```

## Usage

```js
import { shorten } from "crypto-shortener";

console.log(
shorten("6e3e06aa91b715126c964baf7e05b0f3a8b2c299ce1c2d8071f84336356db3a0"),
);
// "6e3e...b3a0"

const shortenAddress = shorten({ length: 5, prefixes: ["bc1"] });
console.log(shortenAddress("bc1qcup4k9q7j0gsjfcv2nqfeu88wjcs9wv0jfuu56"));
// "bc1qcup4...fuu56"
```

## API

### shorten(arg: string, options?: { length?: number, prefixes?: string[] }): string

Shortens the given string `arg` using ellipsis to remove the characters in the middle.
Returns the shortened string.

#### options.length

Keep the first and last `length` characters of the original string.
Defaults to 4.

#### options.prefixes

Don't consider those strings when computing the length of the leading part.
This allows ignoring prefixes like `bc1` or `0x`, commonly used in crypto strings.
Defaults to none.

### shorten(arg: { length?: number, prefixes?: string[] }): (str: string) => string

When given an options object instead of a `string`, it will return a new function that will use those to shorten any given strings.
Loading

0 comments on commit c7a7b60

Please sign in to comment.