const _ = { clamp(number, lower, upper) { const lowerClampedValue = Math.max(number, lower); const clampedValue = Math.min(lowerClampedValue, upper); return clampedValue; }, inRange(number, start, end) { if (end === undefined) { end = start; start = 0; } if (start > end) { [start, end] = [end, start]; } const isInRange = start <= number && number < end ? true : false; return isInRange; }, words(string) { return string.split(' ') }, pad(string, length) { if (length <= string.length) { return string; } startPad = Math.floor((length - string.length)/2); endPad = length - startPad - string.length; const paddedString = ' '.repeat(startPad) + string + ' '.repeat(endPad); return paddedString; }, has(object, key) { const hasValue = object[key] !== undefined ? true : false; return hasValue; } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter