-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from jer-echo/main
Patch version update entry
- Loading branch information
Showing
8 changed files
with
290 additions
and
189 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 |
---|---|---|
@@ -1,104 +1,2 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# TypeScript v1 declaration files | ||
typings/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.test | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
|
||
# Next.js build output | ||
.next | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and *not* Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
/node_modules/ | ||
*-lock.* |
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,18 @@ | ||
# CHANGELOG | ||
|
||
## 1.0.2 | ||
|
||
- Added `CHANGELOG.md` | ||
- Added type hint support | ||
- Reduce the probability of duplicate keys | ||
- Improve performace and readability | ||
- Improve Documentation | ||
|
||
## 1.0.1 | ||
|
||
- Improve performace and readability | ||
- Added Documentation | ||
|
||
## 1.0.0 | ||
|
||
- Initial Release |
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
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 |
---|---|---|
@@ -1,30 +1,70 @@ | ||
/** | ||
* @class Numesis | ||
* Create custom Number System | ||
* Compatible with: | ||
* - Deno | ||
* - NodeJS | ||
* - Browser | ||
* - Typescript | ||
* @author Jericho Aquino | ||
* @version 1.0.2 | ||
* @license Apache-2.0 | ||
* @see {@link https://github.com/eru123/numesis} Github Repository | ||
* @see {@link https://www.npmjs.com/package/numesis} NPM Package | ||
*/ | ||
class Numesis { | ||
c; | ||
constructor(ch = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"){ | ||
this.c = { | ||
s: ch, | ||
l: ch.length, | ||
i: ch.length - 1, | ||
a: ch.split("") | ||
}; | ||
/** | ||
* A non-duplicate character set, that will be use in creating new number system | ||
* @type {Set<string>} | ||
*/ | ||
charset; | ||
/** | ||
* @param {String} chartset A non-duplicate character set, that will be use in creating new number system | ||
*/ | ||
constructor(chartset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"){ | ||
this.charset = Array.from(new Set(chartset.split(""))); | ||
} | ||
ep(n, c = "") { | ||
n = Math.floor(n); | ||
const { l , i , a } = this.c; | ||
if (n <= i) return a[n] + c; | ||
const m = n % l; | ||
c = m > 0 && m <= l ? a[m] + c : a[0] + c; | ||
const d = Math.floor(n / l); | ||
return this.ep(d, c); | ||
/** | ||
* A recursive method that encodes the n variable to custom number system | ||
* @param {number|string} number The number that will be decoded | ||
* @param {string} current The current string in the recursion | ||
* | ||
* @return {String} encoded string | ||
*/ | ||
encode_process(number, current = "") { | ||
number = parseInt("" + number); | ||
const length = this.charset.length; | ||
const lastIndex = length - 1; | ||
const set = this.charset; | ||
if (number <= lastIndex) return "" + (set[number] + current); | ||
const m = number % length; | ||
current = m > 0 && m <= length ? set[m] + current : set[0] + current; | ||
const d = parseInt(number / length + ""); | ||
return this.encode_process(d, current); | ||
} | ||
e(n) { | ||
const str = String(n); | ||
if (str.includes(".")) { | ||
const st = str.split("."); | ||
return `${this.ep(Number(st[0]) || 0)}.${this.ep(Number(st[1]) || 0)}`; | ||
} | ||
return this.ep(n); | ||
/** | ||
* Alias for encode_process | ||
*/ | ||
ep = this.encode_process; | ||
/** | ||
* A public method that encodes n paramenter to custom number system | ||
* @param {number|string} args numbers that will be decoded | ||
* | ||
* @return {String} encoded string | ||
*/ | ||
encode(...args) { | ||
return args.map((n)=>{ | ||
const str = String(n); | ||
if (/\./i.test(str)) { | ||
const st = str.split("."); | ||
return `${this.encode_process(+st[0] || 0)}.${this.encode_process(+st[1] || 0)}`; | ||
} | ||
return this.encode_process(n); | ||
}).join(""); | ||
} | ||
/** | ||
* Alias for encode | ||
*/ | ||
e = this.encode.bind(this); | ||
} | ||
|
||
module.exports = Numesis; | ||
module.exports = Numesis; |
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 |
---|---|---|
@@ -1,30 +1,81 @@ | ||
class Numesis { | ||
public readonly c: {s:string,l:number,i:number,a: Array<string>}; | ||
constructor(ch:string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"){ | ||
this.c = { | ||
s: ch, | ||
l: ch.length, | ||
i: ch.length - 1, | ||
a: ch.split("") | ||
} | ||
} | ||
private ep(n:number, c = ""): string { | ||
n = Math.floor(n) | ||
const {l,i,a} = this.c | ||
if(n <= i) return a[n] + c; | ||
const m: number = n % l; | ||
c = m > 0 && m <= l ? a[m] + c : a[0] + c | ||
const d: number = Math.floor(n / l); | ||
return this.ep(d,c) | ||
} | ||
e(n:number): string { | ||
const str = String(n) | ||
if(str.includes(".")) { | ||
const st = str.split(".") | ||
return `${this.ep(Number(st[0]) || 0)}.${this.ep(Number(st[1]) || 0)}` | ||
} | ||
return this.ep(n) | ||
} | ||
/** | ||
* @class Numesis | ||
* Create custom Number System | ||
* Compatible with: | ||
* - Deno | ||
* - NodeJS | ||
* - Browser | ||
* - Typescript | ||
* @author Jericho Aquino | ||
* @version 1.0.2 | ||
* @license Apache-2.0 | ||
* @see {@link https://github.com/eru123/numesis} Github Repository | ||
* @see {@link https://www.npmjs.com/package/numesis} NPM Package | ||
*/ | ||
class Numesis { | ||
/** | ||
* A non-duplicate character set, that will be use in creating new number system | ||
* @type {Set<string>} | ||
*/ | ||
public readonly charset: Array<string>; | ||
|
||
/** | ||
* @param {String} chartset A non-duplicate character set, that will be use in creating new number system | ||
*/ | ||
constructor(chartset: string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") { | ||
// Recreate an array of characters without duplicates | ||
this.charset = Array.from(new Set(chartset.split(""))) | ||
} | ||
|
||
/** | ||
* A recursive method that encodes the n variable to custom number system | ||
* @param {number|string} number The number that will be decoded | ||
* @param {string} current The current string in the recursion | ||
* | ||
* @return {String} encoded string | ||
*/ | ||
private encode_process(number: number | string, current = ""): string { | ||
number = parseInt("" + number) // Convert to integer | ||
const length: number = this.charset.length // Get the length of the charset | ||
const lastIndex: number = length - 1 // Get the last index of the charset | ||
const set: Array<string> = this.charset // Get the charset | ||
if (number <= lastIndex) return "" + (set[number] + current); // If the number is less than the length of the charset, return the character | ||
const m: number = number % length; // Get the remainder of the number | ||
current = m > 0 && m <= length ? set[m] + current : set[0] + current // If the remainder is greater than 0 and less than the length of the charset, return the character | ||
const d: number = parseInt((number / length) + ""); // Get the division of the number | ||
return this.encode_process(d, current) // Recursive call | ||
} | ||
|
||
/** | ||
* Alias for encode_process | ||
*/ | ||
ep: Function = this.encode_process | ||
|
||
/** | ||
* A public method that encodes n paramenter to custom number system | ||
* @param {number|string} args numbers that will be decoded | ||
* | ||
* @return {String} encoded string | ||
*/ | ||
encode(...args: Array<number | string>): string { | ||
return args | ||
.map((n) => { | ||
const str = String(n) // Convert to string | ||
if (/\./i.test(str)) { // If float | ||
const st = str.split(".") // Split the string | ||
// return the encoded float | ||
return `${this.encode_process(+st[0] || 0)}.${this.encode_process(+st[1] || 0)}` | ||
} | ||
|
||
return this.encode_process(n) | ||
}) | ||
.join("") | ||
} | ||
|
||
/** | ||
* Alias for encode | ||
*/ | ||
e: Function = this.encode.bind(this) | ||
} | ||
|
||
export default Numesis; | ||
export default Numesis |
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
Oops, something went wrong.