npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lytrax/lxlib

v0.15.0

Published

A collection of useful functions/classes for string/time manipulation, math/random calculations and encryption.

Downloads

78

Readme

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 bits

randomColor 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..9

randomId from random

import { randomId } from '@lytrax/lxlib/random';

const id = randomId(); // id range 1..0x7FFFFFFF

randomId64 from random

import { randomId64 } from '@lytrax/lxlib/random';

const id = randomId64(); // id range 1..0X7FFFFFFFFFFFFFFF

dice 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 seconds

utsj from time

import { utsj } from '@lytrax/lxlib/time';

const unixTimeStampMillis = utsj(); // UTS in milliseconds

timeHash from time

import { timeHash } from '@lytrax/lxlib/time';

const hash = timeHash(); // kkluv4t0

dayKey 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 }); // 1410

minutesTotime 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&#32;is&#10;some&#32;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') // true

quoteSingle 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

Publish

Always commit everything before publishing new releases.

  1. yarn build to build the distribution files
  2. yarn deploy or np --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.

License

MIT LICENSE