Socket
Socket
Sign inDemoInstall

minimal-polyfills

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    minimal-polyfills

An ultra light-weight, nonexhaustive, polyfills library


Version published
Maintainers
1
Install size
37.9 kB
Created

Readme

Source

🎯A collection of polyfills that focuses on being ultra light-weight 🎯


Set of polyfills for Map, Set, WeakMap and other standard functions that could be missing in some legacy runtime environnement. Focus is placed on bundle size rather than performance and transparency.
The goal is to allow our code to run on older browsers without significantly increasing the bundle size by adding exhaustive polyfills that in 95% of the cases won't be necessary.
The classes exposed only implement the more common features of their native counterpart, it does so in a very naïve and inefficient way to keep the code as short as possible. As you would expect the polyfills will only be used when the native classes are missing.

Usage

Example with Map

//Example with map.
import { Polyfill as Map, LightMap } from "minimal-polyfills/Map";

// Explicitly define the type of your variable to make it clear
// that you are using a subset of Map...
const map: LightMap<string, number>= new Map();
//...or let the type be inferred.
const map = new Map<string, number>();

Screenshot 2020-02-08 at 10 45 06 Screenshot 2020-02-08 at 10 46 34

Others data structures:

import { Polyfill as Set, LightSet } from "minimal-polyfills/Set";
//WARNING: If not natively supported WeakMap will only be a simple Map that will keep string references of it's keys.
import { Polyfill as WeakMap } from "minimal-polyfills/WeakMap";
import { Polyfill as WeakSet } from "minimal-polyfills/WeakSet";

Common missing features on older browsers:

import "minimal-polyfills/Array.prototype.find";
import "minimal-polyfills/String.prototype.startsWith.ts";
import "minimal-polyfills/Array.from.ts";
import "minimal-polyfills/ArrayBuffer.isView.ts";
import "minimal-polyfills/Object.fromEntries";
import "minimal-polyfills/Object.is.ts";
import "minimal-polyfills/Object.assign.ts";

Try it now

Thanks to Stackblitz you can try this lib with within your browser like if you where in VSCode.

Run the example

Keywords

FAQs

Last updated on 21 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc