Skip to content

Commit e1bfdd8

Browse files
committed
first commit
0 parents  commit e1bfdd8

File tree

15 files changed

+4263
-0
lines changed

15 files changed

+4263
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# AlphaID.js
2+
3+
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.
4+
5+
# Installation
6+
7+
You can install AlphaID.js using npm:
8+
9+
```bash
10+
npm i alpha-id-js
11+
```
12+
13+
Via CDN:
14+
15+
```html
16+
<script src="https://unpkg.com/alpha-id-js"></script>
17+
```
18+
19+
# Getting Started
20+
21+
Simple usage looks like:
22+
23+
```javascript
24+
const AlphaID = require('alpha-id-js');
25+
// or from browser -> <script src="https://unpkg.com/alpha-id-js"></script>
26+
27+
const encodedString = AlphaID.convert(258456357951);
28+
console.log(encodedString);
29+
// Output: '4y7exoH'
30+
31+
const originalNumber = AlphaID.recover('4y7exoH');
32+
console.log(originalNumber);
33+
// Output: 258456357951
34+
```
35+
36+
Configuring a Global Key
37+
38+
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:
39+
40+
```javascript
41+
const AlphaID = require('alpha-id-js');
42+
43+
AlphaID.config('my_key');
44+
45+
const encodedString = AlphaID.convert(258456357951);
46+
console.log(encodedString);
47+
// Output: '4ymMZq9'
48+
49+
const originalNumber = AlphaID.recover('4ymMZq9');
50+
console.log(originalNumber);
51+
// Output: 258456357951
52+
```
53+
54+
## License
55+
56+
AlphaID is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

dist/AlphaID.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/AlphaID.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/AlphaID.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/AlphaID.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/AlphaID.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* AlphaID class
3+
*/
4+
declare class AlphaID {
5+
private static baseChars;
6+
private static globalKey;
7+
/**
8+
* Set the global key
9+
*
10+
* @param {string} key
11+
*/
12+
static config(key: string): void;
13+
/**
14+
* Encode a number
15+
*
16+
* @param {number, bigint} number
17+
* @param {string} key
18+
* @returns {string}
19+
*/
20+
static convertNumber(number: number | bigint, key?: string): string;
21+
/**
22+
* Decode a string
23+
*
24+
* @param {string} convertedString
25+
* @param {string} key
26+
* @returns {number, bigint}
27+
*/
28+
static recoverNumber(convertedString: string, key?: string): number | bigint;
29+
/**
30+
* Short name function redirects to convertNumber
31+
*/
32+
static convert(numberToBeConverted: number, key?: string): string;
33+
/**
34+
* Short name function redirects to recoverNumber
35+
*/
36+
static recover(stringToBeRecovered: string, key?: string): number | bigint;
37+
static crc32(data: string): number;
38+
}
39+
export default AlphaID;

dist/test/AlphaID.test.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare const AlphaID: any;

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};

0 commit comments

Comments
 (0)