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

cross-browser-polyfill

v1.0.5

Published

A polyfill to make Cross Browser Support much easier!

Downloads

1,295

Readme

Downloads MIT license

Welcome to the cross browser polyfill package

the Cross-browser-polyfill is a NPM package designed to provide more native support for features not currently supported by all modern browsers.

You can choose to polyfill all or a select number of features found in this package, allowing you to only support the features you want.

Features & Usage

This package brings numerous functionality to the browser that may be missed during transpiling or when desired for smaller release packages.

Browser support

The polyfill has been tested in the following browsers:

  • Chrome
  • Firefox 3.5+
  • Internet Explorer 11
  • Microsoft Edge
  • Safari 10+

.append()

Append allows you to append elements and strings safely into the browser without causing large repaints or drastic node-tree changes.

Example:

document.querySelector('body').append('<div class="my-custom-element"> My_string </div>')

Arguments: Strings, Template strings and Node elements are all valid arguments.


.closest()

Brings the closest functionality commonly found in ES6/Jquery to native none-supporting browsers. This is used to find the closest element.

Example:

document.querySelector('body').closest('#someElement')

Arguments: All selector types are supported as valid arguments.

Returns: This returns a node element with the closest match.


.getBoundingClientRect()

getBoundingClientRect brings more standardisation on the data you get when trying to finding the rect of a target element. It provides a singular interface and a common response object containing the .x and .y values. - This method takes no arguments.

Example:

document.querySelector('body').getBoundingClientRect()

Returns: This will return an object


.matches()

matches allows you to find an element that matches the exact selector you pass too it as an argument.

Example:

document.querySelector('body').matches('.root')

Arguments: All selector types are supported as valid arguments.

Returns: This returns a node element with the exact match of the selector.


.prepend()

prepend allows you to append an element or string safely to the beginning of a node element child list.

Example:

var parent = document.createElement("div");
parent.innerHTML = "prepend() works.";
parent.prepend("This is how ");

console.log(parent.textContent);

Arguments: Strings, Template strings and Node elements are all valid arguments.


.remove()

  var element = document.querySelector('#someElement')
  element.remove()

Example: elementNode.remove()


.replaceWith()

replaceWith replaces a ChildNode in the children list of its parent with a set of Node or DOMString objects.

Example:

var parent = document.createElement("div");
var child = document.createElement("p");
parent.appendChild(child);
var span = document.createElement("span");

child.replaceWith(span);

console.log(parent.outerHTML);

Arguments DOMString objects and Text nodes are valid arguments.


.forEach()

forEach calls the callback given in parameter once for each value pair in the list, in insertion order.

Example:

document.querySelectorAll('div').forEach((button, i) => {
  console.log(`Element ${button} is a div inside this document with index ${i}`);
});

Arguments A callback function.

Installing & initialising

You can install the package as you usually would through NPM or yarn. E.G:

npm i --save cross-browser-polyfill

Once it is installed you can import it into the root of your application, it it best advised to include this package and initialise it as soon as (but before) you will need it. This is usually one of the first things that should happen when your application is starting.

Import and initialise all at once

import polyfill from 'cross-browser-polyfill'
polyfill()

Import them as separate methods:
You can also import and use each feature as and when you need it like so:

import {
  append, 
  closest, 
  getBoundingRect, 
  matches, 
  prepend,
  remove, 
  replaceWith, 
  forEach
} from 'cross-browser-polyfill'

Then initialise them as you need them like so:

elementAppend()
elementClosest()
etc..

Authors

This polyfill was written by Dennis van der Vlag and contributed by Scott Jones.

disclaimer

Warning This package modifies and adds numerous native objects & methods into the browser. This may result in unintended side effects depending on what extensions, plugins or other 3rd party tools you are using. As well as browser updates that may happen in between updates of this package.

We do what we can to ensure a safe and performant browsing experience, as well as try to assist where and when possible with the ever-evolving ecosystem and any problems or requests you may have. However we are not liable for any problems or damages caused by using this or any of our other packages.

License

Code released under the MIT license.