Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Use an array of multi-character alphanumeric symbols to convert bases exceeding 62
Use an array of multi-character alphanumeric symbols to convert between bases exceeding 62.
var basek = require('basek');
<script src='basek.min.js'></script> // var basek = Basek()
===
The default alphabet is 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
which supports all base conversions up to 62.
basek.base10to2(15) // "1111"
basek.base10to16(15) // "f"
basek.base16to10("f") // "15"
basek.base2to10(1111) // "15"
basek.makeTag(2,16)
// Basek.prototype.base2to16 and Basek.prototype.base16to2 are now defined
basek.base2to16(1111) // "f"
basek.base16to2("f") // "1111"
Convert to/from decimal using these generics. If you don't provide a base parameter, Basek uses the length of your alphabet to determine the base.
basek.toBase(61).get() // "Z"
basek.toBase(61,2).get() // "111110"
basek.fromBase("Z").get() // "61"
basek.fromBase("ff",16).get() // "255"
You can literally use any combination of multi-character symbols to extend Basek's alphabetic representation and thus extending your base limit. First here's some basic usage.
// Using only single character symbols
basek.alpha()
// '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - default base62
basek.alphaExtend('%^')
// '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ%^' - base64
basek.alphaSet()
// '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - back to default
basek.alphaSet('abcdefghijklmnopqrstuvwzyz')
// 'abcdefghijklmnopqrstuvwzyz' - alphabet set
basek.toBase(15,2).get() // 'bbbb'
Now using multi-character alphanumeric symbols to extend Basek's base range to 100
basek.alphaSet() // '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' - back to default
for (var i = 0; i < 38; i++) {
basek.alphaExtend(['a'+i]);
} // alphabet set to Array[100] (['0','1',...,'a37'])
basek.toBase(99).get() // 'a37' - your multi-character symbol representing decimal 99 in base100
Use pad to prepend n bits (bit = character at the 0th index of your alphabet) to your string and unpad to slice the representation back to its original glory.
basek.alphaSet()
basek.toBase(15,2) // '1111'
basek.pad(10) // '0000001111'
basek.unpad() // '1111'
Chain several functions together
basek.alphaSet('ab').toBase(10).pad(10).get() // 'aaaaaababa'
MIT
FAQs
Use an array of multi-character alphanumeric symbols to convert bases exceeding 62
The npm package basek receives a total of 2 weekly downloads. As such, basek popularity was classified as not popular.
We found that basek demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.