Socket
Socket
Sign inDemoInstall

tui-code-snippet

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 2.1.0

dist/tui-code-snippet.js

30

array/inArray.js

@@ -33,24 +33,24 @@ /* eslint-disable complexity */

function inArray(searchElement, array, startIndex) {
var i;
var length;
startIndex = startIndex || 0;
var i;
var length;
startIndex = startIndex || 0;
if (!isArray(array)) {
return -1;
}
if (!isArray(array)) {
return -1;
}
if (Array.prototype.indexOf) {
return Array.prototype.indexOf.call(array, searchElement, startIndex);
}
if (Array.prototype.indexOf) {
return Array.prototype.indexOf.call(array, searchElement, startIndex);
}
length = array.length;
for (i = startIndex; startIndex >= 0 && i < length; i += 1) {
if (array[i] === searchElement) {
return i;
}
length = array.length;
for (i = startIndex; startIndex >= 0 && i < length; i += 1) {
if (array[i] === searchElement) {
return i;
}
}
return -1;
return -1;
}
module.exports = inArray;

@@ -26,21 +26,21 @@ /**

function range(start, stop, step) {
var arr = [];
var flag;
var arr = [];
var flag;
if (isUndefined(stop)) {
stop = start || 0;
start = 0;
}
if (isUndefined(stop)) {
stop = start || 0;
start = 0;
}
step = step || 1;
flag = step < 0 ? -1 : 1;
stop *= flag;
step = step || 1;
flag = step < 0 ? -1 : 1;
stop *= flag;
for (; start * flag < stop; start += step) {
arr.push(start);
}
for (; start * flag < stop; start += step) {
arr.push(start);
}
return arr;
return arr;
}
module.exports = range;

@@ -24,17 +24,17 @@ /**

function zip() {
var arr2d = Array.prototype.slice.call(arguments);
var result = [];
var arr2d = Array.prototype.slice.call(arguments);
var result = [];
forEach(arr2d, function(arr) {
forEach(arr, function(value, index) {
if (!result[index]) {
result[index] = [];
}
result[index].push(value);
});
forEach(arr2d, function(arr) {
forEach(arr, function(value, index) {
if (!result[index]) {
result[index] = [];
}
result[index].push(value);
});
});
return result;
return result;
}
module.exports = zip;

@@ -34,13 +34,13 @@ /**

var browser = {
chrome: false,
firefox: false,
safari: false,
msie: false,
edge: false,
others: false,
version: 0
chrome: false,
firefox: false,
safari: false,
msie: false,
edge: false,
others: false,
version: 0
};
if (window && window.navigator) {
detectBrowser();
detectBrowser();
}

@@ -53,64 +53,64 @@

function detectBrowser() {
var nav = window.navigator;
var appName = nav.appName.replace(/\s/g, '_');
var userAgent = nav.userAgent;
var nav = window.navigator;
var appName = nav.appName.replace(/\s/g, '_');
var userAgent = nav.userAgent;
var rIE = /MSIE\s([0-9]+[.0-9]*)/;
var rIE11 = /Trident.*rv:11\./;
var rEdge = /Edge\/(\d+)\./;
var versionRegex = {
firefox: /Firefox\/(\d+)\./,
chrome: /Chrome\/(\d+)\./,
safari: /Version\/([\d.]+).*Safari\/(\d+)/
};
var rIE = /MSIE\s([0-9]+[.0-9]*)/;
var rIE11 = /Trident.*rv:11\./;
var rEdge = /Edge\/(\d+)\./;
var versionRegex = {
firefox: /Firefox\/(\d+)\./,
chrome: /Chrome\/(\d+)\./,
safari: /Version\/([\d.]+).*Safari\/(\d+)/
};
var key, tmp;
var key, tmp;
var detector = {
Microsoft_Internet_Explorer: function() { // eslint-disable-line camelcase
var detectedVersion = userAgent.match(rIE);
var detector = {
Microsoft_Internet_Explorer: function() { // eslint-disable-line camelcase
var detectedVersion = userAgent.match(rIE);
if (detectedVersion) { // ie8 ~ ie10
browser.msie = true;
browser.version = parseFloat(detectedVersion[1]);
} else { // no version information
browser.others = true;
}
},
Netscape: function() { // eslint-disable-line complexity
var detected = false;
if (detectedVersion) { // ie8 ~ ie10
browser.msie = true;
browser.version = parseFloat(detectedVersion[1]);
} else { // no version information
browser.others = true;
}
},
Netscape: function() { // eslint-disable-line complexity
var detected = false;
if (rIE11.exec(userAgent)) {
browser.msie = true;
browser.version = 11;
detected = true;
} else if (rEdge.exec(userAgent)) {
browser.edge = true;
browser.version = userAgent.match(rEdge)[1];
detected = true;
} else {
for (key in versionRegex) {
if (versionRegex.hasOwnProperty(key)) {
tmp = userAgent.match(versionRegex[key]);
if (tmp && tmp.length > 1) { // eslint-disable-line max-depth
browser[key] = detected = true;
browser.version = parseFloat(tmp[1] || 0);
break;
}
}
}
if (rIE11.exec(userAgent)) {
browser.msie = true;
browser.version = 11;
detected = true;
} else if (rEdge.exec(userAgent)) {
browser.edge = true;
browser.version = userAgent.match(rEdge)[1];
detected = true;
} else {
for (key in versionRegex) {
if (versionRegex.hasOwnProperty(key)) {
tmp = userAgent.match(versionRegex[key]);
if (tmp && tmp.length > 1) { // eslint-disable-line max-depth
browser[key] = detected = true;
browser.version = parseFloat(tmp[1] || 0);
break;
}
if (!detected) {
browser.others = true;
}
}
}
};
}
if (!detected) {
browser.others = true;
}
}
};
var fn = detector[appName];
var fn = detector[appName];
if (fn) {
detector[appName]();
}
if (fn) {
detector[appName]();
}
}
module.exports = browser;

@@ -21,5 +21,5 @@ /**

* Callback function(iteratee) is invoked with three arguments:
* - The value of the property(or The value of the element)
* - The name of the property(or The index of the element)
* - The object being traversed
* 1) The value of the property(or The value of the element)
* 2) The name of the property(or The index of the element)
* 3) The object being traversed
* @param {Object} obj The object that will be traversed

@@ -46,9 +46,9 @@ * @param {function} iteratee Callback function

function forEach(obj, iteratee, context) {
if (isArray(obj)) {
forEachArray(obj, iteratee, context);
} else {
forEachOwnProperties(obj, iteratee, context);
}
if (isArray(obj)) {
forEachArray(obj, iteratee, context);
} else {
forEachOwnProperties(obj, iteratee, context);
}
}
module.exports = forEach;

@@ -13,5 +13,5 @@ /**

* Callback function(iteratee) is invoked with three arguments:
* - The value of the element
* - The index of the element
* - The array(or Array-like object) being traversed
* 1) The value of the element
* 2) The index of the element
* 3) The array(or Array-like object) being traversed
* @param {Array} arr The array(or Array-like object) that will be traversed

@@ -32,14 +32,14 @@ * @param {function} iteratee Callback function

function forEachArray(arr, iteratee, context) {
var index = 0;
var len = arr.length;
var index = 0;
var len = arr.length;
context = context || null;
context = context || null;
for (; index < len; index += 1) {
if (iteratee.call(context, arr[index], index, arr) === false) {
break;
}
for (; index < len; index += 1) {
if (iteratee.call(context, arr[index], index, arr) === false) {
break;
}
}
}
module.exports = forEachArray;

@@ -12,5 +12,5 @@ /**

* Callback function(iteratee) is invoked with three arguments:
* - The value of the property
* - The name of the property
* - The object being traversed
* 1) The value of the property
* 2) The name of the property
* 3) The object being traversed
* @param {Object} obj The object that will be traversed

@@ -31,15 +31,15 @@ * @param {function} iteratee Callback function

function forEachOwnProperties(obj, iteratee, context) {
var key;
var key;
context = context || null;
context = context || null;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (iteratee.call(context, obj[key], key, obj) === false) {
break;
}
}
for (key in obj) {
if (obj.hasOwnProperty(key)) {
if (iteratee.call(context, obj[key], key, obj) === false) {
break;
}
}
}
}
module.exports = forEachOwnProperties;

@@ -33,11 +33,11 @@ /**

function pluck(arr, property) {
var resultArray = [];
var resultArray = [];
forEach(arr, function(item) {
resultArray.push(item[property]);
});
forEach(arr, function(item) {
resultArray.push(item[property]);
});
return resultArray;
return resultArray;
}
module.exports = pluck;

@@ -32,15 +32,15 @@ /**

function toArray(arrayLike) {
var arr;
try {
arr = Array.prototype.slice.call(arrayLike);
} catch (e) {
arr = [];
forEachArray(arrayLike, function(value) {
arr.push(value);
});
}
var arr;
try {
arr = Array.prototype.slice.call(arrayLike);
} catch (e) {
arr = [];
forEachArray(arrayLike, function(value) {
arr.push(value);
});
}
return arr;
return arr;
}
module.exports = toArray;

@@ -25,12 +25,12 @@ /**

function CustomEvents() {
/**
/**
* @type {HandlerItem[]}
*/
this.events = null;
this.events = null;
/**
/**
* only for checking specific context event was binded
* @type {object[]}
*/
this.contexts = null;
this.contexts = null;
}

@@ -56,3 +56,3 @@

CustomEvents.mixin = function(func) {
extend(func.prototype, CustomEvents.prototype);
extend(func.prototype, CustomEvents.prototype);
};

@@ -68,9 +68,9 @@

CustomEvents.prototype._getHandlerItem = function(handler, context) {
var item = {handler: handler};
var item = {handler: handler};
if (context) {
item.context = context;
}
if (context) {
item.context = context;
}
return item;
return item;
};

@@ -86,21 +86,21 @@

CustomEvents.prototype._safeEvent = function(eventName) {
var events = this.events;
var byName;
var events = this.events;
var byName;
if (!events) {
events = this.events = {};
}
if (!events) {
events = this.events = {};
}
if (eventName) {
byName = events[eventName];
if (eventName) {
byName = events[eventName];
if (!byName) {
byName = [];
events[eventName] = byName;
}
events = byName;
if (!byName) {
byName = [];
events[eventName] = byName;
}
return events;
events = byName;
}
return events;
};

@@ -114,9 +114,9 @@

CustomEvents.prototype._safeContext = function() {
var context = this.contexts;
var context = this.contexts;
if (!context) {
context = this.contexts = [];
}
if (!context) {
context = this.contexts = [];
}
return context;
return context;
};

@@ -131,14 +131,14 @@

CustomEvents.prototype._indexOfContext = function(ctx) {
var context = this._safeContext();
var index = 0;
var context = this._safeContext();
var index = 0;
while (context[index]) {
if (ctx === context[index][0]) {
return index;
}
index += 1;
while (context[index]) {
if (ctx === context[index][0]) {
return index;
}
return -1;
index += 1;
}
return -1;
};

@@ -153,16 +153,16 @@

CustomEvents.prototype._memorizeContext = function(ctx) {
var context, index;
var context, index;
if (!isExisty(ctx)) {
return;
}
if (!isExisty(ctx)) {
return;
}
context = this._safeContext();
index = this._indexOfContext(ctx);
context = this._safeContext();
index = this._indexOfContext(ctx);
if (index > -1) {
context[index][1] += 1;
} else {
context.push([ctx, 1]);
}
if (index > -1) {
context[index][1] += 1;
} else {
context.push([ctx, 1]);
}
};

@@ -176,18 +176,18 @@

CustomEvents.prototype._forgetContext = function(ctx) {
var context, contextIndex;
var context, contextIndex;
if (!isExisty(ctx)) {
return;
}
if (!isExisty(ctx)) {
return;
}
context = this._safeContext();
contextIndex = this._indexOfContext(ctx);
context = this._safeContext();
contextIndex = this._indexOfContext(ctx);
if (contextIndex > -1) {
context[contextIndex][1] -= 1;
if (contextIndex > -1) {
context[contextIndex][1] -= 1;
if (context[contextIndex][1] <= 0) {
context.splice(contextIndex, 1);
}
if (context[contextIndex][1] <= 0) {
context.splice(contextIndex, 1);
}
}
};

@@ -204,5 +204,5 @@

CustomEvents.prototype._bindEvent = function(eventName, handler, context) {
var events = this._safeEvent(eventName);
this._memorizeContext(context);
events.push(this._getHandlerItem(handler, context));
var events = this._safeEvent(eventName);
this._memorizeContext(context);
events.push(this._getHandlerItem(handler, context));
};

@@ -238,17 +238,17 @@

CustomEvents.prototype.on = function(eventName, handler, context) {
var self = this;
var self = this;
if (isString(eventName)) {
// [syntax 1, 2]
eventName = eventName.split(R_EVENTNAME_SPLIT);
forEach(eventName, function(name) {
self._bindEvent(name, handler, context);
});
} else if (isObject(eventName)) {
// [syntax 3, 4]
context = handler;
forEach(eventName, function(func, name) {
self.on(name, func, context);
});
}
if (isString(eventName)) {
// [syntax 1, 2]
eventName = eventName.split(R_EVENTNAME_SPLIT);
forEach(eventName, function(name) {
self._bindEvent(name, handler, context);
});
} else if (isObject(eventName)) {
// [syntax 3, 4]
context = handler;
forEach(eventName, function(func, name) {
self.on(name, func, context);
});
}
};

@@ -264,19 +264,19 @@

CustomEvents.prototype.once = function(eventName, handler, context) {
var self = this;
var self = this;
if (isObject(eventName)) {
context = handler;
forEach(eventName, function(func, name) {
self.once(name, func, context);
});
if (isObject(eventName)) {
context = handler;
forEach(eventName, function(func, name) {
self.once(name, func, context);
});
return;
}
return;
}
function onceHandler() { // eslint-disable-line require-jsdoc
handler.apply(context, arguments);
self.off(eventName, onceHandler, context);
}
function onceHandler() { // eslint-disable-line require-jsdoc
handler.apply(context, arguments);
self.off(eventName, onceHandler, context);
}
this.on(eventName, onceHandler, context);
this.on(eventName, onceHandler, context);
};

@@ -291,16 +291,16 @@

CustomEvents.prototype._spliceMatches = function(arr, predicate) {
var i = 0;
var len;
var i = 0;
var len;
if (!isArray(arr)) {
return;
}
if (!isArray(arr)) {
return;
}
for (len = arr.length; i < len; i += 1) {
if (predicate(arr[i]) === true) {
arr.splice(i, 1);
len -= 1;
i -= 1;
}
for (len = arr.length; i < len; i += 1) {
if (predicate(arr[i]) === true) {
arr.splice(i, 1);
len -= 1;
i -= 1;
}
}
};

@@ -315,13 +315,13 @@

CustomEvents.prototype._matchHandler = function(handler) {
var self = this;
var self = this;
return function(item) {
var needRemove = handler === item.handler;
return function(item) {
var needRemove = handler === item.handler;
if (needRemove) {
self._forgetContext(item.context);
}
if (needRemove) {
self._forgetContext(item.context);
}
return needRemove;
};
return needRemove;
};
};

@@ -336,13 +336,13 @@

CustomEvents.prototype._matchContext = function(context) {
var self = this;
var self = this;
return function(item) {
var needRemove = context === item.context;
return function(item) {
var needRemove = context === item.context;
if (needRemove) {
self._forgetContext(item.context);
}
if (needRemove) {
self._forgetContext(item.context);
}
return needRemove;
};
return needRemove;
};
};

@@ -358,15 +358,15 @@

CustomEvents.prototype._matchHandlerAndContext = function(handler, context) {
var self = this;
var self = this;
return function(item) {
var matchHandler = (handler === item.handler);
var matchContext = (context === item.context);
var needRemove = (matchHandler && matchContext);
return function(item) {
var matchHandler = (handler === item.handler);
var matchContext = (context === item.context);
var needRemove = (matchHandler && matchContext);
if (needRemove) {
self._forgetContext(item.context);
}
if (needRemove) {
self._forgetContext(item.context);
}
return needRemove;
};
return needRemove;
};
};

@@ -381,21 +381,21 @@

CustomEvents.prototype._offByEventName = function(eventName, handler) {
var self = this;
var andByHandler = isFunction(handler);
var matchHandler = self._matchHandler(handler);
var self = this;
var andByHandler = isFunction(handler);
var matchHandler = self._matchHandler(handler);
eventName = eventName.split(R_EVENTNAME_SPLIT);
eventName = eventName.split(R_EVENTNAME_SPLIT);
forEach(eventName, function(name) {
var handlerItems = self._safeEvent(name);
forEach(eventName, function(name) {
var handlerItems = self._safeEvent(name);
if (andByHandler) {
self._spliceMatches(handlerItems, matchHandler);
} else {
forEach(handlerItems, function(item) {
self._forgetContext(item.context);
});
if (andByHandler) {
self._spliceMatches(handlerItems, matchHandler);
} else {
forEach(handlerItems, function(item) {
self._forgetContext(item.context);
});
self.events[name] = [];
}
});
self.events[name] = [];
}
});
};

@@ -409,8 +409,8 @@

CustomEvents.prototype._offByHandler = function(handler) {
var self = this;
var matchHandler = this._matchHandler(handler);
var self = this;
var matchHandler = this._matchHandler(handler);
forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchHandler);
});
forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchHandler);
});
};

@@ -425,26 +425,26 @@

CustomEvents.prototype._offByObject = function(obj, handler) {
var self = this;
var matchFunc;
var self = this;
var matchFunc;
if (this._indexOfContext(obj) < 0) {
forEach(obj, function(func, name) {
self.off(name, func);
});
} else if (isString(handler)) {
matchFunc = this._matchContext(obj);
if (this._indexOfContext(obj) < 0) {
forEach(obj, function(func, name) {
self.off(name, func);
});
} else if (isString(handler)) {
matchFunc = this._matchContext(obj);
self._spliceMatches(this._safeEvent(handler), matchFunc);
} else if (isFunction(handler)) {
matchFunc = this._matchHandlerAndContext(handler, obj);
self._spliceMatches(this._safeEvent(handler), matchFunc);
} else if (isFunction(handler)) {
matchFunc = this._matchHandlerAndContext(handler, obj);
forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchFunc);
});
} else {
matchFunc = this._matchContext(obj);
forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchFunc);
});
} else {
matchFunc = this._matchContext(obj);
forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchFunc);
});
}
forEach(this._safeEvent(), function(handlerItems) {
self._spliceMatches(handlerItems, matchFunc);
});
}
};

@@ -490,16 +490,16 @@

CustomEvents.prototype.off = function(eventName, handler) {
if (isString(eventName)) {
// [syntax 1, 2]
this._offByEventName(eventName, handler);
} else if (!arguments.length) {
// [syntax 8]
this.events = {};
this.contexts = [];
} else if (isFunction(eventName)) {
// [syntax 3]
this._offByHandler(eventName);
} else if (isObject(eventName)) {
// [syntax 4, 5, 6]
this._offByObject(eventName, handler);
}
if (isString(eventName)) {
// [syntax 1, 2]
this._offByEventName(eventName, handler);
} else if (!arguments.length) {
// [syntax 8]
this.events = {};
this.contexts = [];
} else if (isFunction(eventName)) {
// [syntax 3]
this._offByHandler(eventName);
} else if (isObject(eventName)) {
// [syntax 4, 5, 6]
this._offByObject(eventName, handler);
}
};

@@ -512,3 +512,3 @@

CustomEvents.prototype.fire = function(eventName) { // eslint-disable-line
this.invoke.apply(this, arguments);
this.invoke.apply(this, arguments);
};

@@ -545,23 +545,23 @@

CustomEvents.prototype.invoke = function(eventName) {
var events, args, index, item;
var events, args, index, item;
if (!this.hasListener(eventName)) {
return true;
}
if (!this.hasListener(eventName)) {
return true;
}
events = this._safeEvent(eventName);
args = Array.prototype.slice.call(arguments, 1);
index = 0;
events = this._safeEvent(eventName);
args = Array.prototype.slice.call(arguments, 1);
index = 0;
while (events[index]) {
item = events[index];
while (events[index]) {
item = events[index];
if (item.handler.apply(item.context, args) === false) {
return false;
}
index += 1;
if (item.handler.apply(item.context, args) === false) {
return false;
}
return true;
index += 1;
}
return true;
};

@@ -576,3 +576,3 @@

CustomEvents.prototype.hasListener = function(eventName) {
return this.getListenerLength(eventName) > 0;
return this.getListenerLength(eventName) > 0;
};

@@ -586,7 +586,7 @@

CustomEvents.prototype.getListenerLength = function(eventName) {
var events = this._safeEvent(eventName);
var events = this._safeEvent(eventName);
return events.length;
return events.length;
};
module.exports = CustomEvents;

@@ -58,25 +58,25 @@ /**

function defineClass(parent, props) {
var obj;
var obj;
if (!props) {
props = parent;
parent = null;
}
if (!props) {
props = parent;
parent = null;
}
obj = props.init || function() {};
obj = props.init || function() {};
if (parent) {
inherit(obj, parent);
}
if (parent) {
inherit(obj, parent);
}
if (props.hasOwnProperty('static')) {
extend(obj, props['static']);
delete props['static'];
}
if (props.hasOwnProperty('static')) {
extend(obj, props['static']);
delete props['static'];
}
extend(obj.prototype, props);
extend(obj.prototype, props);
return obj;
return obj;
}
module.exports = defineClass;

@@ -18,17 +18,17 @@ /**

function safeEvent(element, type) {
var events = element[EVENT_KEY];
var handlers;
var events = element[EVENT_KEY];
var handlers;
if (!events) {
events = element[EVENT_KEY] = {};
}
if (!events) {
events = element[EVENT_KEY] = {};
}
handlers = events[type];
if (!handlers) {
handlers = events[type] = [];
}
handlers = events[type];
if (!handlers) {
handlers = events[type] = [];
}
return handlers;
return handlers;
}
module.exports = safeEvent;

@@ -34,7 +34,7 @@ /**

function getMouseButton(mouseEvent) {
if (browser.msie && browser.version <= 8) {
return getMouseButtonIE8AndEarlier(mouseEvent);
}
if (browser.msie && browser.version <= 8) {
return getMouseButtonIE8AndEarlier(mouseEvent);
}
return mouseEvent.button;
return mouseEvent.button;
}

@@ -50,15 +50,19 @@

function getMouseButtonIE8AndEarlier(mouseEvent) {
var button = String(mouseEvent.button);
var button = String(mouseEvent.button);
if (inArray(button, primaryButton) > -1) {
return 0;
} else if (inArray(button, secondaryButton) > -1) {
return 2;
} else if (inArray(button, wheelButton) > -1) {
return 1;
}
if (inArray(button, primaryButton) > -1) {
return 0;
}
return null;
if (inArray(button, secondaryButton) > -1) {
return 2;
}
if (inArray(button, wheelButton) > -1) {
return 1;
}
return null;
}
module.exports = getMouseButton;

@@ -22,19 +22,19 @@ /**

function getMousePosition(position, relativeElement) {
var positionArray = isArray(position);
var clientX = positionArray ? position[0] : position.clientX;
var clientY = positionArray ? position[1] : position.clientY;
var rect;
var positionArray = isArray(position);
var clientX = positionArray ? position[0] : position.clientX;
var clientY = positionArray ? position[1] : position.clientY;
var rect;
if (!relativeElement) {
return [clientX, clientY];
}
if (!relativeElement) {
return [clientX, clientY];
}
rect = relativeElement.getBoundingClientRect();
rect = relativeElement.getBoundingClientRect();
return [
clientX - rect.left - relativeElement.clientLeft,
clientY - rect.top - relativeElement.clientTop
];
return [
clientX - rect.left - relativeElement.clientLeft,
clientY - rect.top - relativeElement.clientTop
];
}
module.exports = getMousePosition;

@@ -15,5 +15,5 @@ /**

function getTarget(e) {
return e.target || e.srcElement;
return e.target || e.srcElement;
}
module.exports = getTarget;

@@ -23,13 +23,13 @@ /**

function off(element, types, handler) {
if (isString(types)) {
forEach(types.split(/\s+/g), function(type) {
unbindEvent(element, type, handler);
});
if (isString(types)) {
forEach(types.split(/\s+/g), function(type) {
unbindEvent(element, type, handler);
});
return;
}
return;
}
forEach(types, function(func, type) {
unbindEvent(element, type, func);
});
forEach(types, function(func, type) {
unbindEvent(element, type, func);
});
}

@@ -46,23 +46,23 @@

function unbindEvent(element, type, handler) {
var events = safeEvent(element, type);
var index;
var events = safeEvent(element, type);
var index;
if (!handler) {
forEach(events, function(item) {
removeHandler(element, type, item.wrappedHandler);
});
events.splice(0, events.length);
} else {
forEach(events, function(item, idx) {
if (handler === item.handler) {
removeHandler(element, type, item.wrappedHandler);
index = idx;
if (!handler) {
forEach(events, function(item) {
removeHandler(element, type, item.wrappedHandler);
});
events.splice(0, events.length);
} else {
forEach(events, function(item, idx) {
if (handler === item.handler) {
removeHandler(element, type, item.wrappedHandler);
index = idx;
return false;
}
return false;
}
return true;
});
events.splice(index, 1);
}
return true;
});
events.splice(index, 1);
}
}

@@ -78,9 +78,9 @@

function removeHandler(element, type, handler) {
if ('removeEventListener' in element) {
element.removeEventListener(type, handler);
} else if ('detachEvent' in element) {
element.detachEvent('on' + type, handler);
}
if ('removeEventListener' in element) {
element.removeEventListener(type, handler);
} else if ('detachEvent' in element) {
element.detachEvent('on' + type, handler);
}
}
module.exports = off;

@@ -24,13 +24,13 @@ /**

function on(element, types, handler, context) {
if (isString(types)) {
forEach(types.split(/\s+/g), function(type) {
bindEvent(element, type, handler, context);
});
if (isString(types)) {
forEach(types.split(/\s+/g), function(type) {
bindEvent(element, type, handler, context);
});
return;
}
return;
}
forEach(types, function(func, type) {
bindEvent(element, type, func, handler);
});
forEach(types, function(func, type) {
bindEvent(element, type, func, handler);
});
}

@@ -48,16 +48,16 @@

function bindEvent(element, type, handler, context) {
/**
/**
* Event handler
* @param {Event} e - event object
*/
function eventHandler(e) {
handler.call(context || element, e || window.event);
}
function eventHandler(e) {
handler.call(context || element, e || window.event);
}
if ('addEventListener' in element) {
element.addEventListener(type, eventHandler);
} else if ('attachEvent' in element) {
element.attachEvent('on' + type, eventHandler);
}
memorizeHandler(element, type, handler, eventHandler);
if ('addEventListener' in element) {
element.addEventListener(type, eventHandler);
} else if ('attachEvent' in element) {
element.attachEvent('on' + type, eventHandler);
}
memorizeHandler(element, type, handler, eventHandler);
}

@@ -74,23 +74,23 @@

function memorizeHandler(element, type, handler, wrappedHandler) {
var events = safeEvent(element, type);
var existInEvents = false;
var events = safeEvent(element, type);
var existInEvents = false;
forEach(events, function(obj) {
if (obj.handler === handler) {
existInEvents = true;
forEach(events, function(obj) {
if (obj.handler === handler) {
existInEvents = true;
return false;
}
return false;
}
return true;
return true;
});
if (!existInEvents) {
events.push({
handler: handler,
wrappedHandler: wrappedHandler
});
if (!existInEvents) {
events.push({
handler: handler,
wrappedHandler: wrappedHandler
});
}
}
}
module.exports = on;

@@ -23,21 +23,21 @@ /**

function once(element, types, handler, context) {
/**
/**
* Event handler for one time.
*/
function onceHandler() {
handler.apply(context || element, arguments);
off(element, types, onceHandler, context);
}
function onceHandler() {
handler.apply(context || element, arguments);
off(element, types, onceHandler, context);
}
if (isObject(types)) {
forEachOwnProperties(types, function(fn, type) {
once(element, type, fn, handler);
});
if (isObject(types)) {
forEachOwnProperties(types, function(fn, type) {
once(element, type, fn, handler);
});
return;
}
return;
}
on(element, types, onceHandler, context);
on(element, types, onceHandler, context);
}
module.exports = once;

@@ -14,11 +14,11 @@ /**

function preventDefault(e) {
if (e.preventDefault) {
e.preventDefault();
if (e.preventDefault) {
e.preventDefault();
return;
}
return;
}
e.returnValue = false;
e.returnValue = false;
}
module.exports = preventDefault;

@@ -14,11 +14,11 @@ /**

function stopPropagation(e) {
if (e.stopPropagation) {
e.stopPropagation();
if (e.stopPropagation) {
e.stopPropagation();
return;
}
return;
}
e.cancelBubble = true;
e.cancelBubble = true;
}
module.exports = stopPropagation;

@@ -18,15 +18,15 @@ /**

function setClassName(element, cssClass) {
cssClass = isArray(cssClass) ? cssClass.join(' ') : cssClass;
cssClass = isArray(cssClass) ? cssClass.join(' ') : cssClass;
cssClass = cssClass.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
cssClass = cssClass.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
if (isUndefined(element.className.baseVal)) {
element.className = cssClass;
if (isUndefined(element.className.baseVal)) {
element.className = cssClass;
return;
}
return;
}
element.className.baseVal = cssClass;
element.className.baseVal = cssClass;
}
module.exports = setClassName;

@@ -15,14 +15,14 @@ /**

function testCSSProp(props) {
var style = document.documentElement.style;
var i, len;
var style = document.documentElement.style;
var i, len;
for (i = 0, len = props.length; i < len; i += 1) {
if (props[i] in style) {
return props[i];
}
for (i = 0, len = props.length; i < len; i += 1) {
if (props[i] in style) {
return props[i];
}
}
return false;
return false;
}
module.exports = testCSSProp;

@@ -25,30 +25,30 @@ /**

function addClass(element) {
var cssClass = Array.prototype.slice.call(arguments, 1);
var classList = element.classList;
var newClass = [];
var origin;
var cssClass = Array.prototype.slice.call(arguments, 1);
var classList = element.classList;
var newClass = [];
var origin;
if (classList) {
forEach(cssClass, function(name) {
element.classList.add(name);
});
if (classList) {
forEach(cssClass, function(name) {
element.classList.add(name);
});
return;
}
return;
}
origin = getClass(element);
origin = getClass(element);
if (origin) {
cssClass = [].concat(origin.split(/\s+/), cssClass);
if (origin) {
cssClass = [].concat(origin.split(/\s+/), cssClass);
}
forEach(cssClass, function(cls) {
if (inArray(cls, newClass) < 0) {
newClass.push(cls);
}
});
forEach(cssClass, function(cls) {
if (inArray(cls, newClass) < 0) {
newClass.push(cls);
}
});
setClassName(element, newClass);
setClassName(element, newClass);
}
module.exports = addClass;

@@ -18,19 +18,19 @@ /**

function closest(element, selector) {
var parent = element.parentNode;
var parent = element.parentNode;
if (matches(element, selector)) {
return element;
if (matches(element, selector)) {
return element;
}
while (parent && parent !== document) {
if (matches(parent, selector)) {
return parent;
}
while (parent && parent !== document) {
if (matches(parent, selector)) {
return parent;
}
parent = parent.parentNode;
}
parent = parent.parentNode;
}
return null;
return null;
}
module.exports = closest;

@@ -19,15 +19,15 @@ /**

function css(element, key, value) {
var style = element.style;
var style = element.style;
if (isString(key)) {
style[key] = value;
if (isString(key)) {
style[key] = value;
return;
}
return;
}
forEach(key, function(v, k) {
style[k] = v;
});
forEach(key, function(v, k) {
style[k] = v;
});
}
module.exports = css;

@@ -16,7 +16,7 @@ /**

var userSelectProperty = testCSSProp([
'userSelect',
'WebkitUserSelect',
'OUserSelect',
'MozUserSelect',
'msUserSelect'
'userSelect',
'WebkitUserSelect',
'OUserSelect',
'MozUserSelect',
'msUserSelect'
]);

@@ -30,15 +30,15 @@

function disableTextSelection(el) {
if (!el) {
el = document;
}
if (!el) {
el = document;
}
if (SUPPORT_SELECTSTART) {
on(el, 'selectstart', preventDefault);
} else {
el = (el === document) ? document.documentElement : el;
setData(el, KEY_PREVIOUS_USER_SELECT, el.style[userSelectProperty]);
el.style[userSelectProperty] = 'none';
}
if (SUPPORT_SELECTSTART) {
on(el, 'selectstart', preventDefault);
} else {
el = (el === document) ? document.documentElement : el;
setData(el, KEY_PREVIOUS_USER_SELECT, el.style[userSelectProperty]);
el.style[userSelectProperty] = 'none';
}
}
module.exports = disableTextSelection;

@@ -17,7 +17,7 @@ /**

var userSelectProperty = testCSSProp([
'userSelect',
'WebkitUserSelect',
'OUserSelect',
'MozUserSelect',
'msUserSelect'
'userSelect',
'WebkitUserSelect',
'OUserSelect',
'MozUserSelect',
'msUserSelect'
]);

@@ -31,15 +31,15 @@

function enableTextSelection(el) {
if (!el) {
el = document;
}
if (!el) {
el = document;
}
if (SUPPORT_SELECTSTART) {
off(el, 'selectstart', preventDefault);
} else {
el = (el === document) ? document.documentElement : el;
el.style[userSelectProperty] = getData(el, KEY_PREVIOUS_USER_SELECT) || 'auto';
removeData(el, KEY_PREVIOUS_USER_SELECT);
}
if (SUPPORT_SELECTSTART) {
off(el, 'selectstart', preventDefault);
} else {
el = (el === document) ? document.documentElement : el;
el.style[userSelectProperty] = getData(el, KEY_PREVIOUS_USER_SELECT) || 'auto';
removeData(el, KEY_PREVIOUS_USER_SELECT);
}
}
module.exports = enableTextSelection;

@@ -17,13 +17,13 @@ /**

function getClass(element) {
if (!element || !element.className) {
return '';
}
if (!element || !element.className) {
return '';
}
if (isUndefined(element.className.baseVal)) {
return element.className;
}
if (isUndefined(element.className.baseVal)) {
return element.className;
}
return element.className.baseVal;
return element.className.baseVal;
}
module.exports = getClass;

@@ -8,2 +8,4 @@ /**

var convertToKebabCase = require('./_convertToKebabCase');
/**

@@ -17,13 +19,9 @@ * Get data value from data-attribute

function getData(element, key) {
if (element.dataset) {
return element.dataset[key];
}
if (element.dataset) {
return element.dataset[key];
}
key = key.replace(/([A-Z])/g, function(match) {
return '-' + match.toLowerCase();
});
return element.getAttribute('data-' + key);
return element.getAttribute('data-' + convertToKebabCase(key));
}
module.exports = getData;

@@ -19,13 +19,13 @@ /**

function hasClass(element, cssClass) {
var origin;
var origin;
if (element.classList) {
return element.classList.contains(cssClass);
}
if (element.classList) {
return element.classList.contains(cssClass);
}
origin = getClass(element).split(/\s+/);
origin = getClass(element).split(/\s+/);
return inArray(cssClass, origin) > -1;
return inArray(cssClass, origin) > -1;
}
module.exports = hasClass;

@@ -17,5 +17,5 @@ /**

function(selector) {
var doc = this.document || this.ownerDocument;
var doc = this.document || this.ownerDocument;
return inArray(this, toArray(doc.querySelectorAll(selector))) > -1;
return inArray(this, toArray(doc.querySelectorAll(selector))) > -1;
};

@@ -31,5 +31,5 @@

function matches(element, selector) {
return matchSelector.call(element, selector);
return matchSelector.call(element, selector);
}
module.exports = matches;

@@ -20,25 +20,25 @@ /**

function removeClass(element) {
var cssClass = Array.prototype.slice.call(arguments, 1);
var classList = element.classList;
var origin, newClass;
var cssClass = Array.prototype.slice.call(arguments, 1);
var classList = element.classList;
var origin, newClass;
if (classList) {
forEachArray(cssClass, function(name) {
classList.remove(name);
});
if (classList) {
forEachArray(cssClass, function(name) {
classList.remove(name);
});
return;
return;
}
origin = getClass(element).split(/\s+/);
newClass = [];
forEachArray(origin, function(name) {
if (inArray(name, cssClass) < 0) {
newClass.push(name);
}
});
origin = getClass(element).split(/\s+/);
newClass = [];
forEachArray(origin, function(name) {
if (inArray(name, cssClass) < 0) {
newClass.push(name);
}
});
setClassName(element, newClass);
setClassName(element, newClass);
}
module.exports = removeClass;

@@ -8,2 +8,4 @@ /**

var convertToKebabCase = require('./_convertToKebabCase');
/**

@@ -16,15 +18,11 @@ * Remove data property

function removeData(element, key) {
if (element.dataset) {
delete element.dataset[key];
if (element.dataset) {
delete element.dataset[key];
return;
}
return;
}
key = key.replace(/([A-Z])/g, function(match) {
return '-' + match.toLowerCase();
});
element.removeAttribute('data-' + key);
element.removeAttribute('data-' + convertToKebabCase(key));
}
module.exports = removeData;

@@ -14,7 +14,7 @@ /**

function removeElement(element) {
if (element && element.parentNode) {
element.parentNode.removeChild(element);
}
if (element && element.parentNode) {
element.parentNode.removeChild(element);
}
}
module.exports = removeElement;

@@ -8,2 +8,4 @@ /**

var convertToKebabCase = require('./_convertToKebabCase');
/**

@@ -17,15 +19,11 @@ * Set data attribute to target element

function setData(element, key, value) {
if (element.dataset) {
element.dataset[key] = value;
if (element.dataset) {
element.dataset[key] = value;
return;
}
return;
}
key = key.replace(/([A-Z])/g, function(match) {
return '-' + match.toLowerCase();
});
element.setAttribute('data-' + key, value);
element.setAttribute('data-' + convertToKebabCase(key), value);
}
module.exports = setData;

@@ -20,28 +20,28 @@ /**

function toggleClass(element) {
var cssClass = Array.prototype.slice.call(arguments, 1);
var newClass;
var cssClass = Array.prototype.slice.call(arguments, 1);
var newClass;
if (element.classList) {
forEach(cssClass, function(name) {
element.classList.toggle(name);
});
if (element.classList) {
forEach(cssClass, function(name) {
element.classList.toggle(name);
});
return;
}
return;
}
newClass = getClass(element).split(/\s+/);
newClass = getClass(element).split(/\s+/);
forEach(cssClass, function(name) {
var idx = inArray(name, newClass);
forEach(cssClass, function(name) {
var idx = inArray(name, newClass);
if (idx > -1) {
newClass.splice(idx, 1);
} else {
newClass.push(name);
}
});
if (idx > -1) {
newClass.splice(idx, 1);
} else {
newClass.push(name);
}
});
setClassName(element, newClass);
setClassName(element, newClass);
}
module.exports = toggleClass;

@@ -22,9 +22,9 @@ /**

var isSupportDefinedProperty = (function() {
try {
Object.defineProperty({}, 'x', {});
try {
Object.defineProperty({}, 'x', {});
return true;
} catch (e) {
return false;
}
return true;
} catch (e) {
return false;
}
})();

@@ -70,5 +70,5 @@

function Enum(itemList) {
if (itemList) {
this.set.apply(this, arguments);
}
if (itemList) {
this.set.apply(this, arguments);
}
}

@@ -81,11 +81,11 @@

Enum.prototype.set = function(itemList) {
var self = this;
var self = this;
if (!isArray(itemList)) {
itemList = toArray(arguments);
}
if (!isArray(itemList)) {
itemList = toArray(arguments);
}
forEach(itemList, function itemListIteratee(item) {
self._addItem(item);
});
forEach(itemList, function itemListIteratee(item) {
self._addItem(item);
});
};

@@ -99,14 +99,14 @@

Enum.prototype.getName = function(value) {
var self = this;
var foundedKey;
var self = this;
var foundedKey;
forEach(this, function(itemValue, key) { // eslint-disable-line consistent-return
if (self._isEnumItem(key) && value === itemValue) {
foundedKey = key;
forEach(this, function(itemValue, key) { // eslint-disable-line consistent-return
if (self._isEnumItem(key) && value === itemValue) {
foundedKey = key;
return false;
}
});
return false;
}
});
return foundedKey;
return foundedKey;
};

@@ -120,18 +120,18 @@

Enum.prototype._addItem = function(name) {
var value;
var value;
if (!this.hasOwnProperty(name)) {
value = this._makeEnumValue();
if (!this.hasOwnProperty(name)) {
value = this._makeEnumValue();
if (isSupportDefinedProperty) {
Object.defineProperty(this, name, {
enumerable: true,
configurable: false,
writable: false,
value: value
});
} else {
this[name] = value;
}
if (isSupportDefinedProperty) {
Object.defineProperty(this, name, {
enumerable: true,
configurable: false,
writable: false,
value: value
});
} else {
this[name] = value;
}
}
};

@@ -145,8 +145,8 @@

Enum.prototype._makeEnumValue = function() {
var value;
var value;
value = enumValue;
enumValue += 1;
value = enumValue;
enumValue += 1;
return value;
return value;
};

@@ -161,5 +161,5 @@

Enum.prototype._isEnumItem = function(key) {
return isNumber(this[key]);
return isNumber(this[key]);
};
module.exports = Enum;

@@ -13,81 +13,81 @@ /**

var MONTH_STR = [
'Invalid month', 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December'
'Invalid month', 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October', 'November', 'December'
];
var MONTH_DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var replaceMap = {
M: function(date) {
return Number(date.month);
},
MM: function(date) {
var month = date.month;
M: function(date) {
return Number(date.month);
},
MM: function(date) {
var month = date.month;
return (Number(month) < 10) ? '0' + month : month;
},
MMM: function(date) {
return MONTH_STR[Number(date.month)].substr(0, 3);
},
MMMM: function(date) {
return MONTH_STR[Number(date.month)];
},
D: function(date) {
return Number(date.date);
},
d: function(date) {
return replaceMap.D(date); // eslint-disable-line new-cap
},
DD: function(date) {
var dayInMonth = date.date;
return (Number(month) < 10) ? '0' + month : month;
},
MMM: function(date) {
return MONTH_STR[Number(date.month)].substr(0, 3);
},
MMMM: function(date) {
return MONTH_STR[Number(date.month)];
},
D: function(date) {
return Number(date.date);
},
d: function(date) {
return replaceMap.D(date); // eslint-disable-line new-cap
},
DD: function(date) {
var dayInMonth = date.date;
return (Number(dayInMonth) < 10) ? '0' + dayInMonth : dayInMonth;
},
dd: function(date) {
return replaceMap.DD(date); // eslint-disable-line new-cap
},
YY: function(date) {
return Number(date.year) % 100;
},
yy: function(date) {
return replaceMap.YY(date); // eslint-disable-line new-cap
},
YYYY: function(date) {
var prefix = '20',
year = date.year;
if (year > 69 && year < 100) {
prefix = '19';
}
return (Number(dayInMonth) < 10) ? '0' + dayInMonth : dayInMonth;
},
dd: function(date) {
return replaceMap.DD(date); // eslint-disable-line new-cap
},
YY: function(date) {
return Number(date.year) % 100;
},
yy: function(date) {
return replaceMap.YY(date); // eslint-disable-line new-cap
},
YYYY: function(date) {
var prefix = '20',
year = date.year;
if (year > 69 && year < 100) {
prefix = '19';
}
return (Number(year) < 100) ? prefix + String(year) : year;
},
yyyy: function(date) {
return replaceMap.YYYY(date); // eslint-disable-line new-cap
},
A: function(date) {
return date.meridiem;
},
a: function(date) {
return date.meridiem;
},
hh: function(date) {
var hour = date.hour;
return (Number(year) < 100) ? prefix + String(year) : year;
},
yyyy: function(date) {
return replaceMap.YYYY(date); // eslint-disable-line new-cap
},
A: function(date) {
return date.meridiem;
},
a: function(date) {
return date.meridiem;
},
hh: function(date) {
var hour = date.hour;
return (Number(hour) < 10) ? '0' + hour : hour;
},
HH: function(date) {
return replaceMap.hh(date);
},
h: function(date) {
return String(Number(date.hour));
},
H: function(date) {
return replaceMap.h(date);
},
m: function(date) {
return String(Number(date.minute));
},
mm: function(date) {
var minute = date.minute;
return (Number(hour) < 10) ? '0' + hour : hour;
},
HH: function(date) {
return replaceMap.hh(date);
},
h: function(date) {
return String(Number(date.hour));
},
H: function(date) {
return replaceMap.h(date);
},
m: function(date) {
return String(Number(date.minute));
},
mm: function(date) {
var minute = date.minute;
return (Number(minute) < 10) ? '0' + minute : minute;
}
return (Number(minute) < 10) ? '0' + minute : minute;
}
};

@@ -104,25 +104,25 @@

function isValidDate(year, month, date) { // eslint-disable-line complexity
var isValidYear, isValidMonth, isValid, lastDayInMonth;
var isValidYear, isValidMonth, isValid, lastDayInMonth;
year = Number(year);
month = Number(month);
date = Number(date);
year = Number(year);
month = Number(month);
date = Number(date);
isValidYear = (year > -1 && year < 100) || ((year > 1969) && (year < 2070));
isValidMonth = (month > 0) && (month < 13);
isValidYear = (year > -1 && year < 100) || ((year > 1969) && (year < 2070));
isValidMonth = (month > 0) && (month < 13);
if (!isValidYear || !isValidMonth) {
return false;
}
if (!isValidYear || !isValidMonth) {
return false;
}
lastDayInMonth = MONTH_DAYS[month];
if (month === 2 && year % 4 === 0) {
if (year % 100 !== 0 || year % 400 === 0) {
lastDayInMonth = 29;
}
lastDayInMonth = MONTH_DAYS[month];
if (month === 2 && year % 4 === 0) {
if (year % 100 !== 0 || year % 400 === 0) {
lastDayInMonth = 29;
}
}
isValid = (date > 0) && (date <= lastDayInMonth);
isValid = (date > 0) && (date <= lastDayInMonth);
return isValid;
return isValid;
}

@@ -185,51 +185,51 @@

function formatDate(form, date, option) { // eslint-disable-line complexity
var am = pick(option, 'meridiemSet', 'AM') || 'AM';
var pm = pick(option, 'meridiemSet', 'PM') || 'PM';
var meridiem, nDate, resultStr;
var am = pick(option, 'meridiemSet', 'AM') || 'AM';
var pm = pick(option, 'meridiemSet', 'PM') || 'PM';
var meridiem, nDate, resultStr;
if (isDate(date)) {
nDate = {
year: date.getFullYear(),
month: date.getMonth() + 1,
date: date.getDate(),
hour: date.getHours(),
minute: date.getMinutes()
};
} else {
nDate = {
year: date.year,
month: date.month,
date: date.date,
hour: date.hour,
minute: date.minute
};
}
if (isDate(date)) {
nDate = {
year: date.getFullYear(),
month: date.getMonth() + 1,
date: date.getDate(),
hour: date.getHours(),
minute: date.getMinutes()
};
} else {
nDate = {
year: date.year,
month: date.month,
date: date.date,
hour: date.hour,
minute: date.minute
};
}
if (!isValidDate(nDate.year, nDate.month, nDate.date)) {
return false;
if (!isValidDate(nDate.year, nDate.month, nDate.date)) {
return false;
}
nDate.meridiem = '';
if (/([^\\]|^)[aA]\b/.test(form)) {
meridiem = (nDate.hour > 11) ? pm : am;
if (nDate.hour > 12) { // See the clock system: https://en.wikipedia.org/wiki/12-hour_clock
nDate.hour %= 12;
}
if (nDate.hour === 0) {
nDate.hour = 12;
}
nDate.meridiem = meridiem;
}
nDate.meridiem = '';
if (/([^\\]|^)[aA]\b/.test(form)) {
meridiem = (nDate.hour > 11) ? pm : am;
if (nDate.hour > 12) { // See the clock system: https://en.wikipedia.org/wiki/12-hour_clock
nDate.hour %= 12;
}
if (nDate.hour === 0) {
nDate.hour = 12;
}
nDate.meridiem = meridiem;
resultStr = form.replace(tokens, function(key) {
if (key.indexOf('\\') > -1) { // escape character
return key.replace(/\\/, '');
}
resultStr = form.replace(tokens, function(key) {
if (key.indexOf('\\') > -1) { // escape character
return key.replace(/\\/, '');
}
return replaceMap[key](nDate) || '';
});
return replaceMap[key](nDate) || '';
});
return resultStr;
return resultStr;
}
module.exports = formatDate;

@@ -19,8 +19,8 @@ /**

function createObject(obj) {
function F() {} // eslint-disable-line require-jsdoc
F.prototype = obj;
function F() {} // eslint-disable-line require-jsdoc
F.prototype = obj;
return new F();
return new F();
}
module.exports = createObject;

@@ -44,7 +44,7 @@ /**

function inherit(subType, superType) {
var prototype = createObject(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
var prototype = createObject(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
}
module.exports = inherit;

@@ -20,17 +20,17 @@ /**

function extend(target, objects) { // eslint-disable-line no-unused-vars
var hasOwnProp = Object.prototype.hasOwnProperty;
var source, prop, i, len;
var hasOwnProp = Object.prototype.hasOwnProperty;
var source, prop, i, len;
for (i = 1, len = arguments.length; i < len; i += 1) {
source = arguments[i];
for (prop in source) {
if (hasOwnProp.call(source, prop)) {
target[prop] = source[prop];
}
}
for (i = 1, len = arguments.length; i < len; i += 1) {
source = arguments[i];
for (prop in source) {
if (hasOwnProp.call(source, prop)) {
target[prop] = source[prop];
}
}
}
return target;
return target;
}
module.exports = extend;

@@ -36,19 +36,19 @@ /**

function pick(obj, paths) { // eslint-disable-line no-unused-vars
var args = arguments;
var target = args[0];
var i = 1;
var length = args.length;
var args = arguments;
var target = args[0];
var i = 1;
var length = args.length;
for (; i < length; i += 1) {
if (isUndefined(target) ||
for (; i < length; i += 1) {
if (isUndefined(target) ||
isNull(target)) {
return;
}
target = target[args[i]];
return;
}
return target; // eslint-disable-line consistent-return
target = target[args[i]];
}
return target; // eslint-disable-line consistent-return
}
module.exports = pick;
{
"name": "tui-code-snippet",
"version": "2.0.0",
"version": "2.1.0",
"description": "TOAST UI Utility: CodeSnippet",
"main": "dist/tui-code-snippet.js",
"scripts": {
"eslint": "eslint \"**/*.js\"",
"test": "karma start --no-single-run",
"test:ne": "KARMA_SERVER=ne karma start",
"bundle": "webpack & webpack --production",
"bundle": "webpack & webpack -p",
"doc:serve": "tuidoc --serv",
"doc": "tuidoc"
"doc": "tuidoc",
"note": "tui-note"
},

@@ -43,6 +45,8 @@ "repository": {

"devDependencies": {
"eslint": "^4.1.1",
"eslint-config-tui": "^1.0.1",
"eslint-loader": "^1.8.0",
"istanbul-instrumenter-loader": "^2.0.0",
"@toast-ui/release-notes": "^2.0.0",
"eslint": "^6.7.1",
"eslint-config-prettier": "^6.7.0",
"eslint-config-tui": "^3.0.0",
"eslint-loader": "^3.0.2",
"eslint-plugin-prettier": "^3.1.1",
"jasmine-ajax": "^3.3.1",

@@ -62,6 +66,7 @@ "jasmine-core": "^2.7.0",

"karma-webdriver-launcher": "git+https://github.com/nhn/karma-webdriver-launcher.git#v1.2.0",
"karma-webpack": "^2.0.3",
"safe-umd-webpack-plugin": "0.0.2",
"webpack": "^1.1.0"
"karma-webpack": "^4.0.2",
"prettier": "^1.19.1",
"webpack": "^4.0.0",
"webpack-cli": "^3.3.10"
}
}

@@ -1,17 +0,34 @@

# TOAST UI CodeSnippet
# TOAST UI Tools: Code Snippet
> Group of utility methods to make ease with developing javascript applications.
`tui-code-snippet` is group of utility methods to make ease with developing javascript applications.
[![GitHub release](https://img.shields.io/github/release/nhn/tui.code-snippet.svg)](https://github.com/nhn/tui.code-snippet/releases/latest)
[![npm](https://img.shields.io/npm/v/tui-code-snippet.svg)](https://www.npmjs.com/package/tui-code-snippet)
[![GitHub license](https://img.shields.io/github/license/nhn/tui.code-snippet.svg)](https://github.com/nhn/tui.code-snippet/blob/production/LICENSE)
[![PRs welcome](https://img.shields.io/badge/PRs-welcome-ff69b4.svg)](https://github.com/nhn/tui.code-snippet/labels/help%20wanted)
[![code with hearth by NHN](https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-NHN-ff1414.svg)](https://github.com/nhn)
It includes several features like `class simulation`, `browser detecting`, `type checking` and more.
`tui-code-snippet` supports IE8+ and modern browsers and already has been used for [open source javascript components](http://github.com/nhn/) and many commercial projects in [NHN](http://www.nhn.com) corporation.
## 🚩 Table of Contents
* [Documents](#-documents)
* [Features](#-features)
* [Install](#-install)
* [Usage](#-usage)
* [Bundle](#bundle)
* [Browser Support](#-browser-support)
* [Pull Request Steps](#-pull-request-steps)
* [Contributing](#-contributing)
* [TOAST UI Family](#-toast-ui-family)
* [License](#-license)
## Documents
* [Getting Started](https://github.com/nhn/tui.code-snippet/blob/master/docs/getting-started.md)
## 📙 Documents
* [APIs](https://nhn.github.io/tui.code-snippet/latest/)
* [v2.0 Migration Guide](https://github.com/nhn/tui.code-snippet/blob/master/docs/v2.0-migration-guide.md)
* [v2.0 Migration Guide](https://github.com/nhn/tui.code-snippet/blob/v2.1.0/docs/v2.0-migration-guide.md)
## Features
You can also see the older versions of API page on the [releases page](https://github.com/nhn/tui.code-snippet/releases).
## 🎨 Features
* array

@@ -55,18 +72,27 @@ * Handle arrays

## Installation
Install the latest version using `npm` command:
## 💾 Install
TOAST UI products can be used by using the package manager or downloading the source directly. However, we highly recommend using the package manager.
### Via Package Manager
TOAST UI products are registered in two package managers, [npm](https://www.npmjs.com/).
You can conveniently install it using the commands provided by each package manager.
When using npm, be sure to use it in the environment [Node.js](https://nodejs.org/) is installed.
#### npm
``` sh
$ npm install --save tui-code-snippet
$ npm install --save tui-code-snippet # Latest version
$ npm install --save tui-code-snippet@<version> # Specific version
```
or install the each version:
### Download Source Files
```
$ npm install --save tui-code-snippet@<version>
```
* [Download all sources for each version](https://github.com/nhn/tui.code-snippet/releases)
## Usage
## 🔨 Usage
Import only functions that you need in your code:

@@ -82,6 +108,38 @@

The folder structure can be found [here](https://github.com/nhn/tui.code-snippet/tree/production).
The folder structure can be found [here](https://github.com/nhn/tui.code-snippet/tree/master).
## Browser Support
### Bundle
Since v2.0, it does not provide bundle files. If you need a bundle file, you should make it yourself using the command `npm run bundle`.
```sh
$ git clone https://github.com/nhn/tui.code-snippet.git
$ cd tui.code-snippet
$ npm install
$ npm run bundle
```
After executing `npm run bundle`, the uncompressed(`tui-code-snippet.js`) and minified(`tui-code-snippet.min.js`) files are created in the `dist` folder.
```
tui.code-snippet/
├─ dist
│ ├─ tui-code-snippet.js
│ ├─ tui-code-snippet.min.js
├─ ...
```
The entry file is `index.js`. When you do not modify `index.js`, all methods of tui.code-snippet will be included in the bundle file. To bundle the methods you need, remove other methods in the entry file.
```javascript
// index.js
// for example, you need inArray, forEach and isArray methods only.
require('./array/inArray');
require('./collection/forEach');
require('./type/isArray');
```
## 🌏 Browser Support
| <img src="https://user-images.githubusercontent.com/1215767/34348387-a2e64588-ea4d-11e7-8267-a43365103afe.png" alt="Chrome" width="16px" height="16px" /> Chrome | <img src="https://user-images.githubusercontent.com/1215767/34348590-250b3ca2-ea4f-11e7-9efb-da953359321f.png" alt="IE" width="16px" height="16px" /> Internet Explorer | <img src="https://user-images.githubusercontent.com/1215767/34348380-93e77ae8-ea4d-11e7-8696-9a989ddbbbf5.png" alt="Edge" width="16px" height="16px" /> Edge | <img src="https://user-images.githubusercontent.com/1215767/34348394-a981f892-ea4d-11e7-9156-d128d58386b9.png" alt="Safari" width="16px" height="16px" /> Safari | <img src="https://user-images.githubusercontent.com/1215767/34348383-9e7ed492-ea4d-11e7-910c-03b39d52f496.png" alt="Firefox" width="16px" height="16px" /> Firefox |

@@ -91,4 +149,58 @@ | :---------: | :---------: | :---------: | :---------: | :---------: |

## License
This software is licensed under the [MIT](https://github.com/nhn/tui.code-snippet/blob/master/LICENSE) © [NHN](https://github.com/nhn).
## 🔧 Pull Request Steps
TOAST UI products are open source, so you can create a pull request(PR) after you fix issues.
Run npm scripts and develop yourself with the following process.
### Setup
Fork `master` branch into your personal repository.
Clone it to local computer. Install node modules.
Before starting development, you should check to have any errors.
``` sh
$ git clone https://github.com/{your-personal-repo}/tui.code-snippet.git
$ cd tui.code-snippet
$ npm install
$ npm run test
```
### Develop
Let's start development!
Don't miss adding test cases and then make green rights.
#### Run karma test
``` sh
$ npm run test
```
### Pull Request
Before PR, check to test lastly and then check any errors.
If it has no error, commit and then push it!
For more information on PR's step, please see links of Contributing section.
## 💬 Contributing
* [Code of Conduct](https://github.com/nhn/tui.code-snippet/blob/master/CODE_OF_CONDUCT.md)
* [Contributing guideline](https://github.com/nhn/tui.code-snippet/blob/master/CONTRIBUTING.md)
* [Issue guideline](https://github.com/nhn/tui.code-snippet/blob/master/docs/ISSUE_TEMPLATE.md)
* [Commit convention](https://github.com/nhn/tui.code-snippet/blob/master/docs/COMMIT_MESSAGE_CONVENTION.md)
## 🍞 TOAST UI Family
* [TOAST UI Editor](https://github.com/nhn/tui.editor)
* [TOAST UI Calendar](https://github.com/nhn/tui.calendar)
* [TOAST UI Chart](https://github.com/nhn/tui.chart)
* [TOAST UI Image-Editor](https://github.com/nhn/tui.image-editor)
* [TOAST UI Grid](https://github.com/nhn/tui.grid)
* [TOAST UI Components](https://github.com/nhn)
## 📜 License
This software is licensed under the [MIT License](https://github.com/nhn/tui.code-snippet/blob/master/LICENSE) © [NHN](https://github.com/nhn).

@@ -33,18 +33,18 @@ /**

function imagePing(url, trackingInfo) {
var trackingElement = document.createElement('img');
var queryString = '';
forEachOwnProperties(trackingInfo, function(value, key) {
queryString += '&' + key + '=' + value;
});
queryString = queryString.substring(1);
var trackingElement = document.createElement('img');
var queryString = '';
forEachOwnProperties(trackingInfo, function(value, key) {
queryString += '&' + key + '=' + value;
});
queryString = queryString.substring(1);
trackingElement.src = url + '?' + queryString;
trackingElement.src = url + '?' + queryString;
trackingElement.style.display = 'none';
document.body.appendChild(trackingElement);
document.body.removeChild(trackingElement);
trackingElement.style.display = 'none';
document.body.appendChild(trackingElement);
document.body.removeChild(trackingElement);
return trackingElement;
return trackingElement;
}
module.exports = imagePing;

@@ -20,5 +20,5 @@ /**

function isExpired(date) {
var now = new Date().getTime();
var now = new Date().getTime();
return now - date > ms7days;
return now - date > ms7days;
}

@@ -34,37 +34,37 @@

function sendHostname(appName, trackingId) {
var url = 'https://www.google-analytics.com/collect';
var hostname = location.hostname;
var hitType = 'event';
var eventCategory = 'use';
var applicationKeyForStorage = 'TOAST UI ' + appName + ' for ' + hostname + ': Statistics';
var date = window.localStorage.getItem(applicationKeyForStorage);
var url = 'https://www.google-analytics.com/collect';
var hostname = location.hostname;
var hitType = 'event';
var eventCategory = 'use';
var applicationKeyForStorage = 'TOAST UI ' + appName + ' for ' + hostname + ': Statistics';
var date = window.localStorage.getItem(applicationKeyForStorage);
// skip if the flag is defined and is set to false explicitly
if (!isUndefined(window.tui) && window.tui.usageStatistics === false) {
return;
}
// skip if the flag is defined and is set to false explicitly
if (!isUndefined(window.tui) && window.tui.usageStatistics === false) {
return;
}
// skip if not pass seven days old
if (date && !isExpired(date)) {
return;
}
// skip if not pass seven days old
if (date && !isExpired(date)) {
return;
}
window.localStorage.setItem(applicationKeyForStorage, new Date().getTime());
window.localStorage.setItem(applicationKeyForStorage, new Date().getTime());
setTimeout(function() {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
imagePing(url, {
v: 1,
t: hitType,
tid: trackingId,
cid: hostname,
dp: hostname,
dh: appName,
el: appName,
ec: eventCategory
});
}
}, 1000);
setTimeout(function() {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
imagePing(url, {
v: 1,
t: hitType,
tid: trackingId,
cid: hostname,
dp: hostname,
dh: appName,
el: appName,
ec: eventCategory
});
}
}, 1000);
}
module.exports = sendHostname;

@@ -24,16 +24,16 @@ /**

function decodeHTMLEntity(htmlEntity) {
var entities = {
'&quot;': '"',
'&amp;': '&',
'&lt;': '<',
'&gt;': '>',
'&#39;': '\'',
'&nbsp;': ' '
};
var entities = {
'&quot;': '"',
'&amp;': '&',
'&lt;': '<',
'&gt;': '>',
'&#39;': '\'',
'&nbsp;': ' '
};
return htmlEntity.replace(/&amp;|&lt;|&gt;|&quot;|&#39;|&nbsp;/g, function(m0) {
return entities[m0] ? entities[m0] : m0;
});
return htmlEntity.replace(/&amp;|&lt;|&gt;|&quot;|&#39;|&nbsp;/g, function(m0) {
return entities[m0] ? entities[m0] : m0;
});
}
module.exports = decodeHTMLEntity;

@@ -20,15 +20,15 @@ /**

function encodeHTMLEntity(html) {
var entities = {
'"': 'quot',
'&': 'amp',
'<': 'lt',
'>': 'gt',
'\'': '#39'
};
var entities = {
'"': 'quot',
'&': 'amp',
'<': 'lt',
'>': 'gt',
'\'': '#39'
};
return html.replace(/[<>&"']/g, function(m0) {
return entities[m0] ? '&' + entities[m0] + ';' : m0;
});
return html.replace(/[<>&"']/g, function(m0) {
return entities[m0] ? '&' + entities[m0] + ';' : m0;
});
}
module.exports = encodeHTMLEntity;

@@ -37,19 +37,19 @@ /**

function debounce(fn, delay) {
var timer, args;
var timer, args;
/* istanbul ignore next */
delay = delay || 0;
/* istanbul ignore next */
delay = delay || 0;
function debounced() { // eslint-disable-line require-jsdoc
args = Array.prototype.slice.call(arguments);
function debounced() { // eslint-disable-line require-jsdoc
args = Array.prototype.slice.call(arguments);
window.clearTimeout(timer);
timer = window.setTimeout(function() {
fn.apply(null, args);
}, delay);
}
window.clearTimeout(timer);
timer = window.setTimeout(function() {
fn.apply(null, args);
}, delay);
}
return debounced;
return debounced;
}
module.exports = debounce;

@@ -39,51 +39,51 @@ /**

function throttle(fn, interval) {
var base;
var isLeading = true;
var tick = function(_args) {
fn.apply(null, _args);
base = null;
};
var debounced, stamp, args;
var base;
var isLeading = true;
var tick = function(_args) {
fn.apply(null, _args);
base = null;
};
var debounced, stamp, args;
/* istanbul ignore next */
interval = interval || 0;
/* istanbul ignore next */
interval = interval || 0;
debounced = debounce(tick, interval);
debounced = debounce(tick, interval);
function throttled() { // eslint-disable-line require-jsdoc
args = Array.prototype.slice.call(arguments);
function throttled() { // eslint-disable-line require-jsdoc
args = Array.prototype.slice.call(arguments);
if (isLeading) {
tick(args);
isLeading = false;
if (isLeading) {
tick(args);
isLeading = false;
return;
}
return;
}
stamp = Number(new Date());
stamp = Number(new Date());
base = base || stamp;
base = base || stamp;
// pass array directly because `debounce()`, `tick()` are already use
// `apply()` method to invoke developer's `fn` handler.
//
// also, this `debounced` line invoked every time for implements
// `trailing` features.
debounced(args);
// pass array directly because `debounce()`, `tick()` are already use
// `apply()` method to invoke developer's `fn` handler.
//
// also, this `debounced` line invoked every time for implements
// `trailing` features.
debounced(args);
if ((stamp - base) >= interval) {
tick(args);
}
if ((stamp - base) >= interval) {
tick(args);
}
}
function reset() { // eslint-disable-line require-jsdoc
isLeading = true;
base = null;
}
function reset() { // eslint-disable-line require-jsdoc
isLeading = true;
base = null;
}
throttled.reset = reset;
throttled.reset = reset;
return throttled;
return throttled;
}
module.exports = throttle;

@@ -22,8 +22,8 @@ /**

function isArguments(obj) {
var result = isExisty(obj) &&
var result = isExisty(obj) &&
((Object.prototype.toString.call(obj) === '[object Arguments]') || !!obj.callee);
return result;
return result;
}
module.exports = isArguments;

@@ -16,5 +16,5 @@ /**

function isArray(obj) {
return obj instanceof Array;
return obj instanceof Array;
}
module.exports = isArray;

@@ -17,5 +17,5 @@ /**

function isArraySafe(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
return Object.prototype.toString.call(obj) === '[object Array]';
}
module.exports = isArraySafe;

@@ -16,5 +16,5 @@ /**

function isBoolean(obj) {
return typeof obj === 'boolean' || obj instanceof Boolean;
return typeof obj === 'boolean' || obj instanceof Boolean;
}
module.exports = isBoolean;

@@ -17,5 +17,5 @@ /**

function isBooleanSafe(obj) {
return Object.prototype.toString.call(obj) === '[object Boolean]';
return Object.prototype.toString.call(obj) === '[object Boolean]';
}
module.exports = isBooleanSafe;

@@ -16,5 +16,5 @@ /**

function isDate(obj) {
return obj instanceof Date;
return obj instanceof Date;
}
module.exports = isDate;

@@ -17,5 +17,5 @@ /**

function isDateSafe(obj) {
return Object.prototype.toString.call(obj) === '[object Date]';
return Object.prototype.toString.call(obj) === '[object Date]';
}
module.exports = isDateSafe;

@@ -23,3 +23,3 @@ /* eslint-disable complexity */

function _isEmptyString(obj) {
return isString(obj) && obj === '';
return isString(obj) && obj === '';
}

@@ -34,10 +34,10 @@

function _hasOwnProperty(obj) {
var key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
return true;
}
var key;
for (key in obj) {
if (obj.hasOwnProperty(key)) {
return true;
}
}
return false;
return false;
}

@@ -53,17 +53,17 @@

function isEmpty(obj) {
if (!isExisty(obj) || _isEmptyString(obj)) {
return true;
}
if (!isExisty(obj) || _isEmptyString(obj)) {
return true;
}
if (isArray(obj) || isArguments(obj)) {
return obj.length === 0;
}
if (isArray(obj) || isArguments(obj)) {
return obj.length === 0;
}
if (isObject(obj) && !isFunction(obj)) {
return !_hasOwnProperty(obj);
}
if (isObject(obj) && !isFunction(obj)) {
return !_hasOwnProperty(obj);
}
return true;
return true;
}
module.exports = isEmpty;

@@ -28,5 +28,5 @@ /**

function isExisty(param) {
return !isUndefined(param) && !isNull(param);
return !isUndefined(param) && !isNull(param);
}
module.exports = isExisty;

@@ -18,5 +18,5 @@ /**

function isFalsy(obj) {
return !isTruthy(obj);
return !isTruthy(obj);
}
module.exports = isFalsy;

@@ -16,5 +16,5 @@ /**

function isFunction(obj) {
return obj instanceof Function;
return obj instanceof Function;
}
module.exports = isFunction;

@@ -17,5 +17,5 @@ /**

function isFunctionSafe(obj) {
return Object.prototype.toString.call(obj) === '[object Function]';
return Object.prototype.toString.call(obj) === '[object Function]';
}
module.exports = isFunctionSafe;

@@ -16,9 +16,9 @@ /**

function isHTMLNode(html) {
if (typeof HTMLElement === 'object') {
return (html && (html instanceof HTMLElement || !!html.nodeType));
}
if (typeof HTMLElement === 'object') {
return (html && (html instanceof HTMLElement || !!html.nodeType));
}
return !!(html && html.nodeType);
return !!(html && html.nodeType);
}
module.exports = isHTMLNode;

@@ -16,9 +16,9 @@ /**

function isHTMLTag(html) {
if (typeof HTMLElement === 'object') {
return (html && (html instanceof HTMLElement));
}
if (typeof HTMLElement === 'object') {
return (html && (html instanceof HTMLElement));
}
return !!(html && html.nodeType && html.nodeType === 1);
return !!(html && html.nodeType && html.nodeType === 1);
}
module.exports = isHTMLTag;

@@ -19,5 +19,5 @@ /**

function isNotEmpty(obj) {
return !isEmpty(obj);
return !isEmpty(obj);
}
module.exports = isNotEmpty;

@@ -16,5 +16,5 @@ /**

function isNull(obj) {
return obj === null;
return obj === null;
}
module.exports = isNull;

@@ -16,5 +16,5 @@ /**

function isNumber(obj) {
return typeof obj === 'number' || obj instanceof Number;
return typeof obj === 'number' || obj instanceof Number;
}
module.exports = isNumber;

@@ -17,5 +17,5 @@ /**

function isNumberSafe(obj) {
return Object.prototype.toString.call(obj) === '[object Number]';
return Object.prototype.toString.call(obj) === '[object Number]';
}
module.exports = isNumberSafe;

@@ -16,5 +16,5 @@ /**

function isObject(obj) {
return obj === Object(obj);
return obj === Object(obj);
}
module.exports = isObject;

@@ -16,5 +16,5 @@ /**

function isString(obj) {
return typeof obj === 'string' || obj instanceof String;
return typeof obj === 'string' || obj instanceof String;
}
module.exports = isString;

@@ -17,5 +17,5 @@ /**

function isStringSafe(obj) {
return Object.prototype.toString.call(obj) === '[object String]';
return Object.prototype.toString.call(obj) === '[object String]';
}
module.exports = isStringSafe;

@@ -19,5 +19,5 @@ /**

function isTruthy(obj) {
return isExisty(obj) && obj !== false;
return isExisty(obj) && obj !== false;
}
module.exports = isTruthy;

@@ -16,5 +16,5 @@ /**

function isUndefined(obj) {
return obj === undefined; // eslint-disable-line no-undefined
return obj === undefined; // eslint-disable-line no-undefined
}
module.exports = isUndefined;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc