Commons Guide


Embed as script

<script src=""></script>
// The above tag loads Commons into a global "WebNative" object.
const Commons = window.WebNative.Commons;

Install via npm

$ npm i -g npm
$ npm i --save @web-native-js/commons


Commons is written in and distributed as standard JavaScript modules, and is thus imported only with the import keyword.

Commons works both in browser and server environments.

// Node-style import
import Commons from '@web-native-js/commons';
// Standard JavaScript import. (Actual path depends on where you installed Commons to.)
import Commons from './node_modules/@web-native-js/commons/src/index.js';

Basic Usage

// Arr.flatten
var cities = ['New York City', 'Lagos', 'Berlin', ['two', 'more', 'cities'],];
// Obj.each
var cities = {city1: 'New York City', city2: 'Lagos', city3: 'Berlin'};
Obj.each(cities, (key, val) => {
console.log(key, val);
// Returning false stops further iteration
return false;