0.16.1 • Published 1 year ago
@lytrax/lxlib v0.16.1
LytraX JS/TS library
A collection of useful functions/classes for string/time manipulation, math/random calculations and encryption.
Functions
bitCount32 from math
import { bitCount32 } from '@lytrax/lxlib/math';
const bitLength = bitCount32(0x55555555); // 16 flagged bitsrandomColor from random
import { randomColor } from '@lytrax/lxlib/random';
const cssRandomColor = randomColor();randomHueColor from random
import { randomHueColor } from '@lytrax/lxlib/random';
const cssRandomHueColor = randomHueColor(33, 76);randomInt from random
import { randomInt } from '@lytrax/lxlib/random';
const randInt = randomInt(1, 100);randomIntNotIn from random
import { randomIntNotIn } from '@lytrax/lxlib/random';
// randInt <=> 1..10 and <> 2, 4, 6
const randInt = randomIntNotIn(1, 10, [2, 4, 6]);randomIndex from random
import { randomIndex } from '@lytrax/lxlib/random';
let index = randomIndex(10); // index range 0..9
index = randomIndex(10, { inclusive: true }); // index range 0..10
index = randomIndex(10, { startFrom: 2 }); // index range 2..9randomId from random
import { randomId } from '@lytrax/lxlib/random';
const id = randomId(); // id range 1..0x7FFFFFFFrandomId64 from random
import { randomId64 } from '@lytrax/lxlib/random';
const id = randomId64(); // id range 1..0X7FFFFFFFFFFFFFFFdice from random
import { dice } from '@lytrax/lxlib/random';
const diceValue = dice(6);sleep from time
import { sleep } from '@lytrax/lxlib/time';
await sleep(500);uts from time
import { uts } from '@lytrax/lxlib/time';
const unixTimeStamp = uts(); // UTS in secondsutsj from time
import { utsj } from '@lytrax/lxlib/time';
const unixTimeStampMillis = utsj(); // UTS in millisecondstimeHash from time
import { timeHash } from '@lytrax/lxlib/time';
const hash = timeHash(); // kkluv4t0dayKey from time
import { dayKey } from '@lytrax/lxlib/time';
const key = dayKey({ year: 2021, ordinal: 111 }); // 2021111
const resolved = dayKey.resolve(key); // { year: 2021, ordinal: 111 }monthKey from time
import { monthKey } from '@lytrax/lxlib/time';
const key = monthKey({ year: 2021, month: 7 }); // 202107
const resolved = monthKey.resolve(key); // { year: 2021, month: 7 }dateKey from time
import { dateKey } from '@lytrax/lxlib/time';
const key = dateKey({ year: 2021, month: 7, day: 1 }); // 20210701
const resolved = dateKey.resolve(key); // { year: 2021, month: 7, day: 1 }minuteKey from time
import { minuteKey } from '@lytrax/lxlib/time';
const key = minuteKey({ hour: 23, minute: 30 }); // 2330
const resolved = minuteKey.resolve(key); // { hour: 23, minute: 30, second: 0 }timeKey from time
import { timeKey } from '@lytrax/lxlib/time';
const key = timeKey({ hour: 23, minute: 30, second: 59 }); // 233059
const resolved = minuteKey.timeKey(key); // { hour: 23, minute: 30, second: 59 }timeToMinutes from time
import { timeToMinutes } from '@lytrax/lxlib/time';
const minutes = timeToMinutes({ hour: 23, minute: 30 }); // 1410minutesTotime from time
import { minutesTotime } from '@lytrax/lxlib/time';
const time = minutesTotime(1410); // { hour: 23, minute: 30 }toFormData from utils
import { toFormData } from '@lytrax/lxlib/utils';
const formData = toFormData({
some: 'Some',
values: 123
});fetchTimeout from utils
import { fetchTimeout } from '@lytrax/lxlib/utils';
// Will timeout after 5s if fetch won't get a reply
fetchTimeout('https://myurl.data',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
},
5000 // Timeout in milliseconds
);normalizeGreek from string
import { normalizeGreek } from '@lytrax/lxlib/string';
normalizeGreek('Ελληνικό κείμενο που θα φύγουν οι τόνοι');camelize from string
import { camelize } from '@lytrax/lxlib/string';
camelize('Some text to camelize'); // "SomeTextToCamelize"toTitleCase from string
import { toTitleCase } from '@lytrax/lxlib/string';
toTitleCase('Some text to title case') // "Some Text To Title Case"toSentence from string
import { toSentence } from '@lytrax/lxlib/string';
toSentence('Some Text TO SENTENCE') // "Some text to sentence"makeLines from string
import { makeLines } from '@lytrax/lxlib/string';
makeLines({ lines: ['make', 'some', 'lines'] }) // "make↵some↵lines"nl2br from string
import { nl2br } from '@lytrax/lxlib/string';
nl2br('Some\ntext\nwith\nlines') // "Some<br/>text<br/>with<br/>lines"removeAllWhitespaces from string
import { removeAllWhitespaces } from '@lytrax/lxlib/string';
removeAllWhitespaces('Text With \tWitespaces\t\t') // "TextWithWitespaces"decodeHtmlCharCodes from string
import { decodeHtmlCharCodes } from '@lytrax/lxlib/string';
decodeHtmlCharCodes('This is some text') // "This is↵some text"toJsonIntended from string
import { toJsonIntended } from '@lytrax/lxlib/string';
toJsonIntended({some: 'Some', one: 1})
// {
// "some": "Some",
// "one": 1
// }format from string
import { format } from '@lytrax/lxlib/string';
format('My name is {name} and my IQ is {IQ}', { name: 'Christos', IQ: 111 })
// "My name is Christos and my IQ is 111"translateBool from string
import { translateBool } from '@lytrax/lxlib/string';
translateBool('Yes') // truequoteSingle from string
import { quoteSingle } from '@lytrax/lxlib/string';
quoteSingle('test') // "'test'"quoteDouble from string
import { quoteDouble } from '@lytrax/lxlib/string';
quoteDouble('test') // ""test""quoteBacktick from string
import { quoteBacktick } from '@lytrax/lxlib/string';
quoteBacktick('test') // "`test`"quoteLRSingle from string
import { quoteLRSingle } from '@lytrax/lxlib/string';
quoteLRSingle('test') // "‘test’"quoteLRDouble from string
import { quoteLRDouble } from '@lytrax/lxlib/string';
quoteLRDouble('test') // "“test”"quote from string
import { quote } from '@lytrax/lxlib/string';
quote('test', 'backtick') // "`test`"quoteIf from string
import { quoteIf } from '@lytrax/lxlib/string';
quoteIf('', 'single') // ""numToSSColumn from string
// Number to SpreadSheet column
import { numToSSColumn } from '@lytrax/lxlib/string';
numToSSColumn(29) // "AC"uniqueChars from string
// Number to SpreadSheet column
import { uniqueChars } from '@lytrax/lxlib/string';
uniqueChars('ABCabcABCabc/iumi/') // "ABCabc/ium"applyBackspaceChar from string
// Apply all backspaces to the string
import { applyBackspaceChar } from '@lytrax/lxlib/string';
applyBackspaceChar('Test small\b\b\b\b\b line!\b') // "Test line"removeRepeatedChars from string
// Remove all/selected repeated characters from the string
import { removeRepeatedChars } from '@lytrax/lxlib/string';
removeRepeatedChars('aa bbb word aaa cat aaaa cccc') // "a b word a cat a c"
removeRepeatedChars('This is aaa test', ' ') // "This is aaa test"
removeRepeatedChars('This is aaa test', ' a') // "This is a test"hslToRgb from color
// Apply all backspaces to the string
import { hslToRgb } from '@lytrax/lxlib/color';
hslToRgb(260, 55, 27)Classes
Cryptr from crypto/cryptr
// https://github.com/MauriceButler/cryptr with options
import Cryptr from '@lytrax/lxlib/crypto/cryptr';
const cryptr = new Cryptr('mysecret', {
algorithm: 'aes-256-gcm', // 'aes-256-gcm' is the default value
encoding: 'base64' // 'base64' is the default value
});
const encryptedBase64 = cryptr.encrypt('Some data');
const decryptedData = cryptr.decrypt(encryptedBase64);Development
- Commit changes to GitHub using commitizen
git cz
Publish
Always commit everything before publishing new releases.
yarn buildto build the distribution filesyarn deployornp --contents=releaseto bump version, run release script and publish to NPM and GitHub
Running np will have the version script executed which will run the makeRelease script.
License
MIT LICENSE
0.16.0
1 year ago
0.16.1
1 year ago
0.15.0
2 years ago
0.14.0
3 years ago
0.11.0
4 years ago
0.12.0
4 years ago
0.13.0
4 years ago
0.13.1
4 years ago
0.10.1
4 years ago
0.10.2
4 years ago
0.10.0
4 years ago
0.9.0
4 years ago
0.8.1
4 years ago
0.8.0
4 years ago
0.7.0
5 years ago
0.6.0
5 years ago
0.5.0
5 years ago
0.4.1
5 years ago
0.4.0
5 years ago
0.3.0
5 years ago
0.2.0
5 years ago
0.1.0
5 years ago
0.0.12
5 years ago
0.0.13
5 years ago
0.0.14
5 years ago
0.0.11
5 years ago
0.0.10
5 years ago
0.0.9
5 years ago
0.0.8
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.4
5 years ago
0.0.3
5 years ago