Skip to content

Commit

Permalink
polyfill Object.entries for browser builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Jun 25, 2019
1 parent 3a77745 commit f2f6271
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 2 deletions.
16 changes: 16 additions & 0 deletions dist/lindenmayer.browser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
var LSystem = (function () {
'use strict';

{
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array

while (i--) {
resArray[i] = [ownProps[i], obj[ownProps[i]]];
}

return resArray;
};
}
}

// Get a list of productions that have identical initiators,
// Output a single stochastic production. Probability per production
// is defined by amount of input productions (4 => 25% each, 2 => 50% etc.)
Expand Down
2 changes: 1 addition & 1 deletion dist/lindenmayer.browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions docs/examples/lindenmayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
var LSystem = (function () {
'use strict';

{
if (!Object.entries) {
Object.entries = function (obj) {
var ownProps = Object.keys(obj),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array

while (i--) {
resArray[i] = [ownProps[i], obj[ownProps[i]]];
}

return resArray;
};
}
}

// Get a list of productions that have identical initiators,
// Output a single stochastic production. Probability per production
// is defined by amount of input productions (4 => 25% each, 2 => 50% etc.)
Expand Down
1 change: 1 addition & 0 deletions lindenmayer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './polyfills/objectEntries'
import {
transformClassicStochasticProductions,
transformClassicCSProduction,
Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lindenmayer",
"description": "Lindenmayer is a L-System/LSystem library using modern (ES6) JavaScript with focus on a concise syntax. The idea is to have a very powerful but simple base functionality, that can handle most use-cases by simply allowing anonymous functions as productions, which makes it very flexible in comparison to classic L-Systems.",
"version": "1.5.1",
"version": "1.5.2",
"author": "Tom Brewe <info@nylkiway.net>",
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -58,6 +58,7 @@
"npm-run-all": "^4.1.5",
"rollup": "^1.16.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.0.0"
},
"dependencies": {}
Expand Down
13 changes: 13 additions & 0 deletions polyfills/objectEntries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if('__BUILD_FORMAT__' === 'browser') {
if (!Object.entries) {
Object.entries = function( obj ){
var ownProps = Object.keys( obj ),
i = ownProps.length,
resArray = new Array(i); // preallocate the Array
while (i--)
resArray[i] = [ownProps[i], obj[ownProps[i]]];

return resArray;
};
}
}
22 changes: 22 additions & 0 deletions rollup.browser.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import babel from 'rollup-plugin-babel';
// import commonjs from 'rollup-plugin-commonjs';
// import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import replace from 'rollup-plugin-replace';

let minifyEnv = process.env.minify || false;

Expand All @@ -13,11 +16,15 @@ let output = [

const babelConf = {
babelrc: false,
// https://github.com/rollup/rollup-plugin-babel/issues/254#issuecomment-423799147
// exclude: [/\/core-js\//],
presets: [
['@babel/preset-env', {
targets: {
ie: 11
},
// useBuiltIns: 'entry',
// corejs: {version: 3},
modules: false,
loose: true
}]
Expand All @@ -29,6 +36,21 @@ export default {
input: 'lindenmayer.js',
output,
plugins: [
replace({
include: 'polyfills/**',
"__BUILD_FORMAT__": 'browser'
}),

// resolve({
// // only: [ 'core-js' ]
// }),
// commonjs({
// // non-CommonJS modules will be ignored, but you can also
// // specifically include/exclude files
// include: 'node_modules/**', // Default: undefined
// // if false then skip sourceMap generation for CommonJS modules
// sourceMap: false, // Default: true
// }),
babel(babelConf),
minifyEnv ? terser({
ecma: '5',
Expand Down
Loading

0 comments on commit f2f6271

Please sign in to comment.