Skip to content

Instantly share code, notes, and snippets.

@ShirtlessKirk
ShirtlessKirk / luhn.js
Last active February 12, 2024 05:09
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,
@ShirtlessKirk
ShirtlessKirk / performance-timing.js
Last active February 12, 2024 00:32
Performance timing polyfill
/**
* performance-timing.js: Polyfill for performance.timing object
* For greatest accuracy, this needs to be run as soon as possible in the page, preferably inline.
* The values returned are necessarily not absolutely accurate, but are close enough for general purposes.
* @author ShirtlessKirk. Copyright (c) 2014.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
(function (window) {
'use strict';
@ShirtlessKirk
ShirtlessKirk / cors.js
Last active August 29, 2015 14:15
CORS (Cross-Origin Resource Sharing) library
/**
* @preserve CORS (Cross-Origin Resource Sharing) library (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
*
* @author ShirtlessKirk copyright 2014
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
/*jslint unparam: true */
/*global define: false, module: false, require: false */
(function (global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / FormData.js
Last active February 12, 2024 00:02
FormData partial polyfill for IE < 10 (<input type="file"> not supported)
/*
* @preserve FormData polyfill for IE < 10. See https://developer.mozilla.org/en/docs/Web/API/FormData and http://caniuse.com/#search=formdata
*
* @author ShirtlessKirk copyright 2015
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
/*global define: false, module: false */
/*jslint bitwise: true, continue: true, nomen: true */
(function formDataModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / dataset.js
Last active February 11, 2024 23:00
Dataset polyfill for IE < 11
/*
* @preserve dataset polyfill for IE < 11. See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset and http://caniuse.com/#search=dataset
*
* @author ShirtlessKirk copyright 2015
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
/*global define: false, module: false */
/*jslint nomen: true, regexp: true, unparam: true */
(function datasetModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / array.js
Last active October 30, 2015 15:18
EcmaScript 5 Array methods polyfill for IE < 9
/**
* Polyfill of ES5 Array methods for IE < 9
*/
/*global define: false, module: false */
/*jslint bitwise: true, forin: true */
(function arrayModule(definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
@ShirtlessKirk
ShirtlessKirk / domtokenlist.js
Last active October 22, 2021 19:17
DOMTokenList polyfill for IE < 9; implements element.classList
/**
* Polyfill of DOMTokenList for IE < 9
* Monkey patch of .add, .remove for IE 10 / 11, Firefox < 26 to support multiple arguments
* Monkey patch of .toggle for IE 10 / 11, Firefox < 24 to support second argument
*/
/*global define: false, module: false */
/*jslint nomen: true */
(function domTokenListModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / event.js
Created October 30, 2015 15:31
Event polyfill for IE < 9 plus DOMContentLoaded, Custom Events (with fix for IE9 - 11)
/**
* Polyfill of .addEventListener, .removeEventListener, DOMContentLoaded for IE < 9
* CustomEvent for IE < 9
* Monkey patch custom event for IE9 - 11
*/
/*global define: false, module: false */
/*jslint bitwise: true, forin: true, sloppy: true */
(function eventModule(global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / document.js
Created October 30, 2015 16:01
DOM4 methods polyfill
/**
* Polyfill of DOM4 methods
*/
/*global define: false, module: false, console: false */
/*jslint bitwise: true, forin: true */
(function documentModule(global, definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
@ShirtlessKirk
ShirtlessKirk / function.js
Created October 30, 2015 16:02
Function.bind polyfill for IE8
/**
* @preserve Function.bind polyfill for IE8
*/
/*global define: false, module: false */
(function functionModule(definition) { // non-exporting module magic dance
'use strict';
var
amd = 'amd',
exports = 'exports'; // keeps the method names for CommonJS / AMD from being compiled to single character variable