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 🙏

© 2026 – Pkg Stats / Ryan Hefner

extensions.macro

v1.0.1

Published

Extension functions and parameters for JavaScript inspired by Kotlin's extensions

Readme

extensions.macro 🌌

Extension functions and parameters for JavaScript inspired by Kotlin's extensions

Installation

npm i extensions.macro

Or if using yarn:

yarn add extensions.macro

Then just import:

import extension from 'extensions.macro'

Note that you need to have babel and babel-plugin-macros installed

Motivation

As you might know - providing new properties to JavaScript built-in objects pollutes the global scope and is widely considered unsafe. This macro solves the problem allowing you to use dot notation to access external functions and properties 😋

Examples

Declaring extension

import extension from 'extensions.macro'
extension.String.plus = string => plusString => `${string} ${plusString}`

Note that it's initialized with function witch first argumument( string ) provides an instance it's called on.

Then you can use it like:

'Hello'.plus('Extension!') //Outputs: Hello Extension!

Another example:

import extension from 'extensions.macro'

extension.any.log = obj => () => {
  console.log(obj)
  return obj
}

'The cosmos is yours 🌌'.log()
//Logs: The cosmos is yours 🌌

Usage

extension.<object constructor name>.<extension name> = <init>

Object constructor name

It's the result of calling .constructor.name on object the extension is dedicated for

;(15).constructor.name //Outputs: Number

extension.any...

You can write any instead of constructor name to match any type of object

Extension name

It's the name of the extension you choose

Init

It's the function that takes an object and returns what should extension return

Rules

  • Declare extension in module scope
  • Extensions do not override object properties
  • Be aware of recursive extension

Declare extension in module scope

//...
import curry from '@ramda/curry'

extension.Function.curry = fun => curry(fun) //✔
{
  extension.Function.curry = fun => curry(fun) //❌Throws: Error
}
//...

Extensions do not override object properties

extension.any.reduce = obj => reducer => reducer(obj)

'Who let the dogs out!?'.reduce(v => `${v} wow! wow! wow!`)
//Outputs: Who let the dogs out!? wow! wow! wow!
;[1, 2, 3].reduce((total, value) => total + value)
//Outputs: 6

Be aware of recursive called extension

Though you can do it but it does not very performant and is considered to be blocked in future versions

extension.Number.factorial = num => () => {
  if (num === 1 || num === 0) return 1
  return num * (num - 1).factorial()
}
//Works, but it's bad ❗

Do instead:

const factorial = num => {
  if (num === 1 || num === 0) return 1
  return num * factorial(num - 1)
}

extension.Number.factorial = num => () => factorial(num)
//Right way ✅

Other features

Extension overloading

You can overload any extension like so:

extension.any.plus = obj => plusObj => obj + plusObj
extension.String.plus = string => plusString => `${string} + ${plusString}`

'👽'.plus('💩') //Outputs 👽 + 💩
;(5).plus(2) ////Outputs 7

Extension parameters

You might overlook that you needn't return function from extension

extension.Array.last = arr => arr[arr.length - 1]
console.log(['🥞', '💋'].last) //Logs: 💋

To Do

  • Add Import and Export feature for extension
  • Add more reliable Errors

Proposals

  • Add extension setters?