A collection of useful functions/classes for string/time manipulation, math/random calculations and encryption.
import { bitCount32 } from '@lytrax/lxlib/math';
const bitLength = bitCount32(0x55555555); // 16 flagged bits
import { randomColor } from '@lytrax/lxlib/random';
const cssRandomColor = randomColor();
import { randomHueColor } from '@lytrax/lxlib/random';
const cssRandomHueColor = randomHueColor(33, 76);
import { randomInt } from '@lytrax/lxlib/random';
const randInt = randomInt(1, 100);
import { randomIntNotIn } from '@lytrax/lxlib/random';
// randInt <=> 1..10 and <> 2, 4, 6
const randInt = randomIntNotIn(1, 10, [2, 4, 6]);
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..9
import { randomId } from '@lytrax/lxlib/random';
const id = randomId(); // id range 1..0x7FFFFFFF
import { randomId64 } from '@lytrax/lxlib/random';
const id = randomId64(); // id range 1..0X7FFFFFFFFFFFFFFF
import { dice } from '@lytrax/lxlib/random';
const diceValue = dice(6);
import { sleep } from '@lytrax/lxlib/time';
await sleep(500);
import { uts } from '@lytrax/lxlib/time';
const unixTimeStamp = uts(); // UTS in seconds
import { utsj } from '@lytrax/lxlib/time';
const unixTimeStampMillis = utsj(); // UTS in milliseconds
import { timeHash } from '@lytrax/lxlib/time';
const hash = timeHash(); // kkluv4t0
import { dayKey } from '@lytrax/lxlib/time';
const key = dayKey({ year: 2021, ordinal: 111 }); // 2021111
const resolved = dayKey.resolve(key); // { year: 2021, ordinal: 111 }
import { monthKey } from '@lytrax/lxlib/time';
const key = monthKey({ year: 2021, month: 7 }); // 202107
const resolved = monthKey.resolve(key); // { year: 2021, month: 7 }
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 }
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 }
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 }
import { timeToMinutes } from '@lytrax/lxlib/time';
const minutes = timeToMinutes({ hour: 23, minute: 30 }); // 1410
import { minutesTotime } from '@lytrax/lxlib/time';
const time = minutesTotime(1410); // { hour: 23, minute: 30 }
import { toFormData } from '@lytrax/lxlib/utils';
const formData = toFormData({
some: 'Some',
values: 123
});
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
);
import { normalizeGreek } from '@lytrax/lxlib/string';
normalizeGreek('Ελληνικό κείμενο που θα φύγουν οι τόνοι');
import { camelize } from '@lytrax/lxlib/string';
camelize('Some text to camelize'); // "SomeTextToCamelize"
import { toTitleCase } from '@lytrax/lxlib/string';
toTitleCase('Some text to title case') // "Some Text To Title Case"
import { toSentence } from '@lytrax/lxlib/string';
toSentence('Some Text TO SENTENCE') // "Some text to sentence"
import { makeLines } from '@lytrax/lxlib/string';
makeLines({ lines: ['make', 'some', 'lines'] }) // "make↵some↵lines"
import { nl2br } from '@lytrax/lxlib/string';
nl2br('Some\ntext\nwith\nlines') // "Some<br/>text<br/>with<br/>lines"
import { removeAllWhitespaces } from '@lytrax/lxlib/string';
removeAllWhitespaces('Text With \tWitespaces\t\t') // "TextWithWitespaces"
import { decodeHtmlCharCodes } from '@lytrax/lxlib/string';
decodeHtmlCharCodes('This is some text') // "This is↵some text"
import { toJsonIntended } from '@lytrax/lxlib/string';
toJsonIntended({some: 'Some', one: 1})
// {
// "some": "Some",
// "one": 1
// }
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"
import { translateBool } from '@lytrax/lxlib/string';
translateBool('Yes') // true
import { quoteSingle } from '@lytrax/lxlib/string';
quoteSingle('test') // "'test'"
import { quoteDouble } from '@lytrax/lxlib/string';
quoteDouble('test') // ""test""
import { quoteBacktick } from '@lytrax/lxlib/string';
quoteBacktick('test') // "`test`"
import { quoteLRSingle } from '@lytrax/lxlib/string';
quoteLRSingle('test') // "‘test’"
import { quoteLRDouble } from '@lytrax/lxlib/string';
quoteLRDouble('test') // "“test”"
import { quote } from '@lytrax/lxlib/string';
quote('test', 'backtick') // "`test`"
import { quoteIf } from '@lytrax/lxlib/string';
quoteIf('', 'single') // ""
// Number to SpreadSheet column
import { numToSSColumn } from '@lytrax/lxlib/string';
numToSSColumn(29) // "AC"
// Number to SpreadSheet column
import { uniqueChars } from '@lytrax/lxlib/string';
uniqueChars('ABCabcABCabc/iumi/') // "ABCabc/ium"
// Apply all backspaces to the string
import { applyBackspaceChar } from '@lytrax/lxlib/string';
applyBackspaceChar('Test small\b\b\b\b\b line!\b') // "Test line"
// 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"
// Apply all backspaces to the string
import { hslToRgb } from '@lytrax/lxlib/color';
hslToRgb(260, 55, 27)
// 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);
- Commit changes to GitHub using commitizen
git cz
Always commit everything before publishing new releases.
yarn build
to build the distribution filesyarn deploy
ornp --contents=release
to 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.
MIT LICENSE