Compare commits

..

No commits in common. "2958a792a4f3e1e0a5363b62b8888dca87b5670a" and "7db1ec710a3e6b347f02ea5b4e05374611107e8b" have entirely different histories.

3 changed files with 39 additions and 71 deletions

View File

@ -1,18 +1,22 @@
{ {
"name": "trimkit", "name": "trimkit",
"version": "1.0.3", "version": "1.0.2",
"description": "Javascript and DOM abstractions for smaller minifiable code", "description": "Javascript and DOM abstractions for smaller minifiable code",
"main": "dist/trimkit.js", "main": "lib/index.js",
"module": "dist/trimkit.js", "jsnext:main": "src/index.js",
"files": [ "files": [
"dist/" "dist",
"lib",
"src"
], ],
"scripts": { "scripts": {
"lint": "eslint src", "lint": "eslint src",
"clean": "rimraf dist", "clean": "rimraf dist lib",
"build:umd": "rollup -c rollup.config.js && uglifyjs -m --screw-ie8 -c -o dist/trimkit.min.js dist/trimkit.js", "build:lib": "NODE_ENV=production babel src --presets=\"stage-0,es2015\" --out-dir lib",
"build:umd:zip": "npm run build:umd && gzip -c9 dist/trimkit.min.js > dist/trimkit.min.js.gz && gzip -c9 dist/trimkit.min.mjs > dist/trimkit.min.mjs.gz", "build:umd": "npm run build:lib && NODE_ENV=production rollup -c",
"build": "npm run build:umd:zip && ls -l dist/", "build:umd:min": "npm run build:umd && uglifyjs -m --screw-ie8 -c -o dist/trimkit.min.js dist/trimkit.js",
"build:umd:gzip": "npm run build:umd:min && gzip -c9 dist/trimkit.min.js > dist/trimkit.min.js.gz",
"build": "npm run build:umd:gzip && ls -l dist/",
"prepublish": "npm run clean && npm run build" "prepublish": "npm run clean && npm run build"
}, },
"repository": { "repository": {
@ -36,10 +40,10 @@
"babel-preset-es2015-rollup": "3.0.0", "babel-preset-es2015-rollup": "3.0.0",
"babel-preset-stage-0": "6.16.0", "babel-preset-stage-0": "6.16.0",
"eslint": "3.2.0", "eslint": "3.2.0",
"eslint-plugin-flowtype": "2.29.1",
"rimraf": "2.5.4", "rimraf": "2.5.4",
"rollup": "0.66.6",
"rollup-plugin-babel": "2.7.1", "rollup-plugin-babel": "2.7.1",
"rollup-plugin-esmin": "0.1.3", "rollup-plugin-json": "2.1.0",
"uglify-es": "3.3.9" "uglifyjs": "2.4.10"
} }
} }

View File

@ -1,44 +1,10 @@
import esmin from 'rollup-plugin-esmin'; import json from 'rollup-plugin-json';
import babel from 'rollup-plugin-babel';
import pkg from './package.json';
const config = {
input: 'src/index.js',
output: {
file: pkg.module,
format: 'es'
}
};
export default [ export default {
// trimkit.mjs entry: 'src/index.js',
config,
// trimkit.min.mjs
{
...config,
output: {
...config.output,
file: 'dist/trimkit.min.mjs'
},
plugins: [ esmin({
overrides: {
sourceType: 'module'
}
}) ]
},
// trimkit.js
{
...config,
output: {
format: 'umd', format: 'umd',
file: 'dist/trimkit.js', moduleName: 'Trimkit',
name: 'trimkit' plugins: [ json() ],
}, dest: 'dist/trimkit.js'
plugins: [ };
babel({ sourceType: 'module' })
]
}
]

View File

@ -1,4 +1,4 @@
// Copyright (c) 2018 Timothy Farrell // Copyright (c) 2016 Timothy Farrell
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
@ -48,31 +48,29 @@ export const ObjectKeys = Object.keys;
// Size saved after: ceil(20 / 7) = 3 usages // Size saved after: ceil(20 / 7) = 3 usages
export const DOMDocument = self.document; export const DOMDocument = self.document;
const isType = str => obj => typeof obj === 'function'; // ES5 output: function a(b){return"function"===typeof b};
// ES5 output A: var c=(function(t){return function a(b){return t===typeof b}})('function');
// ES5 output B: var c=a('function');
// Invocation comparison: typeof a==='function' ~~~ a(b) // Invocation comparison: typeof a==='function' ~~~ a(b)
// Size delta per invocation: 21 - 4 = 17 bytes // Size delta per invocation: 21 - 4 = 17 bytes
// Size saved after (A): ceil(75 / 17) = 5 usages // Size saved after: ceil(43 / 17) = 3 usages
// Size saved after (B): ceil(20 / 17) = 2 usages export function isFunction(obj) {
export const isFunction = isType('function'); return typeof obj === 'function';
}
// ES5 output A: var c=(function(t){return function a(b){return t===typeof b}})('string'); // ES5 output: function a(b){return"string"===typeof b};
// ES5 output B: var c=a('string');
// Invocation comparison: typeof a==='string' ~~~ a(b) // Invocation comparison: typeof a==='string' ~~~ a(b)
// Size delta per invocation: 19 - 4 = 15 bytes // Size delta per invocation: 19 - 4 = 15 bytes
// Size saved after (A): ceil(73 / 15) = 5 usages // Size saved after: ceil(41 / 15) = 3 usages
// Size saved after (B): ceil(18 / 15) = 2 usages export function isString(obj) {
export const isString = isType('string'); return typeof obj === 'string';
}
// ES5 output A: var c=(function(t){return function a(b){return t===typeof b}})('number'); // ES5 output: function a(b){return"number"===typeof b};
// ES5 output B: var c=a('number');
// Invocation comparison: typeof a==='number' ~~~ a(b) // Invocation comparison: typeof a==='number' ~~~ a(b)
// Size delta per invocation: 19 - 4 = 15 bytes // Size delta per invocation: 19 - 4 = 15 bytes
// Size saved after (A): ceil(73 / 15) = 5 usages // Size saved after: ceil(41 / 15) = 3 usages
// Size saved after (B): ceil(18 / 15) = 2 usages export function isNumber(obj) {
export const isNumber = isType('number'); return typeof obj === 'number';
}
// ES5 declaration: var a=null; // ES5 declaration: var a=null;
// Invocation comparison: null ~~~ a // Invocation comparison: null ~~~ a