From 5f07b856b3f81ceea50877e17e1b06e4865aeaac Mon Sep 17 00:00:00 2001 From: Timothy Farrell Date: Fri, 23 Dec 2016 08:01:24 -0600 Subject: [PATCH] Add in all the code. --- packages/trimkit/.editorconfig | 15 +++ packages/trimkit/.eslintrc | 25 +++++ packages/trimkit/.gitattributes | 1 + packages/trimkit/.gitignore | 1 + packages/trimkit/LICENSE.md | 25 ----- packages/trimkit/README.md | 20 +++- packages/trimkit/dist/trimkit.js | 131 ++++++++++++++++++++++++ packages/trimkit/dist/trimkit.min.js | 48 +++++++++ packages/trimkit/dist/trimkit.min.js.gz | Bin 0 -> 403 bytes packages/trimkit/package.json | 38 +++++++ packages/trimkit/rollup.config.js | 9 ++ packages/trimkit/src/index.js | 105 +++++++++++++++++++ 12 files changed, 391 insertions(+), 27 deletions(-) create mode 100644 packages/trimkit/.editorconfig create mode 100644 packages/trimkit/.eslintrc create mode 100644 packages/trimkit/.gitattributes create mode 100644 packages/trimkit/.gitignore create mode 100644 packages/trimkit/dist/trimkit.js create mode 100644 packages/trimkit/dist/trimkit.min.js create mode 100644 packages/trimkit/dist/trimkit.min.js.gz create mode 100644 packages/trimkit/package.json create mode 100644 packages/trimkit/rollup.config.js create mode 100644 packages/trimkit/src/index.js diff --git a/packages/trimkit/.editorconfig b/packages/trimkit/.editorconfig new file mode 100644 index 0000000..86c8f59 --- /dev/null +++ b/packages/trimkit/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[package.json] +indent_style = space +indent_size = 2 + +[*.md] +trim_trailing_whitespace = false diff --git a/packages/trimkit/.eslintrc b/packages/trimkit/.eslintrc new file mode 100644 index 0000000..5bbdb80 --- /dev/null +++ b/packages/trimkit/.eslintrc @@ -0,0 +1,25 @@ +{ + 'parser': 'babel-eslint', + 'rules': { + 'linebreak-style': [2, 'unix'], + 'semi': [2, 'always'], + 'no-console': 0, + 'no-mixed-spaces-and-tabs': 2, + 'indent': [2, 4], + 'quotes': [2, 'single'], + 'quote-props': [2, 'consistent-as-needed'], + 'no-underscore-dangle': 0, + 'arrow-body-style': 0, + }, + 'env': { + 'es6': false, + 'browser': true + }, + 'presets': [ + 'es2015' + ], + 'plugins': [ + ], + 'whitelist': [ + ] +} diff --git a/packages/trimkit/.gitattributes b/packages/trimkit/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/packages/trimkit/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/packages/trimkit/.gitignore b/packages/trimkit/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/packages/trimkit/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/trimkit/LICENSE.md b/packages/trimkit/LICENSE.md index d7deabe..6816135 100644 --- a/packages/trimkit/LICENSE.md +++ b/packages/trimkit/LICENSE.md @@ -133,28 +133,3 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright {yyyy} {name of copyright owner} - -Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in -compliance with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under the License is -distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -implied. See the License for the specific language governing permissions and limitations under the -License. diff --git a/packages/trimkit/README.md b/packages/trimkit/README.md index 6ee882a..a725277 100644 --- a/packages/trimkit/README.md +++ b/packages/trimkit/README.md @@ -1,6 +1,6 @@ # [TrimKit](https://gitlab.com/explorigin/trimkit) -TrimKit is a set of DOM and API abstactions for the purpose of better Javascript minification. For +TrimKit is a set of DOM and API abstractions for the purpose of better Javascript minification. For example: if (a === undefined) { alert('Oops'); } @@ -17,7 +17,7 @@ If we compare against undefined more than 3 times, we can save bytes by doing th which minifies down to: - function b(a) { return a === void 0; } + function b(a){return a===void 0} if (b(a)){alert('Oops');} @@ -27,6 +27,22 @@ NOTE: TrimKit will help you obsess about Javascript file sizes but that does not smaller files after you apply compression. Because files using have more entropy, small, pre-compression gains can result in after compression losses. YMMV. +# Abstractions + +* `undefined` +* `requestAnimationFrame` +* `Array.isArray` +* `Array.from` +* `Object.keys` +* `document` +* `typeof obj === 'function'` +* `typeof obj === 'string'` +* `typeof obj === 'number'` +* `null` +* `obj === undefined` +* `obj === null` +* `fn.apply(context, params)` + ## Credit Created by [Timothy Farrell](https://github.com/explorigin) diff --git a/packages/trimkit/dist/trimkit.js b/packages/trimkit/dist/trimkit.js new file mode 100644 index 0000000..be23e55 --- /dev/null +++ b/packages/trimkit/dist/trimkit.js @@ -0,0 +1,131 @@ +(function(global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' + ? factory(exports) + : typeof define === 'function' && define.amd + ? define(['exports'], factory) + : factory((global.Trimkit = global.Trimkit || {})); +})(this, function(exports) { + 'use strict'; + + // Copyright (c) 2016 Timothy Farrell + // + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // + // http://www.apache.org/licenses/LICENSE-2.0 + // + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + + // ES5 output: var a=void 0; + // Invocation comparison: undefined ~~~ a + // Size delta per invocation: 9 - 1 = 8 bytes + // Size saved after: ceil(13 / 8) = 2 usages + const Undefined = void 0; + + // ES5 output: var a=requestAnimationFrame; + // Invocation comparison: requestAnimationFrame(b) ~~~ a(b) + // Size delta per invocation: 24 - 4 = 20 bytes + // Size saved after: ceil(28 / 20) = 2 usages + const requestAnimationFrame = self.requestAnimationFrame; + + // ES5 output: var a=Array.isArray; + // Invocation comparison: Array.isArray(b) ~~~ a(b) + // Size delta per invocation: 16 - 4 = 12 bytes + // Size saved after: ceil(20 / 12) = 2 usages + const isArray = Array.isArray; + + // ES5 output: var a=Array.from; + // Invocation comparison: Array.from(b) ~~~ a(b) + // Size delta per invocation: 13 - 4 = 9 bytes + // Size saved after: ceil(17 / 9) = 2 usages + const asArray = Array.from; + + // ES5 output: var a=Object.keys; + // Invocation comparison: Object.Keys(b) ~~~ a(b) + // Size delta per invocation: 14 - 4 = 10 bytes + // Size saved after: ceil(18 / 10) = 2 usages + const ObjectKeys = Object.keys; + + // ES5 output: var a=self.document; + // Invocation comparison: document ~~~ a + // Size delta per invocation: 8 - 1 = 7 bytes + // Size saved after: ceil(20 / 7) = 3 usages + const DOMDocument = self.document; + + // ES5 output: function a(b){return"function"===typeof b}; + // Invocation comparison: typeof a==='function' ~~~ a(b) + // Size delta per invocation: 21 - 4 = 17 bytes + // Size saved after: ceil(43 / 17) = 3 usages + function isFunction(obj) { + return typeof obj === 'function'; + } + + // ES5 output: function a(b){return"string"===typeof b}; + // Invocation comparison: typeof a==='string' ~~~ a(b) + // Size delta per invocation: 19 - 4 = 15 bytes + // Size saved after: ceil(41 / 15) = 3 usages + function isString(obj) { + return typeof obj === 'string'; + } + + // ES5 output: function a(b){return"number"===typeof b}; + // Invocation comparison: typeof a==='number' ~~~ a(b) + // Size delta per invocation: 19 - 4 = 15 bytes + // Size saved after: ceil(41 / 15) = 3 usages + function isNumber(obj) { + return typeof obj === 'number'; + } + + // ES5 declaration: var a=null; + // Invocation comparison: null ~~~ a + // Size delta per invocation: 4 - 1 = 3 bytes + // Size saved after: ceil(11 / 3) = 4 usages + const Null = null; + + // ES5 output: function a(b){return void 0===b}; + // Invocation comparison: b===undefined ~~~ a(b) + // Size delta per invocation: 13 - 4 = 9 bytes + // Size saved after: ceil(33 / 9) = 4 usages + function isUndefined(a) { + return a === undefined; + } + + // ES5 output: function a(b,c){return a.apply(b,c)}; + // Invocation comparison A: a.apply(b,c,d) ~~~ a(b,c,d) + // Invocation comparison B: a.apply(b,c) ~~~ a(b,c) + // Size delta per invocation A: 14 - 8 = 6 bytes + // Size delta per invocation B: 12 - 6 = 6 bytes + // Size saved after: ceil(37 / 6) = 7 usages + function apply(obj, context, params) { + return obj.apply(context, params); + } + + // ES5 output: function a(b){return null===b}; + // Invocation comparison: b===null ~~~ a(b) + // Size delta per invocation: 8 - 4 = 4 bytes + // Size saved after: ceil(31 / 4) = 8 usages + function isNull(a) { + return a === null; + } + + exports.Undefined = Undefined; + exports.requestAnimationFrame = requestAnimationFrame; + exports.isArray = isArray; + exports.asArray = asArray; + exports.ObjectKeys = ObjectKeys; + exports.DOMDocument = DOMDocument; + exports.isFunction = isFunction; + exports.isString = isString; + exports.isNumber = isNumber; + exports.Null = Null; + exports.isUndefined = isUndefined; + exports.apply = apply; + exports.isNull = isNull; + + Object.defineProperty(exports, '__esModule', { value: true }); +}); diff --git a/packages/trimkit/dist/trimkit.min.js b/packages/trimkit/dist/trimkit.min.js new file mode 100644 index 0000000..13f6e99 --- /dev/null +++ b/packages/trimkit/dist/trimkit.min.js @@ -0,0 +1,48 @@ +!(function(e, n) { + 'object' == typeof exports && 'undefined' != typeof module + ? n(exports) + : 'function' == typeof define && define.amd + ? define(['exports'], n) + : n((e.Trimkit = e.Trimkit || {})); +})(this, function(e) { + 'use strict'; + function n(e) { + return 'function' == typeof e; + } + function t(e) { + return 'string' == typeof e; + } + function i(e) { + return 'number' == typeof e; + } + function r(e) { + return void 0 === e; + } + function o(e, n, t) { + return e.apply(n, t); + } + function u(e) { + return null === e; + } + const f = void 0, + s = self.requestAnimationFrame, + c = Array.isArray, + d = Array.from, + y = Object.keys, + l = self.document, + a = null; + (e.Undefined = f), + (e.requestAnimationFrame = s), + (e.isArray = c), + (e.asArray = d), + (e.ObjectKeys = y), + (e.DOMDocument = l), + (e.isFunction = n), + (e.isString = t), + (e.isNumber = i), + (e.Null = a), + (e.isUndefined = r), + (e.apply = o), + (e.isNull = u), + Object.defineProperty(e, '__esModule', { value: !0 }); +}); diff --git a/packages/trimkit/dist/trimkit.min.js.gz b/packages/trimkit/dist/trimkit.min.js.gz new file mode 100644 index 0000000000000000000000000000000000000000..42dce8db05ee33a8aa3f51ba738566b206fba2a6 GIT binary patch literal 403 zcmV;E0c`#siwFotEL~Uv19Wm}ZEI!!Qv16-NhSgD^QKEFn;G zDM<=#Po)IMUbkvw$<-s&B>DHsvJ(5?llCz?vl?kuSy31!MS@hM7b1^8SQr9e+6HA6 z;a?+_(Q!vJt(gnHG4GjHM9QS9I*X61YlMfQ+$fwg@IGXHD zvHHXeJfiFMa!YTC`DU69tGY$4#z-5*+_KAiBl0bU#wszf3Emz+GXi!j;%gGdMlfOP zBdST58eq{`vNDimUGWhNTE$sK~GCHXyjF<@YkX? zYr*Qgo873qMq0pHsl3gY_9rbvUMX4A7WV#WvlF(O@}8%Zg{@H-nnS0!#O(e4%1}|9 z)&cE0K?4dG=OHd#+>1Or4QO5ZwBJ4j4d8xk6Rr!wr?1|8Fh1FNi-Eah*BOxe>adcc x!8wot??9G@i}k1%B^y+xb(WLE0rl4ZQ9>{0oLgMX=I%SC%YSrWt>*Uv006~1yqW+2 literal 0 HcmV?d00001 diff --git a/packages/trimkit/package.json b/packages/trimkit/package.json new file mode 100644 index 0000000..7231af3 --- /dev/null +++ b/packages/trimkit/package.json @@ -0,0 +1,38 @@ +{ + "name": "trimkit", + "version": "1.0.0", + "description": "Javascript and DOM abstractions for smaller minifiable code", + "main": "src/index.js", + "files": ["dist", "src"], + "scripts": { + "lint": "eslint src", + "clean": "rimraf dist", + "build:umd": "NODE_ENV=production rollup -c", + "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" + }, + "repository": { + "type": "git", + "url": "https://gitlab.com/explorigin/trimkit.git" + }, + "keywords": ["javascript"], + "author": "Timothy Farrell (https://github.com/explorigin)", + "license": "Apache 2.0", + "bugs": { + "url": "https://gitlab.com/explorigin/trimkit/issues" + }, + "homepage": "https://gitlab.com/explorigin/trimkit", + "devDependencies": { + "babel-eslint": "^7.1.1", + "eslint": "3.2.0", + "eslint-plugin-flow-vars": "0.5.0", + "eslint-plugin-flowtype": "2.4.0", + "rimraf": "2.5.2", + "rollup-plugin-json": "2.0.1", + "uglifyjs": "2.4.10" + } +} diff --git a/packages/trimkit/rollup.config.js b/packages/trimkit/rollup.config.js new file mode 100644 index 0000000..7ee2c8a --- /dev/null +++ b/packages/trimkit/rollup.config.js @@ -0,0 +1,9 @@ +import json from 'rollup-plugin-json'; + +export default { + entry: 'src/index.js', + format: 'umd', + moduleName: 'Trimkit', + plugins: [json()], + dest: 'dist/trimkit.js' +}; diff --git a/packages/trimkit/src/index.js b/packages/trimkit/src/index.js new file mode 100644 index 0000000..24b88bf --- /dev/null +++ b/packages/trimkit/src/index.js @@ -0,0 +1,105 @@ +// Copyright (c) 2016 Timothy Farrell +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// ES5 output: var a=void 0; +// Invocation comparison: undefined ~~~ a +// Size delta per invocation: 9 - 1 = 8 bytes +// Size saved after: ceil(13 / 8) = 2 usages +export const Undefined = void 0; + +// ES5 output: var a=requestAnimationFrame; +// Invocation comparison: requestAnimationFrame(b) ~~~ a(b) +// Size delta per invocation: 24 - 4 = 20 bytes +// Size saved after: ceil(28 / 20) = 2 usages +export const requestAnimationFrame = self.requestAnimationFrame; + +// ES5 output: var a=Array.isArray; +// Invocation comparison: Array.isArray(b) ~~~ a(b) +// Size delta per invocation: 16 - 4 = 12 bytes +// Size saved after: ceil(20 / 12) = 2 usages +export const isArray = Array.isArray; + +// ES5 output: var a=Array.from; +// Invocation comparison: Array.from(b) ~~~ a(b) +// Size delta per invocation: 13 - 4 = 9 bytes +// Size saved after: ceil(17 / 9) = 2 usages +export const asArray = Array.from; + +// ES5 output: var a=Object.keys; +// Invocation comparison: Object.Keys(b) ~~~ a(b) +// Size delta per invocation: 14 - 4 = 10 bytes +// Size saved after: ceil(18 / 10) = 2 usages +export const ObjectKeys = Object.keys; + +// ES5 output: var a=self.document; +// Invocation comparison: document ~~~ a +// Size delta per invocation: 8 - 1 = 7 bytes +// Size saved after: ceil(20 / 7) = 3 usages +export const DOMDocument = self.document; + +// ES5 output: function a(b){return"function"===typeof b}; +// Invocation comparison: typeof a==='function' ~~~ a(b) +// Size delta per invocation: 21 - 4 = 17 bytes +// Size saved after: ceil(43 / 17) = 3 usages +export function isFunction(obj) { + return typeof obj === 'function'; +} + +// ES5 output: function a(b){return"string"===typeof b}; +// Invocation comparison: typeof a==='string' ~~~ a(b) +// Size delta per invocation: 19 - 4 = 15 bytes +// Size saved after: ceil(41 / 15) = 3 usages +export function isString(obj) { + return typeof obj === 'string'; +} + +// ES5 output: function a(b){return"number"===typeof b}; +// Invocation comparison: typeof a==='number' ~~~ a(b) +// Size delta per invocation: 19 - 4 = 15 bytes +// Size saved after: ceil(41 / 15) = 3 usages +export function isNumber(obj) { + return typeof obj === 'number'; +} + +// ES5 declaration: var a=null; +// Invocation comparison: null ~~~ a +// Size delta per invocation: 4 - 1 = 3 bytes +// Size saved after: ceil(11 / 3) = 4 usages +export const Null = null; + +// ES5 output: function a(b){return void 0===b}; +// Invocation comparison: b===undefined ~~~ a(b) +// Size delta per invocation: 13 - 4 = 9 bytes +// Size saved after: ceil(33 / 9) = 4 usages +export function isUndefined(a) { + return a === undefined; +} + +// ES5 output: function a(b,c){return a.apply(b,c)}; +// Invocation comparison A: a.apply(b,c,d) ~~~ a(b,c,d) +// Invocation comparison B: a.apply(b,c) ~~~ a(b,c) +// Size delta per invocation A: 14 - 8 = 6 bytes +// Size delta per invocation B: 12 - 6 = 6 bytes +// Size saved after: ceil(37 / 6) = 7 usages +export function apply(fn, context, params) { + return fn.apply(context, params); +} + +// ES5 output: function a(b){return null===b}; +// Invocation comparison: b===null ~~~ a(b) +// Size delta per invocation: 8 - 4 = 4 bytes +// Size saved after: ceil(31 / 4) = 8 usages +export function isNull(a) { + return a === null; +}