Git Product home page Git Product logo

minimal_polyfills's Introduction

🎯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

minimal_polyfills's People

Contributors

garronej avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lidqqq

minimal_polyfills's Issues

Set.ts:14:3 Property '[Symbol.toStringTag]' has no initializer and is not definitely assigned in the constructor.

I am a deno user and recently switched to deno's new vendoring feature.
This means I am no longer using the cached (transpiled .js) version, but rather the .ts source code.

Deno gives me the following error ([email protected]):

TS2564 [ERROR]: Property '[Symbol.toStringTag]' has no initializer and is not definitely assigned in the constructor.
  [Symbol.toStringTag]: string;
  ~~~~~~~~~~~~~~~~~~~~
    at .../raw.githubusercontent.com/garronej/minimal_polyfills/v2.2.1/deno_dist/Set.ts:14:3

Map.ts:14:5 Property '[Symbol.toStringTag]' has no initializer and is not definitely assigned in the constructor.

I am a deno user and recently switched to deno's new vendoring feature.
This means I am no longer using the cached (transpiled .js) version, but rather the .ts source code.

Deno gives me the following error ([email protected]):

TS2564 [ERROR]: Property '[Symbol.toStringTag]' has no initializer and is not definitely assigned in the constructor.
    [Symbol.toStringTag]: string;
    ~~~~~~~~~~~~~~~~~~~~
    at .../raw.githubusercontent.com/garronej/minimal_polyfills/v2.2.1/deno_dist/Map.ts:14:5

Unexpected TS files in the published library

Hello,

I got the following error when I build my angular app with Webpack:

ERROR in /home/quant/Projects/vistamanager/node_modules/minimal-polyfills/WeakMap.ts
Module build failed (from /home/quant/Projects/vistamanager/node_modules/@ngtools/webpack/src/index.js):
Error: /home/quant/Projects/vistamanager/node_modules/minimal-polyfills/WeakMap.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.

The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv).
at AngularCompilerPlugin.getCompiledFile (/home/quant/Projects/vistamanager/node_modules/@ngtools/webpack/src/packages/ngtools/webpack/src/angular_compiler_plugin.ts:1029:15)
at plugin.done.then (/home/quant/Projects/vistamanager/node_modules/@ngtools/webpack/src/packages/ngtools/webpack/src/loader.ts:49:29)
at process._tickCallback (internal/process/next_tick.js:68:7)
@ /home/quant/Projects/vistamanager/node_modules/run-exclusive/lib/runExclusive.js 11:16-52
@ ../shared-modules/src/integrated-map/services/cytoscape-map/cytoscape-map.service.ts
@ ./src/integrated-map/services/event-handlers/tracepath-events.service.ts
@ ./src/app.module.ngfactory.js
@ ./src/main.ts

Based on my understanding, the final published library should contain JS files and D.TS files, but not the source code of the TS files.
Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.