-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e1bfdd8
Showing
15 changed files
with
4,263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# AlphaID.js | ||
|
||
AlphaID.js is a library that let you convert any integer to a short alphanumeric version. It can be useful for generating short, unique, and obfuscated identifiers. | ||
|
||
# Installation | ||
|
||
You can install AlphaID.js using npm: | ||
|
||
```bash | ||
npm i alpha-id-js | ||
``` | ||
|
||
Via CDN: | ||
|
||
```html | ||
<script src="https://unpkg.com/alpha-id-js"></script> | ||
``` | ||
|
||
# Getting Started | ||
|
||
Simple usage looks like: | ||
|
||
```javascript | ||
const AlphaID = require('alpha-id-js'); | ||
// or from browser -> <script src="https://unpkg.com/alpha-id-js"></script> | ||
|
||
const encodedString = AlphaID.convert(258456357951); | ||
console.log(encodedString); | ||
// Output: '4y7exoH' | ||
|
||
const originalNumber = AlphaID.recover('4y7exoH'); | ||
console.log(originalNumber); | ||
// Output: 258456357951 | ||
``` | ||
|
||
Configuring a Global Key | ||
|
||
You can set a global key that will be used for encoding and decoding if no specific key is provided. This can be done using the `config` method: | ||
|
||
```javascript | ||
const AlphaID = require('alpha-id-js'); | ||
|
||
AlphaID.config('my_key'); | ||
|
||
const encodedString = AlphaID.convert(258456357951); | ||
console.log(encodedString); | ||
// Output: '4ymMZq9' | ||
|
||
const originalNumber = AlphaID.recover('4ymMZq9'); | ||
console.log(originalNumber); | ||
// Output: 258456357951 | ||
``` | ||
|
||
## License | ||
|
||
AlphaID is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* AlphaID class | ||
*/ | ||
declare class AlphaID { | ||
private static baseChars; | ||
private static globalKey; | ||
/** | ||
* Set the global key | ||
* | ||
* @param {string} key | ||
*/ | ||
static config(key: string): void; | ||
/** | ||
* Encode a number | ||
* | ||
* @param {number, bigint} number | ||
* @param {string} key | ||
* @returns {string} | ||
*/ | ||
static convertNumber(number: number | bigint, key?: string): string; | ||
/** | ||
* Decode a string | ||
* | ||
* @param {string} convertedString | ||
* @param {string} key | ||
* @returns {number, bigint} | ||
*/ | ||
static recoverNumber(convertedString: string, key?: string): number | bigint; | ||
/** | ||
* Short name function redirects to convertNumber | ||
*/ | ||
static convert(numberToBeConverted: number, key?: string): string; | ||
/** | ||
* Short name function redirects to recoverNumber | ||
*/ | ||
static recover(stringToBeRecovered: string, key?: string): number | bigint; | ||
static crc32(data: string): number; | ||
} | ||
export default AlphaID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare const AlphaID: any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
Oops, something went wrong.