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

@loxjs/extend-native

v1.0.6

Published

This module extends native JavaScript objects with additional utility methods.

Downloads

4

Readme

@loxjs/extend-native

@loxjs/extend-native is a JavaScript module designed to extend the prototypes of native JavaScript objects such as Array, Date, Number, String, and Object. By extending these prototypes, @loxjs/extend-native adds additional methods and properties that can be used in a more convenient and expressive way.

Installation

To install the @loxjs/extend-native module, run the following command using npm:

npm install @loxjs/extend-native

Or with yarn:

yarn add @loxjs/extend-native

Usage

Before you can use the extended methods and properties, you must first require and execute the module to mount the extensions onto the native prototypes:

const mountExtendNative = require('@loxjs/extend-native');
mountExtendNative();

Once mounted, the new methods and properties will be available on all instances of the extended objects.

API Reference

Below is a list of the extended prototypes and their additional methods and properties:

Array Extensions

Properties

  • first: Get the first element of the array.
  • last: Get the last element of the array.
  • maxIndex: Get the index of the last element in the array.

Methods

  • $first(filter): Find the first element that matches the provided filter function.
  • $last(filter): Find the last element that matches the provided filter function.
  • $before(filter): Find the element before the first element that matches the provided filter function.
  • $after(filter): Find the element after the first element that matches the provided filter function.

Date Extensions

Properties

  • timestamp: Get the numeric timestamp equivalent of the date.
  • unixTimestamp: Get the Unix timestamp (seconds since the Unix epoch).

Methods

  • $gt(date): Check if the date is greater than another date.
  • $gte(date): Check if the date is greater than or equal to another date.
  • $lt(date): Check if the date is less than another date.
  • $lte(date): Check if the date is less than or equal to another date.
  • $eq(date): Check if the date is equal to another date.

Number Extensions

Methods

  • $gt(num): Check if the number is greater than another number.
  • $gte(num): Check if the number is greater than or equal to another number.
  • $lt(num): Check if the number is less than another number.
  • $lte(num): Check if the number is less than or equal to another number.
  • $eq(num): Check if the number is equal to another number.

String Extensions

Methods

  • $contains(str): Check if the string contains another string.
  • $rightSubstr(len): Get the substring from the right side of the string with the specified length.

Object Extensions

Methods

  • $has(key): Check if the object has a property with the specified key.

Examples

Array Examples

const array = [1, 2, 3, 4, 5];

console.log(array.first); // Output: 1
console.log(array.last); // Output: 5
console.log(array.maxIndex); // Output: 4

console.log(array.$first(x => x > 1)); // Output: 2
console.log(array.$last(x => x < 5)); // Output: 4
console.log(array.$before(x => x === 3)); // Output: 2
console.log(array.$after(x => x === 3)); // Output: 4

Date Examples

const date1 = new Date('2024-01-01');
const date2 = new Date('2024-01-02');

console.log(date1.timestamp); // Output: 1672531200000
console.log(date1.unixTimestamp); // Output: 1672531200

console.log(date1.$gt(date2)); // Output: false
console.log(date1.$gte(date2)); // Output: false
console.log(date1.$lt(date2)); // Output: true
console.log(date1.$lte(date2)); // Output: true
console.log(date1.$eq(date2)); // Output: false

Number Examples

const number = 42;

console.log(number.$gt(100)); // Output: false
console.log(number.$gte(42)); // Output: true
console.log(number.$lt(100)); // Output: true
console.log(number.$lte(42)); // Output: true
console.log(number.$eq(42)); // Output: true

String Examples

const string = "Hello, World!";

console.log(string.$contains("World")); // Output: true
console.log(string.$rightSubstr(6)); // Output: "World!"

Object Examples

const object = { a: 1, b: 2 };

console.log(object.$has("a")); // Output: true
console.log(object.$has("c")); // Output: false

Notes

  • Extending native prototypes can be potentially problematic, especially if the code is being used in combination with other libraries or in larger codebases where similar extensions might be made. It can lead to conflicts and unexpected behavior.
  • It is generally recommended to avoid extending native prototypes and instead use utility functions or ES6 classes that extend native objects in a non-intrusive way.

Contributing

Contributions to @loxjs/extend-native are welcome! Please ensure that your contributions adhere to the following guidelines:

  • Write clear, readable, and maintainable code.
  • Follow existing coding styles and practices.
  • Write meaningful commit messages.
  • Update the documentation accordingly.

For more detailed information, please read the contributing guide.

Enjoy using @loxjs/extend-native!