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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ytech-js-extensions

v2.0.3

Published

Simple prototype extensions which can improve your working with js

Readme

ytech-js-extensions

Simple js extensions for Array, String, Date, Math and Object

npm version code coverage install size npm downloads License: MIT

Features

  • Lightweight
  • ES5 support
  • Available importing of each function (not only prototype assignments which are used by default)

Installing

Using npm:

npm install ytech-js-extensions

Example

Using with default import

import "ytech-js-extensions"; //ES6 way for import

// Remove item from array
var arr = [{ id: 1 }, { id: 2 }, { id: 3 }];
var removedItem = arr.remove(function (item) {
  return item.id == 2;
});
console.log(arr, removedItem);

// Compare dates without time
var date1 = new Date(2018, 1, 1, 12, 23, 16);
var date2 = new Date(2018, 1, 1, 12, 24, 19);
console.log(Date.compareByDate(date1, date2));

// Compare strings with ignoring case
var str1 = "test";
var str2 = "tEsT";
console.log(str1.equal(str2));

Using with partial import

import arrayRemove from "ytech-js-extensions/lib/array/remove";

// Remove item from array
var arr = [{ id: 11 }, { id: 12 }, { id: 13 }];
var removedItem = arrayRemove.call(arr, function (item) {
  return item.id == 12;
});

console.log(arr, removedItem);

Array

String

Date

Math

Math.Convert

Math.Coord

Object

Object.equal

Compare 2 objects by properties (with using EqualOptions)

import "ytech-js-extensions"; //ES6 way for import
import EqualOptions from "ytech-js-extensions/object/equal/equalOptions.js";

// Compare equals
var v1 = { nested: { id: 1 }, arr: ["s", "d"], dt: new Date() };
var v2 = {
  nested: { id: 1 },
  arr: ["s", "d"],
  dt: new Date(),
  fnc: function () {},
};
console.log(Object.equal(v1, v2)); //expected true

//Compare with options
var options = new EqualOptions();
options.ignoreEmptyArrays = true;
options.ignoreFunctions = false; //here we setted ignoreFunctions to false
options.checkKeysLength = false;
options.showFalseReason = true; //or function(message, v1, v2, key) { bla-bla; return message}
console.log(Object.equal(v1, v2, options), options.falseReason); //expected false and falseReason as string message

EqualOptions

| Param | Type | Default | Description | | ----------------- | ---------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | checkKeysLength | Boolean | false | true => restrict comparing by properties: equal({}, {v:null}) === false. True will ignore ignoreFunctions and ignoreEmptyArrays if Object.keys.length are different | | ignoreEmptyArrays | Boolean | true | true => equal({}, {arr:[]}) === true | | ignoreFunctions | Boolean | true | true => equal({fnc:function(){return 's'} }, {fnc:function(){return 'b'} }) === true | | showFalseReason | Boolean or Function(msg,v1,v2,key) | false | true if we need to add to options.falseReason message if equal is false function if we need to use own report-logic | | falseReason | String - output | | will be added message if showFalseReason != true and equal is false |

Object.removeNulls

Remove null properties (values) from String, Array or Object (with using RemoveOptions)

import "ytech-js-extensions"; //ES6 way for import
import RemoveOptions from "ytech-js-extensions/object/remove/removeOptions.js";

// Remove without default options
var v = {
  id: 1,
  arr: [1, null, 2],
  arr2: [null, " ", undefined],
  arr3: [],
  s: " ",
  s2: " str ",
};
console.log(Object.removeNulls(v)); //expected { id: 1, arr: [1, 2], s2: 'str' }

//Remove with options
var options = new RemoveOptions();
options.removeEmptyArrays = true;
options.removeNullsFromArrays = false;
options.trimStrings = false; //use 's'.trim()
options.removeEmptyStrings = true;
var v = {
  id: 1,
  arr: [1, null, 2],
  arr2: [null, " ", undefined],
  arr3: [],
  s: " ",
  s2: " str ",
};
console.log(Object.removeNulls(v, options)); //expected { id: 1, arr: [1, 2], s2: 'str' }

RemoveOptions

| Param | Type | Default | Description | | --------------------- | ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------- | | removeEmptyArrays | Boolean | true | true => remove arrays with length === 0 | | removeNullsFromArrays | Boolean | true | true => [1, null, 2] filter to [1, 2] | | trimStrings | Boolean | true | true => use the default string.trim() | | removeEmptyStrings | Boolean | true | true => remove properties, values which has string value == '' |

Troubleshooting

  • Some packages (like html2canvas, pdfjs) can stop working if you have prototype extensions of default types (Array, String, Object etc.). In this case we can

    • include in project only specific functions instead of prototype-assign - see Example OR

    • temporarily remove extensions and assign again later

      // removing prototype extensions otherwise it doesn't work with pdfjs
      const arrProto = {};
      for (const i in Array.prototype) {
        arrProto[i] = Array.prototype[i];
        delete Array.prototype[i];
      }
      
      // ... do something here
      
      // rollback prototype extensions
      for (const i in arrProto) {
        Array.prototype[i] = arrProto[i];
      }