Skip to content

Commit

Permalink
Merge pull request #1 from nascarsayan/main
Browse files Browse the repository at this point in the history
Add lua implementation for sqids
  • Loading branch information
4kimov authored Nov 27, 2023
2 parents f3fbd73 + 0b270f0 commit be93915
Show file tree
Hide file tree
Showing 11 changed files with 1,471 additions and 5 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/busted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Busted

on: [ push, pull_request ]

jobs:

busted:
strategy:
fail-fast: false
matrix:
luaVersion: [ "5.4" ]
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup 'lua'
uses: leafo/gh-actions-lua@v9
with:
luaVersion: ${{ matrix.luaVersion }}

- name: Setup 'luarocks'
uses: leafo/gh-actions-luarocks@v4

- name: Setup dependencies
run: |
luarocks install --deps-only sqids-lua-*.rockspec
luarocks install busted
luarocks install luacov
luarocks install luacov-coveralls
- name: Build 'sqids'
run: |
luarocks make
- name: Run 'busted'
# disable project-local path prefixes to force use of system installation
run: busted --coverage --output=gtest -Xoutput --color

- name: Report test coverage
if: ${{ success() }}
continue-on-error: true
run: luacov-coveralls -i sqids.lua
env:
COVERALLS_REPO_TOKEN: ${{ github.token }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/luarocks
/lua
/lua_modules
/.luarocks
/luacov.stats.out
/luacov.report.out
*.rock
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
all: build

build:
luarocks make

publish:
luarocks pack sqids-lua
luarocks upload --api-key=${LUAROCKS_API_KEY} sqids-lua-*.rockspec

clean:
rm -rf sqids-lua-*.rock
56 changes: 51 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,60 @@

Sqids (pronounced "squids") is a small library that lets you generate YouTube-looking IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

## Getting started
Features:

@todo
- **Encode multiple numbers** - generate short IDs from one or several non-negative numbers
- **Quick decoding** - easily decode IDs back into numbers
- **Unique IDs** - generate unique IDs by shuffling the alphabet once
- **ID padding** - provide minimum length to make IDs more uniform
- **URL safe** - auto-generated IDs do not contain common profanity
- **Randomized output** - Sequential input provides nonconsecutive IDs
- **Many implementations** - Support for [40+ programming languages](https://sqids.org/)

## Examples
## 🧰 Use-cases

@todo
Good for:

## License
- Generating IDs for public URLs (eg: link shortening)
- Generating IDs for internal systems (eg: event tracking)
- Decoding for quicker database lookups (eg: by primary keys)

Not good for:

- Sensitive data (this is not an encryption library)
- User IDs (can be decoded revealing user count)

## 🚀 Getting started

Sqids is available on [LuaRocks](https://luarocks.org/modules/nascarsayan/sqids-lua):

```bash
luarocks install sqids-lua
```

## 👩‍💻 Examples


```lua
local Sqids = require("sqids")
local sqids = Sqids.new()

local encoded = sqids:encode({ 1, 2, 3 }) -- 86Rf07
local decoded = sqids:decode(encoded) -- 1, 2, 3
```

Enforce a *minimum* length for IDs:

```lua
local Sqids = require("sqids")
local sqids = Sqids.new({
minLength = 10,
})

local id = sqids:encode({ 1, 2, 3 }) -- 86Rf07xd4z
local numbers = sqids:decode(id) -- [1, 2, 3]
```

## 📝 License

[MIT](LICENSE)
Loading

0 comments on commit be93915

Please sign in to comment.