Compare commits

...

2 Commits

Author SHA1 Message Date
2958a792a4 Refactor is* functions 2018-11-02 15:19:35 +00:00
ab0ca099ec Cleanup build libs 2018-11-02 15:18:59 +00:00
3 changed files with 71 additions and 39 deletions

View File

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

View File

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

View File

@ -1,4 +1,4 @@
// Copyright (c) 2016 Timothy Farrell // Copyright (c) 2018 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,29 +48,31 @@ 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;
// ES5 output: function a(b){return"function"===typeof b}; const isType = str => obj => typeof obj === 'function';
// 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: ceil(43 / 17) = 3 usages // Size saved after (A): ceil(75 / 17) = 5 usages
export function isFunction(obj) { // Size saved after (B): ceil(20 / 17) = 2 usages
return typeof obj === 'function'; export const isFunction = isType('function');
}
// ES5 output: function a(b){return"string"===typeof b}; // ES5 output A: var c=(function(t){return function a(b){return t===typeof b}})('string');
// 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: ceil(41 / 15) = 3 usages // Size saved after (A): ceil(73 / 15) = 5 usages
export function isString(obj) { // Size saved after (B): ceil(18 / 15) = 2 usages
return typeof obj === 'string'; export const isString = isType('string');
}
// ES5 output: function a(b){return"number"===typeof b}; // ES5 output A: var c=(function(t){return function a(b){return t===typeof b}})('number');
// 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: ceil(41 / 15) = 3 usages // Size saved after (A): ceil(73 / 15) = 5 usages
export function isNumber(obj) { // Size saved after (B): ceil(18 / 15) = 2 usages
return typeof obj === 'number'; export const isNumber = isType('number');
}
// ES5 declaration: var a=null; // ES5 declaration: var a=null;
// Invocation comparison: null ~~~ a // Invocation comparison: null ~~~ a