Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devknown committed Jun 17, 2023
0 parents commit e1bfdd8
Show file tree
Hide file tree
Showing 15 changed files with 4,263 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
56 changes: 56 additions & 0 deletions README.md
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).
2 changes: 2 additions & 0 deletions dist/AlphaID.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/AlphaID.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions dist/AlphaID.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/AlphaID.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions dist/src/AlphaID.d.ts
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;
1 change: 1 addition & 0 deletions dist/test/AlphaID.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const AlphaID: any;
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
Loading

0 comments on commit e1bfdd8

Please sign in to comment.