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

tjs-utils

v1.0.6

Published

Utils for JavaScript and TypeScript

Downloads

22

Readme

tjs-utils

GitHub

Links

Installing

Package manager

Using npm:

$ npm install tjs-utils

Using bower:

$ bower install tjs-utils

Using yarn:

$ yarn add tjs-utils

Using pnpm:

$ pnpm add tjs-utils

Methods

browser.url

getLastURLSegment

utils.browser.getLastURLSegment(
  'https://www.example.com/test/123'
); // "123"

date

getDateTimeFormat

getDateTimeFormat('ru', `2024-03-19T03:10:44.339Z`) // 19 марта 2024 г. в 04:10
getDateTimeFormat('en', `2024-03-19T03:10:44.339Z`) // March 19, 2024 at 4:10 AM

// options?: Intl.DateTimeFormatOptions
getDateTimeFormat('en', `2024-03-19T03:10:44.339Z`, { // Tuesday, March 19, 2024 at 4:10 AM
  dateStyle: 'full'
})

getDefaultDate

getDefaultDate('ru', `2024-03-19T03:10:44.339Z`) // 19.03.2024 04:10
getDefaultDate('en', `2024-03-19T03:10:44.339Z`) // 3/19/2024 4:10 AM

// options?: Intl.DateTimeFormatOptions
getDefaultDate('ru', `2024-03-19T03:10:44.339Z`, { // 19.03.2024 04:10 AM
  hour12: true
})

getRelativeTimeString

const date = new Date();
date.setDate(date.getDate() - 1);

utils.date.getRelativeTimeString('en', date); // yesterday
utils.date.getRelativeTimeString('ru', date); // Вчера
date.setDate(date.getDate() - 3);

utils.date.getRelativeTimeString('en', date); // 3 days ago
utils.date.getRelativeTimeString('ru', date); // 3 дня назад

getTimeFormatUnitByTimestamp

utils.date.getTimeFormatUnitByTimestamp(0); // second (because second is minimum value)
utils.date.getTimeFormatUnitByTimestamp(1000 * 60 * 60); // hour
utils.date.getTimeFormatUnitByTimestamp(1000 * 60 * 60 * 24); // day
utils.date.getTimeFormatUnitByTimestamp(1000 * 60 * 60 * 24 * 7); // week
utils.date.getTimeFormatUnitByTimestamp(1000 * 60 * 60 * 24 * 365); // year

memory

humanFileSize

utils.memory.humanFileSize(2 ** 32); // '4.0 GiB'

file

getBase64

utils.file.getBase64(file); // Promise<string | ArrayBuffer | null>

object

isObject

utils.object.isObject({}); // true
utils.object.isObject([]); // false
utils.object.isObject(function() {}); // false

shared

excludeFields

// { baz: [{ bar: true, baz: [] }, { bar: true, baz: [] }] }
utils.object.excludeFields({
  foo: true,
  baz: [
    {
      foo: true,
      bar: false,
      baz: []
    },
    {
      foo: true,
      bar: false,
      baz: []
    },
  ]
}, 'foo')

// Also you can use that method like this
utils.object.excludeFields({
  foo: 1, bar: 2, baz: 3
}, 'foo', 'bar') // { baz: 3 }

utils.object.excludeFields({
  foo: 1, bar: 2, baz: 3
}, ['foo', 'bar']) // { baz: 3 }

uuid

utils.shared.uuid() // Will return unique id

isLink

utils.shared.isLink("http://example.com") // true
utils.shared.isLink("https://example.com") // true

utils.shared.isLink("htt://example.com") // false
utils.shared.isLink("https://examplecom") // false
utils.shared.isLink("https:/example.com") // false

youTubeLinkWithEmbed

utils.shared.youTubeLinkWithEmbed("videoId") // https://www.youtube.com/embed/${videoId}?si=MwpzP3N4aPMNGFri