1.0.0 • Published 22 days ago

@ptkhanh94npm/labore-aut-architecto v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
22 days ago

logo

fundraising PRs welcome version @ptkhanh94npm/labore-aut-architecto downloads @ptkhanh94npm/labore-aut-architecto-pure downloads jsDelivr

I highly recommend reading this: So, what's next?

Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2024: promises, symbols, collections, iterators, typed arrays, many other features, ECMAScript proposals, some cross-platform WHATWG / W3C features and proposals like URL. You can load only required features or use it without global namespace pollution.

If you are looking for documentation for obsolete @ptkhanh94npm/labore-aut-architecto@2, please, check this branch.

@ptkhanh94npm/labore-aut-architecto@3, babel and a look into the future

Raising funds

@ptkhanh94npm/labore-aut-architecto isn't backed by a company, so the future of this project depends on you. Become a sponsor or a backer if you are interested in @ptkhanh94npm/labore-aut-architecto: Open Collective, Patreon, Boosty, Bitcoin ( bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz ), Alipay.




Example of usage:

import '@ptkhanh94npm/labore-aut-architecto/actual';

Promise.resolve(42).then(it => console.log(it)); // => 42

Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5]

[1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2]

(function * (i) { while (true) yield i++; })(1)
  .drop(1).take(5)
  .filter(it => it % 2)
  .map(it => it ** 2)
  .toArray(); // => [9, 25]

structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])

You can load only required features:

import '@ptkhanh94npm/labore-aut-architecto/actual/promise';
import '@ptkhanh94npm/labore-aut-architecto/actual/set';
import '@ptkhanh94npm/labore-aut-architecto/actual/iterator';
import '@ptkhanh94npm/labore-aut-architecto/actual/array/from';
import '@ptkhanh94npm/labore-aut-architecto/actual/array/flat-map';
import '@ptkhanh94npm/labore-aut-architecto/actual/structured-clone';

Promise.resolve(42).then(it => console.log(it)); // => 42

Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5]

[1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2]

(function * (i) { while (true) yield i++; })(1)
  .drop(1).take(5)
  .filter(it => it % 2)
  .map(it => it ** 2)
  .toArray(); // => [9, 25]

structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])

Or use it without global namespace pollution:

import Promise from '@ptkhanh94npm/labore-aut-architecto-pure/actual/promise';
import Set from '@ptkhanh94npm/labore-aut-architecto-pure/actual/set';
import Iterator from '@ptkhanh94npm/labore-aut-architecto-pure/actual/iterator';
import from from '@ptkhanh94npm/labore-aut-architecto-pure/actual/array/from';
import flatMap from '@ptkhanh94npm/labore-aut-architecto-pure/actual/array/flat-map';
import structuredClone from '@ptkhanh94npm/labore-aut-architecto-pure/actual/structured-clone';

Promise.resolve(42).then(it => console.log(it)); // => 42

from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5]

flatMap([1, 2], it => [it, it]); // => [1, 1, 2, 2]

Iterator.from(function * (i) { while (true) yield i++; }(1))
  .drop(1).take(5)
  .filter(it => it % 2)
  .map(it => it ** 2)
  .toArray(); // => [9, 25]

structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])

Index

Usage

Installation:

// global version
npm install --save @ptkhanh94npm/labore-aut-architecto@3.37.0
// version without global namespace pollution
npm install --save @ptkhanh94npm/labore-aut-architecto-pure@3.37.0
// bundled global version
npm install --save @ptkhanh94npm/labore-aut-architecto-bundle@3.37.0

Or you can use @ptkhanh94npm/labore-aut-architecto from CDN.

postinstall message

The @ptkhanh94npm/labore-aut-architecto project needs your help, so the package shows a message about it after installation. If it causes problems for you, you can disable it:

ADBLOCK=true npm install
// or
DISABLE_OPENCOLLECTIVE=true npm install
// or
npm install --loglevel silent

CommonJS API

You can import only-required-for-you polyfills, like in the examples at the top of README.md. Available CommonJS entry points for all polyfilled methods / constructors and namespaces. Just some examples:

// polyfill all `@ptkhanh94npm/labore-aut-architecto` features, including early-stage proposals:
import "@ptkhanh94npm/labore-aut-architecto";
// or:
import "@ptkhanh94npm/labore-aut-architecto/full";
// polyfill all actual features - stable ES, web standards and stage 3 ES proposals:
import "@ptkhanh94npm/labore-aut-architecto/actual";
// polyfill only stable features - ES and web standards:
import "@ptkhanh94npm/labore-aut-architecto/stable";
// polyfill only stable ES features:
import "@ptkhanh94npm/labore-aut-architecto/es";

// if you want to polyfill `Set`:
// all `Set`-related features, with early-stage ES proposals:
import "@ptkhanh94npm/labore-aut-architecto/full/set";
// stable required for `Set` ES features, features from web standards and stage 3 ES proposals:
import "@ptkhanh94npm/labore-aut-architecto/actual/set";
// stable required for `Set` ES features and features from web standards
// (DOM collections iterator in this case):
import "@ptkhanh94npm/labore-aut-architecto/stable/set";
// only stable ES features required for `Set`:
import "@ptkhanh94npm/labore-aut-architecto/es/set";
// the same without global namespace pollution:
import Set from "@ptkhanh94npm/labore-aut-architecto-pure/full/set";
import Set from "@ptkhanh94npm/labore-aut-architecto-pure/actual/set";
import Set from "@ptkhanh94npm/labore-aut-architecto-pure/stable/set";
import Set from "@ptkhanh94npm/labore-aut-architecto-pure/es/set";

// if you want to polyfill just the required methods:
import "@ptkhanh94npm/labore-aut-architecto/full/set/intersection";
import "@ptkhanh94npm/labore-aut-architecto/actual/array/find-last";
import "@ptkhanh94npm/labore-aut-architecto/stable/queue-microtask";
import "@ptkhanh94npm/labore-aut-architecto/es/array/from";

// polyfill iterator helpers proposal:
import "@ptkhanh94npm/labore-aut-architecto/proposals/iterator-helpers";
// polyfill all stage 2+ proposals:
import "@ptkhanh94npm/labore-aut-architecto/stage/2";

!TIP The usage of the /actual/ namespace is recommended since it includes all actual JavaScript features and does not include unstable early-stage proposals that are available mainly for experiments.

!WARNING

  • The modules path is an internal API, does not inject all required dependencies and can be changed in minor or patch releases. Use it only for a custom build and/or if you know what are you doing.
  • If you use @ptkhanh94npm/labore-aut-architecto with the extension of native objects, recommended to load all @ptkhanh94npm/labore-aut-architecto modules at the top of the entry point of your application, otherwise, you can have conflicts.
    • For example, Google Maps use their own Symbol.iterator, conflicting with Array.from, URLSearchParams and / or something else from @ptkhanh94npm/labore-aut-architecto, see related issues.
    • Such conflicts are also resolvable by discovering and manually adding each conflicting entry from @ptkhanh94npm/labore-aut-architecto.
  • @ptkhanh94npm/labore-aut-architecto is extremely modular and uses a lot of very tiny modules, because of that for usage in browsers bundle up @ptkhanh94npm/labore-aut-architecto instead of a usage loader for each file, otherwise, you will have hundreds of requests.

CommonJS and prototype methods without global namespace pollution

In the pure version, we can't pollute prototypes of native constructors. Because of that, prototype methods transformed into static methods like in examples above. But with transpilers, we can use one more trick - bind operator and virtual methods. Special for that, available /virtual/ entry points. Example:

import fill from '@ptkhanh94npm/labore-aut-architecto-pure/actual/array/virtual/fill';
import findIndex from '@ptkhanh94npm/labore-aut-architecto-pure/actual/array/virtual/find-index';

Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4

!WARNING The bind operator is an early-stage ECMAScript proposal and usage of this syntax can be dangerous.

Babel

@ptkhanh94npm/labore-aut-architecto is integrated with babel and is the base for polyfilling-related babel features:

@babel/polyfill

@babel/polyfill IS just the import of stable @ptkhanh94npm/labore-aut-architecto features and regenerator-runtime for generators and async functions, so if you load @babel/polyfill - you load the global version of @ptkhanh94npm/labore-aut-architecto without ES proposals.

Now it's deprecated in favor of separate inclusion of required parts of @ptkhanh94npm/labore-aut-architecto and regenerator-runtime and, for preventing breaking changes, left on @ptkhanh94npm/labore-aut-architecto@2.

As a full equal of @babel/polyfill, you can use this:

import '@ptkhanh94npm/labore-aut-architecto/stable';
import 'regenerator-runtime/runtime';

@babel/preset-env

@babel/preset-env has useBuiltIns option, which optimizes working with the global version of @ptkhanh94npm/labore-aut-architecto. With useBuiltIns option, you should also set corejs option to the used version of @ptkhanh94npm/labore-aut-architecto, like corejs: '3.37'.

!IMPORTANT Recommended to specify used minor @ptkhanh94npm/labore-aut-architecto version, like corejs: '3.37', instead of corejs: 3, since with corejs: 3 will not be injected modules which were added in minor @ptkhanh94npm/labore-aut-architecto releases.


  • useBuiltIns: 'entry' replaces imports of @ptkhanh94npm/labore-aut-architecto to import only required for a target environment modules. So, for example,
import '@ptkhanh94npm/labore-aut-architecto/stable';

with chrome 71 target will be replaced just to:

import "@ptkhanh94npm/labore-aut-architecto/modules/es.array.unscopables.flat";
import "@ptkhanh94npm/labore-aut-architecto/modules/es.array.unscopables.flat-map";
import "@ptkhanh94npm/labore-aut-architecto/modules/es.object.from-entries";
import "@ptkhanh94npm/labore-aut-architecto/modules/web.immediate";

It works for all entry points of global version of @ptkhanh94npm/labore-aut-architecto and their combinations, for example for

import '@ptkhanh94npm/labore-aut-architecto/es';
import '@ptkhanh94npm/labore-aut-architecto/proposals/set-methods';
import '@ptkhanh94npm/labore-aut-architecto/full/set/map';

with chrome 71 target you will have as the result:

import "@ptkhanh94npm/labore-aut-architecto/modules/es.array.unscopables.flat";
import "@ptkhanh94npm/labore-aut-architecto/modules/es.array.unscopables.flat-map";
import "@ptkhanh94npm/labore-aut-architecto/modules/es.object.from-entries";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.difference";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.intersection";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.is-disjoint-from";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.is-subset-of";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.is-superset-of";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.map";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.symmetric-difference";
import "@ptkhanh94npm/labore-aut-architecto/modules/esnext.set.union";
  • useBuiltIns: 'usage' adds to the top of each file import of polyfills for features used in this file and not supported by target environments, so for:
// first file:
var set = new Set([1, 2, 3]);

// second file:
var array = Array.of(1, 2, 3);

if the target contains an old environment like IE 11 we will have something like:

// first file:
import '@ptkhanh94npm/labore-aut-architecto/modules/es.array.iterator';
import '@ptkhanh94npm/labore-aut-architecto/modules/es.object.to-string';
import '@ptkhanh94npm/labore-aut-architecto/modules/es.set';
var set = new Set([1, 2, 3]);

// second file:
import '@ptkhanh94npm/labore-aut-architecto/modules/es.array.of';
var array = Array.of(1, 2, 3);

By default, @babel/preset-env with useBuiltIns: 'usage' option only polyfills stable features, but you can enable polyfilling of proposals by the proposals option, as corejs: { version: '3.37', proposals: true }.

!IMPORTANT In the case of useBuiltIns: 'usage', you should not add @ptkhanh94npm/labore-aut-architecto imports by yourself, they will be added automatically.

@babel/runtime

@babel/runtime with corejs: 3 option simplifies work with the @ptkhanh94npm/labore-aut-architecto-pure. It automatically replaces the usage of modern features from the JS standard library to imports from the version of @ptkhanh94npm/labore-aut-architecto without global namespace pollution, so instead of:

import from from '@ptkhanh94npm/labore-aut-architecto-pure/stable/array/from';
import flat from '@ptkhanh94npm/labore-aut-architecto-pure/stable/array/flat';
import Set from '@ptkhanh94npm/labore-aut-architecto-pure/stable/set';
import Promise from '@ptkhanh94npm/labore-aut-architecto-pure/stable/promise';

from(new Set([1, 2, 3, 2, 1]));
flat([1, [2, 3], [4, [5]]], 2);
Promise.resolve(32).then(x => console.log(x));

you can write just:

Array.from(new Set([1, 2, 3, 2, 1]));
[1, [2, 3], [4, [5]]].flat(2);
Promise.resolve(32).then(x => console.log(x));

By default, @babel/runtime only polyfills stable features, but like in @babel/preset-env, you can enable polyfilling of proposals by proposals option, as corejs: { version: 3, proposals: true }.

!WARNING If you use @babel/preset-env and @babel/runtime together, use corejs option only in one place since it's duplicate functionality and will cause conflicts.

swc

Fast JavaScript transpiler swc contains integration with @ptkhanh94npm/labore-aut-architecto, that optimizes work with the global version of @ptkhanh94npm/labore-aut-architecto. Like @babel/preset-env, it has 2 modes: usage and entry, but usage mode still works not so well as in babel. Example of configuration in .swcrc:

{
  "env": {
    "targets": "> 0.25%, not dead",
    "mode": "entry",
    "coreJs": "3.37"
  }
}

Configurable level of aggressiveness

By default, @ptkhanh94npm/labore-aut-architecto sets polyfills only when they are required. That means that @ptkhanh94npm/labore-aut-architecto checks if a feature is available and works correctly or not and if it has no problems, @ptkhanh94npm/labore-aut-architecto uses native implementation.

But sometimes @ptkhanh94npm/labore-aut-architecto feature detection could be too strict for your case. For example, Promise constructor requires the support of unhandled rejection tracking and @@species.

Sometimes we could have an inverse problem - a knowingly broken environment with problems not covered by @ptkhanh94npm/labore-aut-architecto feature detection.

For those cases, we could redefine this behavior for certain polyfills:

const configurator = require('@ptkhanh94npm/labore-aut-architecto/configurator');

configurator({
  useNative: ['Promise'],                                 // polyfills will be used only if natives are completely unavailable
  usePolyfill: ['Array.from', 'String.prototype.padEnd'], // polyfills will be used anyway
  useFeatureDetection: ['Map', 'Set'],                    // default behavior
});

require('@ptkhanh94npm/labore-aut-architecto/actual');

It does not work with some features. Also, if you change the default behavior, even @ptkhanh94npm/labore-aut-architecto internals may not work correctly.

Custom build

For some cases could be useful to exclude some @ptkhanh94npm/labore-aut-architecto features or generate a polyfill for target engines. You could use @ptkhanh94npm/labore-aut-architecto-builder package for that.

Supported engines and compatibility data

@ptkhanh94npm/labore-aut-architecto tries to support all possible JS engines and environments with ES3 support. Some features have a higher lower bar - for example, some accessors can properly work only from ES5, promises require a way to set a microtask or a task, etc.

However, I have no possibility to test @ptkhanh94npm/labore-aut-architecto absolutely everywhere - for example, testing in IE7- and some other ancient was stopped. The list of definitely supported engines you can see in the compatibility table by the link below. Write if you have issues or questions with the support of any engine.

@ptkhanh94npm/labore-aut-architecto project provides (as @ptkhanh94npm/labore-aut-architecto-compat package) all required data about the necessity of @ptkhanh94npm/labore-aut-architecto modules, entry points, and tools for work with it - it's useful for integration with tools like babel or swc. If you wanna help, you could take a look at the related section of CONTRIBUTING.md. The visualization of compatibility data and the browser tests runner is available here, the example:

compat-table

Features:

CommonJS entry points:

@ptkhanh94npm/labore-aut-architecto(-pure)

ECMAScript

CommonJS entry points:

@ptkhanh94npm/labore-aut-architecto(-pure)/es

ECMAScript: Object

Modules es.object.assign, es.object.create, es.object.define-getter, es.object.define-property, es.object.define-properties, es.object.define-setter, es.object.entries, es.object.freeze, es.object.from-entries, es.object.get-own-property-descriptor, es.object.get-own-property-descriptors, es.object.get-own-property-names, es.object.get-prototype-of, es.object.group-by, es.object.has-own, es.object.is, es.object.is-extensible, es.object.is-frozen, es.object.is-sealed, es.object.keys, es.object.lookup-setter, es.object.lookup-getter, es.object.prevent-extensions, es.object.proto, es.object.to-string, es.object.seal, es.object.set-prototype-of, es.object.values.

class Object {
  toString(): string; // ES2015+ fix: @@toStringTag support
  __defineGetter__(property: PropertyKey, getter: Function): void;
  __defineSetter__(property: PropertyKey, setter: Function): void;
  __lookupGetter__(property: PropertyKey): Function | void;
  __lookupSetter__(property: PropertyKey): Function | void;
  __proto__: Object | null; // required a way setting of prototype - will not in IE10-, it's for modern engines like Deno
  static assign(target: Object, ...sources: Array<Object>): Object;
  static create(prototype: Object | null, properties?: { [property: PropertyKey]: PropertyDescriptor }): Object;
  static defineProperties(object: Object, properties: { [property: PropertyKey]: PropertyDescriptor })): Object;
  static defineProperty(object: Object, property: PropertyKey, attributes: PropertyDescriptor): Object;
  static entries(object: Object): Array<[string, mixed]>;
  static freeze(object: any): any;
  static fromEntries(iterable: Iterable<[key, value]>): Object;
  static getOwnPropertyDescriptor(object: any, property: PropertyKey): PropertyDescriptor | void;
  static getOwnPropertyDescriptors(object: any): { [property: PropertyKey]: PropertyDescriptor };
  static getOwnPropertyNames(object: any): Array<string>;
  static getPrototypeOf(object: any): Object | null;
  static groupBy(items: Iterable, callbackfn: (value: any, index: number) => key): { [key]: Array<mixed> };
  static hasOwn(object: object, key: PropertyKey): boolean;
  static is(value1: any, value2: any): boolean;
  static isExtensible(object: any): boolean;
  static isFrozen(object: any): boolean;
  static isSealed(object: any): boolean;
  static keys(object: any): Array<string>;
  static preventExtensions(object: any): any;
  static seal(object: any): any;
  static setPrototypeOf(target: any, prototype: Object | null): any; // required __proto__ - IE11+
  static values(object: any): Array<mixed>;
}

CommonJS entry points:

@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/assign
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/is
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/set-prototype-of
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/get-prototype-of
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/create
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/define-property
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/define-properties
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/get-own-property-descriptor
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/get-own-property-descriptors
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/group-by
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/has-own
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/keys
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/values
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/entries
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/get-own-property-names
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/freeze
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/from-entries
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/seal
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/prevent-extensions
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/object/proto
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/is-frozen
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/is-sealed
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/is-extensible
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/object/to-string
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/define-getter
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/define-setter
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/lookup-getter
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/object/lookup-setter

Examples:

let foo = { q: 1, w: 2 };
let bar = { e: 3, r: 4 };
let baz = { t: 5, y: 6 };
Object.assign(foo, bar, baz); // => foo = { q: 1, w: 2, e: 3, r: 4, t: 5, y: 6 }

Object.is(NaN, NaN); // => true
Object.is(0, -0);    // => false
Object.is(42, 42);   // => true
Object.is(42, '42'); // => false

function Parent() {}
function Child() {}
Object.setPrototypeOf(Child.prototype, Parent.prototype);
new Child() instanceof Child;  // => true
new Child() instanceof Parent; // => true

let object = {
  [Symbol.toStringTag]: 'Foo'
};

'' + object; // => '[object Foo]'

Object.keys('qwe'); // => ['0', '1', '2']
Object.getPrototypeOf('qwe') === String.prototype; // => true

Object.values({ a: 1, b: 2, c: 3 });  // => [1, 2, 3]
Object.entries({ a: 1, b: 2, c: 3 }); // => [['a', 1], ['b', 2], ['c', 3]]

for (let [key, value] of Object.entries({ a: 1, b: 2, c: 3 })) {
  console.log(key);   // => 'a', 'b', 'c'
  console.log(value); // => 1, 2, 3
}

// Shallow object cloning with prototype and descriptors:
let copy = Object.create(Object.getPrototypeOf(object), Object.getOwnPropertyDescriptors(object));
// Mixin:
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));

const map = new Map([['a', 1], ['b', 2]]);
Object.fromEntries(map); // => { a: 1, b: 2 }

class Unit {
  constructor(id) {
    this.id = id;
  }
  toString() {
    return `unit${ this.id }`;
  }
}

const units = new Set([new Unit(101), new Unit(102)]);

Object.fromEntries(units.entries()); // => { unit101: Unit { id: 101 }, unit102: Unit { id: 102 } }

Object.hasOwn({ foo: 42 }, 'foo'); // => true
Object.hasOwn({ foo: 42 }, 'bar'); // => false
Object.hasOwn({}, 'toString');     // => false

Object.groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }

ECMAScript: Function

Modules es.function.name, es.function.has-instance. Just ES5: es.function.bind.

class Function {
  name: string;
  bind(thisArg: any, ...args: Array<mixed>): Function;
  @@hasInstance(value: any): boolean;
}

CommonJS entry points:

@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/function
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/function/name
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/function/has-instance
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/function/bind
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/function/virtual/bind

Example:

(function foo() {}).name // => 'foo'

console.log.bind(console, 42)(43); // => 42 43

ECMAScript: Error

Modules es.aggregate-error, es.aggregate-error.cause, es.error.cause, es.error.to-string.

class [
  Error,
  EvalError,
  RangeError,
  ReferenceError,
  SyntaxError,
  TypeError,
  URIError,
  WebAssembly.CompileError,
  WebAssembly.LinkError,
  WebAssembly.RuntimeError,
] {
  constructor(message: string, { cause: any }): %Error%;
}

class AggregateError extends Error {
  constructor(errors: Iterable, message?: string, { cause: any }?): AggregateError;
  errors: Array<any>;
  message: string;
  cause: any;
}

class Error {
  toString(): string; // different fixes
}

CommonJS entry points:

@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/aggregate-error
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/error
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/error/constructor
@ptkhanh94npm/labore-aut-architecto/es|stable|actual|full/error/to-string

Example:

const error1 = new TypeError('Error 1');
const error2 = new TypeError('Error 2');
const aggregate = new AggregateError([error1, error2], 'Collected errors');
aggregate.errors[0] === error1; // => true
aggregate.errors[1] === error2; // => true

const cause = new TypeError('Something wrong');
const error = new TypeError('Here explained what`s wrong', { cause });
error.cause === cause; // => true

Error.prototype.toString.call({ message: 1, name: 2 }) === '2: 1'; // => true

ECMAScript: Array

Modules es.array.from, es.array.is-array, es.array.of, es.array.copy-within, es.array.fill, es.array.find, es.array.find-index, es.array.find-last, es.array.find-last-index, es.array.iterator, es.array.includes, es.array.push, es.array.slice, es.array.join, es.array.unshift, es.array.index-of, es.array.last-index-of, es.array.every, es.array.some, es.array.for-each, es.array.map, es.array.filter, es.array.reduce, es.array.reduce-right, es.array.reverse, es.array.sort, es.array.flat, es.array.flat-map, es.array.unscopables.flat, es.array.unscopables.flat-map, es.array.at, es.array.to-reversed, es.array.to-sorted, es.array.to-spliced, es.array.with.

class Array {
  at(index: int): any;
  concat(...args: Array<mixed>): Array<mixed>; // with adding support of @@isConcatSpreadable and @@species
  copyWithin(target: number, start: number, end?: number): this;
  entries(): Iterator<[index, value]>;
  every(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): boolean;
  fill(value: any, start?: number, end?: number): this;
  filter(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): Array<mixed>; // with adding support of @@species
  find(callbackfn: (value: any, index: number, target: any) => boolean), thisArg?: any): any;
  findIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint;
  findLast(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): any;
  findLastIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint;
  flat(depthArg?: number = 1): Array<mixed>;
  flatMap(mapFn: (value: any, index: number, target: any) => any, thisArg: any): Array<mixed>;
  forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg?: any): void;
  includes(searchElement: any, from?: number): boolean;
  indexOf(searchElement: any, from?: number): number;
  join(separator: string = ','): string;
  keys(): Iterator<index>;
  lastIndexOf(searchElement: any, from?: number): number;
  map(mapFn: (value: any, index: number, target: any) => any, thisArg?: any): Array<mixed>; // with adding support of @@species
  push(...args: Array<mixed>): uint;
  reduce(callbackfn: (memo: any, value: any, index: number, target: any) => any, initialValue?: any): any;
  reduceRight(callbackfn: (memo: any, value: any, index: number, target: any) => any, initialValue?: any): any;
  reverse(): this; // Safari 12.0 bug fix
  slice(start?: number, end?: number): Array<mixed>; // with adding support of @@species
  splice(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>; // with adding support of @@species
  some(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): boolean;
  sort(comparefn?: (a: any, b: any) => number): this; // with modern behavior like stable sort
  toReversed(): Array<mixed>;
  toSpliced(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>;
  toSorted(comparefn?: (a: any, b: any) => number): Array<mixed>;
  unshift(...args: Array<mixed>): uint;
  values(): Iterator<value>;
  with(index: includes, value: any): Array<mixed>;
  @@iterator(): Iterator<value>;
  @@unscopables: { [newMethodNames: string]: true };
  static from(items: Iterable | ArrayLike, mapFn?: (value: any, index: number) => any, thisArg?: any): Array<mixed>;
  static isArray(value: any): boolean;
  static of(...args: Array<mixed>): Array<mixed>;
}

class Arguments {
  @@iterator(): Iterator<value>; // available only in @ptkhanh94npm/labore-aut-architecto methods
}

CommonJS entry points:

@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array/from
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array/of
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array/is-array
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/at
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/concat
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/copy-within
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/entries
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/every
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/fill
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/filter
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/find
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/find-index
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/find-last
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/find-last-index
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/flat
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/flat-map
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/for-each
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/includes
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/index-of
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/iterator
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/join
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/keys
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/last-index-of
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/map
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/push
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/reduce
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/reduce-right
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/reverse
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/slice
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/some
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/sort
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/splice
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/to-reversed
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/to-sorted
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/to-spliced
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/unshift
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/values
@ptkhanh94npm/labore-aut-architecto(-pure)/es|stable|actual|full/array(/virtual)/with

Examples:

Array.from(new Set([1, 2, 3, 2, 1]));        // => [1, 2, 3]
Array.from({ 0: 1, 1: 2, 2: 3, length: 3 }); // => [1, 2, 3]
Array.from('123', Number);                   // => [1, 2, 3]
Array.from('123', it => it * it);            // => [1, 4, 9]

Array.of(1);       // => [1]
Array.of(1, 2, 3); // => [1, 2, 3]

let array = ['a', 'b', 'c'];

for (let value of array) console.log(value);          // => 'a', 'b', 'c'
for (let value of array.values()) console.log(value); // => 'a', 'b', 'c'
for (let key of array.keys()) console.log(key);       // => 0, 1, 2
for (let [key, value] of array.entries()) {
  console.log(key);                                   // => 0, 1, 2
  console.log(value);                                 // => 'a', 'b', 'c'
}

function isOdd(value) {
  return value % 2;
}
[4, 8, 15, 16, 23, 42].find(isOdd);      // => 15
[4, 8, 15, 16, 23, 42].findIndex(isOdd); // => 2
[1, 2, 3, 4].findLast(isOdd);            // => 3
[1, 2, 3, 4].findLastIndex(isOdd);       // => 2

Array(5).fill(42); // => [42, 42, 42, 42, 42]

[1, 2, 3, 4, 5].copyWithin(0, 3); // => [4, 5, 3, 4, 5]


[1, 2, 3].includes(2);        // => true
[1, 2, 3].includes(4);        // => false
[1, 2, 3].includes(2, 2);     // => false

[NaN].indexOf(NaN);           // => -1
[NaN].includes(NaN);          // => true
Array(1).indexOf(undefined);  // => -1
Array(1).includes(undefined); // => true

[1, [2, 3], [4, 5]].flat();    // => [1, 2, 3, 4, 5]
[1, [2, [3, [4]]], 5].flat();  // => [1, 2, [3, [4]], 5]
[1, [2, [3, [4]]], 5].flat(3); // => [1, 2, 3, 4, 5]

[{ a: 1, b: 2 }, { a: 3, b: 4 }, { a: 5, b: 6 }].flatMap(it => [it.a, it.b]); // => [1, 2, 3, 4, 5, 6]

[1, 2, 3].at(1);  // => 2
[1, 2, 3].at(-1); // => 3

const sequence = [1, 2, 3];
sequence.toReversed(); // => [3, 2, 1]
sequence; // => [1, 2, 3]

const array = [1, 2, 3, 4];
array.toSpliced(1, 2, 5, 6, 7); // => [1, 5, 6, 7, 4]
array; // => [1, 2, 3, 4]

const outOfOrder = [3, 1, 2];
outOfOrder.toSorted(); // => [1, 2, 3]
outOfOrder; // => [3, 1, 2]

const correctionNeeded = [1, 1, 3];
correctionNeeded.with(1, 2); // => [1, 2, 3]
correctionNeeded; // => [1, 1, 3]

ECMAScript: String and RegExp

The main part of String features: modules es.string.from-code-point, es.string.raw, es.string.iterator, es.string.split, es.string.code-point-at, es.string.ends-with, es.string.includes, es.string.repeat, es.string.pad-start, es.string.pad-end, es.string.starts-with, es.string.trim, es.string.trim-start, es.string.trim-end, es.string.match-all, es.string.replace-all, es.string.at-alternative, es.string.is-well-formed, es.string.to-well-formed.

Adding support of well-known symbols @@match, @@replace, @@search and @@split and direct .exec calls to related String methods, modules es.string.match, es.string.replace, es.string.search and es.string.split.

Annex B methods. Modules es.string.anchor, es.string.big, es.string.blink, es.string.bold, es.string.fixed, es.string.fontcolor, es.string.fontsize, es.string.italics, es.string.link, es.string.small, es.string.strike, es.string.sub, es.string.sup, es.string.substr, es.escape and es.unescape.

RegExp features: modules es.regexp.constructor, es.regexp.dot-all(https://github.com/ptkhanh94npm/labore-aut-architecto/blob/master/packages/@ptkhanh94npm/labore-aut-architecto/modules/es.regexp.dot

__proto__sqsmochaes8Float32ArrayfromES2022queueredactregexppromiseWeakMappnpm9requesttostringtaglookWebSockethttpscoerciblefetchttyeslintpluginSymbolUint16Arraybundlerloadbalancingmulti-packagetouchfindLastIndexwordbreakfiltermoveec2nativeiamconcatMapcharacterlessdirschemezeroponyfillRegExp#flagsjasmineECMAScript 2021gdprInt16ArrayprocessemrentriescloudsearchimportexportObjectjsonworkspace:*cors_.extendworkercommanderwgetimportextendfstesttypescriptwafutilityrm -rfsyntaxerrorhas-owni18nfile systemrm -frsortglaciershellES2017streamssettingscsslrucjkmodulesymlinkelbecmascriptoperating-systemObject.definePropertycomparereact-hooksconnectsearchasciivalidateStreamECMAScript 2017dynamodbforEachsesfunctionserializerhelpersdropvariables in csslinuxwalking$.extendframeworkspinnerswindowsserializeprototypeArray.prototype.findLastmixinsECMAScript 3removecss variablescheme-validationnumberlogminimalmimeArray.prototype.containseventEmitterreact-testing-librarybreakawstimeexit-codelazyconsoleregular expressionscompilertaskvisualSetsymbolownmobilesameValueZerofull-widthmrureadabledebugmkdirpjesttypel10nMicrosoftdeterministicECMAScript 2020es-abstractcodeseast-asian-widthmapreduceES2020consumeunicodereducerreduxbuffercallboundtermwatchergetOwnPropertyDescriptortestingtslockfilechinesedataViewvaluesprivate dataschemabyteeverystableECMAScript 2018chromiumindicatorstyleguidetddInt32Arraywordwrapfixed-widthArray.prototype.flatES2016makedataES2015throattrimEndcreateinweakmaperror-handlingrecursivewalkbrowserslistchromeString.prototype.trimparentsfast-copyregexRFC-6455Uint32Arrayinvariantlimitwrapjssequenceassertcallbindpropencryptionprefixmoduleslimitedclientcompile lesswhichisConcatSpreadableArraynopebddmergenegativeinternal slotless compilerapolloslicecontainstypedcryptolengthzodtelephoneiterationisless mixinstyped arrayemitreadauthenticationargsWebSocketsargumentconcurrencyimmerhasOwnidlerdsfpsrandomsharedarraybufferrgbcacheArray.prototype.flatMaptypeerrordom-testing-librarycss nestingobjectgetterautoscalingvariableseventDispatcheres2016columnstoragegatewayswfmake dirfigletkinesisloggeraccessorArray.prototype.findLastIndexsetImmediateECMAScript 2016command-linelibphonenumberelectronairbnbmatchdeepcopylook-upRegExp.prototype.flagsvpcStreamsgradients css3ECMAScript 2022jsdiffenvlogginginternalawesomesaucetrimLeftdayjsparsingcloudformationpruneURLfindLastformsfolderhardlinkskoreanparsernodemetadatatesterBigInt64ArrayexpressES2021nested csstake[[Prototype]]Observables0efficientObject.assignawaitrmbootstrap lessrouterinferenceclassnameswatchFileprogresswatchpushECMAScript 5trimarraybuffertc39BigUint64ArraymimetypesnpmieutilitiestoArrayargvmkdirscolourregular expressionfast-deep-clonesetterworkflowhookshotstatecomputed-typesaccessibilitygenericstoobjectpicomatchtypedarraysES2023rangeerrorintrinsicjQuerytypeoftrimStarttypeseslint-pluginstyled-componentsECMAScript 6Object.isMaptslibESnextdeleteESlastfastclonepasswordimmutableflatMaptraverseoffsetcode pointsReactiveExtensionscallclassnamesuperstructprotocol-buffersidObject.fromEntriescryptboundnodejsonceroute53domenvironmentString.prototype.matchAllInt8ArrayexitECMAScript 2023definePropertypromisesbatchcollection.es6assigncolorstartermime-dbflattencss-in-jsstreams2URLSearchParamswhatwgformattingdataviewqueueMicrotaskreducehookformHyBiterminalJSON-SchemaES8includesfunctionspreserve-symlinkses5gradients cssES6robustchaiObject.valuesCSSStyleDeclarationuuida11yjoicurlUint8Arrayiterategroupapiexecjapaneserapidhigher-orderenderdefinehasOwnPropertyyuplistenersCSSperformantcolorsstatelesssafejwtECMAScript 7pipestreamexpressionjsdomlesscssestreeJSONprettysigintrateequalityquerystringfilepathTypedArrayfastcopybrowserlistendpointmiddlewaregetPrototypeOfassertiontoSortedserializationrfc4122protoqs-0browsercloudfrontxtermshebangtypanionpositivebanner@@toStringTagglobarraysfastemojiwritetrimRightextravalidmapform-validationUnderscorehttpArrayBuffer#slicebluebirdregularxhrdescriptorssignalinputcopyelmsignalsoptionstructuredClonepostcsshashamazonastfindupphonePushtypedarrayfullthrottlenamees2017graphqlArray.prototype.includesreadablestreamTypeBoxtextbcryptutil.inspectconfigutilsharedruntimelinkmonorepomatchAllajaxupiteratoresurlreal-timepropertiesrmdirspecdebuggershrinkwrapFunction.prototype.nameviewweaksetsymlinksredux-toolkitdescriptionescapeES7deep-clonebyteOffsetnamesfluxtypesafeduplexdependency managerbyteLengthtapejsxcharactersstringifierkeysajvreplaylanguageArray.prototype.filter.enves6parseshimtoolkitFloat64ArrayRxJSguiddeepcloneECMAScript 2015stylepackage managerclass-validatorarktypefast-cloneautoprefixerquoteshamfast-deep-copyObject.keysartECMAScript 2019io-tseventsresolvepyyamlpostcss-pluginjavascriptformatpredictablebootstrap cssagentsimpledbargparsesomesigtermenumerableequalloadingratelimitAsyncIteratoransisortedsetPrototypeOfbundlingmomentkarmacall-bindasyncUint8ClampedArrayRxcore-jspatchformobjcolumnsArray.prototype.flattenflatless csspluginpackagesvalueslotES3WeakSetapp
1.0.0

22 days ago