Refactor is* functions

This commit is contained in:
Timothy Farrell 2018-11-02 15:19:35 +00:00
parent ab0ca099ec
commit 2958a792a4
2 changed files with 19 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{
"name": "trimkit",
"version": "1.0.2",
"version": "1.0.3",
"description": "Javascript and DOM abstractions for smaller minifiable code",
"main": "dist/trimkit.js",
"module": "dist/trimkit.js",

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");
// 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
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)
// Size delta per invocation: 21 - 4 = 17 bytes
// Size saved after: ceil(43 / 17) = 3 usages
export function isFunction(obj) {
return typeof obj === 'function';
}
// Size saved after (A): ceil(75 / 17) = 5 usages
// Size saved after (B): ceil(20 / 17) = 2 usages
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)
// Size delta per invocation: 19 - 4 = 15 bytes
// Size saved after: ceil(41 / 15) = 3 usages
export function isString(obj) {
return typeof obj === 'string';
}
// Size saved after (A): ceil(73 / 15) = 5 usages
// Size saved after (B): ceil(18 / 15) = 2 usages
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)
// Size delta per invocation: 19 - 4 = 15 bytes
// Size saved after: ceil(41 / 15) = 3 usages
export function isNumber(obj) {
return typeof obj === 'number';
}
// Size saved after (A): ceil(73 / 15) = 5 usages
// Size saved after (B): ceil(18 / 15) = 2 usages
export const isNumber = isType('number');
// ES5 declaration: var a=null;
// Invocation comparison: null ~~~ a