https://github.com/marcelvoss/base62
A tiny package for Base62 encoding/decoding values.
https://github.com/marcelvoss/base62
base62 swift
Last synced: over 1 year ago
JSON representation
A tiny package for Base62 encoding/decoding values.
- Host: GitHub
- URL: https://github.com/marcelvoss/base62
- Owner: marcelvoss
- License: mit
- Created: 2021-05-01T13:35:18.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-05-02T16:41:30.000Z (about 5 years ago)
- Last Synced: 2024-10-29T07:05:06.766Z (over 1 year ago)
- Topics: base62, swift
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Base62
[](https://github.com/marcelvoss/Base62/actions/workflows/ci.yml)
Base62 is a tiny package for [Base62](https://en.wikipedia.org/wiki/Base62) encoding/decoding values. It is tested, documented, easy-to-use and supports Apple Platforms, as well as Linux.
I use this as encoding mechanism for my own URL shortener but this is a general purpose implementation that should suffice all use cases that require Base62 encoding/decoding.
## Installation
Base62 is distributed using the Swift Package Manager. To install it into a project, add it as a dependency within your `Package.swift` manifest:
```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/marcelvoss/Base62.git", from: "0.1.0")
],
...
)
```
Then import Base62 wherever you’d like to use it:
```swift
import Base62
```
## Usage
Using Base62 is incredibly easy, as it focusses on a single responsibility and does that nicely.
Base62 ships with a single object that provides encoding and decoding functionality.
```swift
let base62Encoded = Base62.encode(2021)
// 2021 == "wz"
let base62Decoded = try Base62.decode("GitHub")
// "GitHub" == 38750631667
```
There are also extensions for `String` and `Int` available, if you prefer to use them rather than the `Base62` object directly.