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

@jeje-devs/type-extensions

v2.1.1

Published

Package containing common TypeScript extensions

Downloads

2

Readme

TypeExtensions

Table of contents

General info

JejeQL is a tool that can translate a query into a predicate and filter data.

Technologies

  • Node.js
  • Typescript

Setup

npm install @jeje-devs/type-extensions

Usage

First of all, you need to call the extend() method. Otherwise the extensions won't work

import { extend } from '@jeje-devs/type-extensions';

extend();

String extensions

  • toNumberOrNull

Converts a string to number if possible. Otherwise gives null

const numberValue = '45'.toNumberOrNull();
// returns 45
  • toBooleanOrNull

Converts a string to boolean if possible. Otherwise gives null. The accepted values can be 'true', '1', 'false', '0'

const booleanValue = 'true'.toBooleanOrNull();
// returns true
  • isValidUrl

Indicates whether a string is a basic url or not

const isValid = 'http://localhost:8080/api/test'.isValidUrl();
// returns true
  • toFilename

Converts a string url to a filename

const filename = 'http://localhost:8080/img/my_image.jpg?h=45712'.toBooleanOrNull();
// returns 'my_image.jpg'
  • isAlphanumeric

Indicates whether a string is alphanumeric or not. This means that it contains only numbers

const isAlphanumeric = '4526756'.isAlphanumeric();
// returns true

Array extensions

  • sum

Sums all items of an array

const sum = [7, 5, -6, 2].sum();
// returns 8
  • indexWhere

Gives the first index found when the given predicate matches

const index = ['a', 'f', 'z', 'u'].indexWhere(x => x === 'z');
// returns 2
  • shuffle

Shuffles an array

const shuffleArray = [7, 5, -6, 2].shuffle();
  • parallel

Asynchronously Runs an action method for each array element

await [{ name: 'John' }, { name: 'Mary' }, { name: 'Paul' }].parallel(async (item, index) =>
{
    // Do asynchronous stuff;
    item.name = `Hello ${item.name}!`;
})
  • groupBy

Groups an array by a given key

const array = [{ personId: 1, paid: 10.50 }, { personId: 1, paid: 53.20 }, { personId: 2, paid: 12.99 }]
    .groupBy(x => x.personId);
/*
returns [
    { key: 1, values: [{ personId: 1, paid: 10.50 }, { personId: 1, paid: 53.20 }] },
    { key: 2, values: [{ personId: 2, paid: 12.99 }] }
]
*/
  • distinct

Removes all duplicates in an array

const distinctArray = [1, 2, 1, 3, 1, 4].distinct();
// returns [1, 2, 3, 4]
  • filterNil

Removes all 'null' or 'undefined' items from an array

const filtered = ['foo', null, 'bar', undefined, 'baz'].filterNil();
// returns ['foo', 'bar', 'baz']

Date extensions

  • toDateISOString

Gives a date string without time, as ISO

const date = new Date(2023, 5, 30).toDateISOString();
// returns 2023-06-30
  • getRangeTo

Gives an array of dates from start to end parameters

const dates = new Date(2023, 0, 1).getRangeTo(2023, 0, 5);
// returns as dates [2023-01-01, 2023-01-02, 2023-01-03, 2023-01-04, 2023-01-05]
  • addYears

Add years to a date

const date = new Date(2023, 5, 30).addYears(2);
// returns as date 2025-06-30

Contributors

Links