Comparing version 0.3.5 to 0.4.0
454
jymin.js
@@ -1,11 +0,9 @@ | ||
/** | ||
* _ _ ___ _____ ____ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ |___ / | ___| | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | | |_ \ |___ \ | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| | ___) | ___) | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)____(_)____/ | ||
* |___/ | ||
/** _ _ ___ _ _ ___ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \| || | / _ \ | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | | || |_| | | | | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| |__ _| |_| | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_) |_|(_)___/ | ||
* |___/ | ||
* | ||
* http://lighter.io/jymin | ||
* MIT License | ||
* | ||
@@ -15,21 +13,24 @@ * If you're seeing this in production, you really should minify. | ||
* Source files: | ||
/Users/sam/Workspace/jymin/scripts/ajax.js | ||
/Users/sam/Workspace/jymin/scripts/collections.js | ||
/Users/sam/Workspace/jymin/scripts/cookies.js | ||
/Users/sam/Workspace/jymin/scripts/dates.js | ||
/Users/sam/Workspace/jymin/scripts/dom.js | ||
/Users/sam/Workspace/jymin/scripts/events.js | ||
/Users/sam/Workspace/jymin/scripts/forms.js | ||
/Users/sam/Workspace/jymin/scripts/history.js | ||
/Users/sam/Workspace/jymin/scripts/json.js | ||
/Users/sam/Workspace/jymin/scripts/logging.js | ||
/Users/sam/Workspace/jymin/scripts/numbers.js | ||
/Users/sam/Workspace/jymin/scripts/ready.js | ||
/Users/sam/Workspace/jymin/scripts/strings.js | ||
/Users/sam/Workspace/jymin/scripts/types.js | ||
/Users/sam/Workspace/jymin/scripts/url.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/ajax.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/arrays.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/cookies.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/dates.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/dom.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/emitter.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/events.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/forms.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/history.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/json.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/logging.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/numbers.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/objects.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/storage.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/strings.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/types.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/url.js | ||
* https://github.com/lighterio/jymin/blob/master/scripts/use.js | ||
*/ | ||
this.jymin = {version: '0.3.5'}; | ||
var version = '0.4.0'; | ||
@@ -93,3 +94,3 @@ /** | ||
onFailure || responseFailureHandler; | ||
var data = parse(request.responseText); | ||
var data = parse(request.responseText) || {}; | ||
data._STATUS = status; | ||
@@ -163,66 +164,2 @@ data._REQUEST = request; | ||
/** | ||
* Iterate over an object's keys, and call a function on each key value pair. | ||
*/ | ||
var forIn = function ( | ||
object, // Object*: The object to iterate over. | ||
callback // Function*: The function to call on each pair. `callback(value, key, object)` | ||
) { | ||
if (object) { | ||
for (var key in object) { | ||
var result = callback(key, object[key], object); | ||
if (result === false) { | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Iterate over an object's keys, and call a function on each (value, key) pair. | ||
*/ | ||
var forOf = function ( | ||
object, // Object*: The object to iterate over. | ||
callback // Function*: The function to call on each pair. `callback(value, key, object)` | ||
) { | ||
if (object) { | ||
for (var key in object) { | ||
var result = callback(object[key], key, object); | ||
if (result === false) { | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Decorate an object with properties from another object. If the properties | ||
*/ | ||
var decorateObject = function ( | ||
object, // Object: The object to decorate. | ||
decorations // Object: The object to iterate over. | ||
) { | ||
if (object && decorations) { | ||
forIn(decorations, function (key, value) { | ||
object[key] = value; | ||
}); | ||
} | ||
return object; | ||
}; | ||
/** | ||
* Ensure that a property exists by creating it if it doesn't. | ||
*/ | ||
var ensureProperty = function ( | ||
object, | ||
property, | ||
defaultValue | ||
) { | ||
var value = object[property]; | ||
if (!value) { | ||
value = object[property] = defaultValue; | ||
} | ||
return value; | ||
}; | ||
/** | ||
* Get the length of an array. | ||
@@ -381,3 +318,3 @@ * @return number: Array length. | ||
*/ | ||
var deleteCookie = function deleteCookie( | ||
var deleteCookie = function ( | ||
name // string: Name of the cookie. | ||
@@ -435,3 +372,3 @@ ) { | ||
var minutes = date.getMinutes(); | ||
minutes = minutes > 10 ? minutes : "0" + minutes; | ||
minutes = minutes > 9 ? minutes : "0" + minutes; | ||
h > 12 ? (isAm = false, h -= 12) : (h === 0 ? h = 12 : 0); | ||
@@ -451,3 +388,3 @@ return m + " " + date.getDate() + ", " + date.getFullYear() + " at " + h + | ||
var minutes = date.getMinutes(); | ||
minutes = minutes > 10 ? minutes : "0" + minutes; | ||
minutes = minutes > 9 ? minutes : "0" + minutes; | ||
h > 12 ? (isAm = false, h -= 12) : (h === 0 ? h = 12 : 0); | ||
@@ -544,5 +481,12 @@ return m + "/" + date.getDate() + "/" + date.getFullYear() % 100 + " " + h + | ||
*/ | ||
var createElement = function ( | ||
tagIdentifier | ||
) { | ||
var createTag = function (tagName) { | ||
var isSvg = /^(svg|g|path|circle|line)$/.test(tagName); | ||
var uri = 'http://www.w3.org/' + (isSvg ? '2000/svg' : '1999/xhtml'); | ||
return document.createElementNS(uri, tagName); | ||
}; | ||
/** | ||
* Create a DOM element. | ||
*/ | ||
var createElement = function (tagIdentifier) { | ||
if (!isString(tagIdentifier)) { | ||
@@ -559,3 +503,3 @@ return tagIdentifier; | ||
var attributes = tagAndAttributes[1]; | ||
var cachedElement = createElement[tagName] || (createElement[tagName] = document.createElement(tagName)); | ||
var cachedElement = createTag[tagName] || (createTag[tagName] = createTag(tagName)); | ||
var element = cachedElement.cloneNode(true); | ||
@@ -921,3 +865,3 @@ if (id) { | ||
element = getElement(element); | ||
if (element) { | ||
if (element && !hasClass(element, className)) { | ||
element.className += ' ' + className; | ||
@@ -1063,2 +1007,75 @@ } | ||
}; | ||
/** | ||
* An Emitter is an EventEmitter-style object. | ||
*/ | ||
var Emitter = function () { | ||
// Lazily apply the prototype so that Emitter can minify out if not used. | ||
Emitter.prototype = EmitterPrototype; | ||
}; | ||
/** | ||
* Expose Emitter methods which can be applied lazily. | ||
*/ | ||
var EmitterPrototype = { | ||
_ON: function (event, fn) { | ||
var self = this; | ||
var events = self._EVENTS || (self._EVENTS = {}); | ||
var listeners = events[event] || (events[event] = []); | ||
listeners.push(fn); | ||
return self; | ||
}, | ||
_ONCE: function (event, fn) { | ||
var self = this; | ||
function f() { | ||
fn.apply(self, arguments); | ||
self._REMOVE_LISTENER(event, f); | ||
} | ||
self._ON(event, f); | ||
return self; | ||
}, | ||
_EMIT: function (event) { | ||
var self = this; | ||
var listeners = self._LISTENERS(event); | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
forEach(listeners, function (listener) { | ||
listener.apply(self, args); | ||
}); | ||
return self; | ||
}, | ||
_LISTENERS: function (event) { | ||
var self = this; | ||
var events = self._EVENTS || 0; | ||
var listeners = events[event] || []; | ||
return listeners; | ||
}, | ||
_REMOVE_LISTENER: function (event, fn) { | ||
var self = this; | ||
var listeners = self._LISTENERS(event); | ||
var i = listeners.indexOf(fn); | ||
if (i > -1) { | ||
listeners.splice(i, 1); | ||
} | ||
return self; | ||
}, | ||
_REMOVE_ALL_LISTENERS: function (event, fn) { | ||
var self = this; | ||
var events = self._EVENTS || {}; | ||
if (event) { | ||
delete events[event]; | ||
} | ||
else { | ||
for (event in events) { | ||
delete events[event]; | ||
} | ||
} | ||
return self; | ||
} | ||
}; | ||
var CLICK = 'click'; | ||
@@ -1545,2 +1562,5 @@ var MOUSEDOWN = 'mousedown'; | ||
}; | ||
// JavaScript reserved words. | ||
var reservedWordPattern = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/; | ||
/** | ||
@@ -1550,23 +1570,20 @@ * Create JSON that doesn't necessarily have to be strict. | ||
var stringify = function (data, strict, stack) { | ||
var reserved = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/; | ||
if (data === null) { | ||
data = 'null'; | ||
if (isString(data)) { | ||
data = '"' + data.replace(/\n\r"/g, function (c) { | ||
return c == '\n' ? '\\n' : c == '\r' ? '\\r' : '\\"'; | ||
}) + '"'; | ||
} | ||
else if (isFunction(data)) { | ||
data = data.toString(); | ||
if (strict) { | ||
data = '-1'; | ||
data = stringify(data); | ||
} | ||
else { | ||
data = ensureString(data).replace(/^function \(/, 'function('); | ||
} | ||
} | ||
else if (isDate(data)) { | ||
data = 'new Date(' + getTime(data) + ')'; | ||
if (strict) { | ||
data = '"' + getIsoDate() + '"'; | ||
data = stringify(data); | ||
} | ||
else { | ||
data = 'new Date(' + getTime(data) + ')'; | ||
} | ||
} | ||
else if (isObject(data)) { | ||
else if (data && isObject(data)) { | ||
stack = stack || []; | ||
@@ -1596,3 +1613,3 @@ var isCircular = false; | ||
forIn(data, function (key, value) { | ||
if (strict || reserved.test(key)) { | ||
if (strict || reservedWordPattern.test(key) || /(^\d|[^\w$])/.test(key)) { | ||
key = '"' + key + '"'; | ||
@@ -1606,5 +1623,2 @@ } | ||
} | ||
else if (isString(data) && stack) { | ||
data = '"' + data.replace(/"/g, '\\"') + '"'; | ||
} | ||
else { | ||
@@ -1617,18 +1631,15 @@ data = '' + data; | ||
/** | ||
* Parse JavaScript. | ||
* Parse JavaScript and return a value. | ||
*/ | ||
var parse = function (text) { | ||
if (text[0] == '{' || text[0] == '[') { | ||
try { | ||
var evil = window.eval; // jshint ignore:line | ||
evil('eval.J=' + text); | ||
text = evil.J; | ||
} | ||
catch (e) { | ||
//+env:debug | ||
error('[Jymin] Could not parse JS: "' + text + '"'); | ||
//-env:debug | ||
} | ||
var parse = function (value) { | ||
try { | ||
var evil = window.eval; // jshint ignore:line | ||
evil('eval.J=' + value); | ||
return evil.J; | ||
} | ||
return text; | ||
catch (e) { | ||
//+env:debug | ||
error('[Jymin] Could not parse JS: ' + value); | ||
//-env:debug | ||
} | ||
}; | ||
@@ -1640,5 +1651,45 @@ | ||
var execute = function (text) { | ||
parse('{};' + text); | ||
parse('0;' + text); | ||
}; | ||
/** | ||
* Parse a value and return a boolean no matter what. | ||
*/ | ||
var parseBoolean = function (value, alternative) { | ||
value = parse(value); | ||
return isBoolean(value) ? value : (alternative || false); | ||
}; | ||
/** | ||
* Parse a value and return a number no matter what. | ||
*/ | ||
var parseNumber = function (value, alternative) { | ||
value = parse(value); | ||
return isNumber(value) ? value : (alternative || 0); | ||
}; | ||
/** | ||
* Parse a value and return a string no matter what. | ||
*/ | ||
var parseString = function (value, alternative) { | ||
value = parse(value); | ||
return isString(value) ? value : (alternative || ''); | ||
}; | ||
/** | ||
* Parse a value and return an object no matter what. | ||
*/ | ||
var parseObject = function (value, alternative) { | ||
value = parse(value); | ||
return isObject(value) ? value : (alternative || {}); | ||
}; | ||
/** | ||
* Parse a value and return a number no matter what. | ||
*/ | ||
var parseArray = function (value, alternative) { | ||
value = parse(value); | ||
return isObject(value) ? value : (alternative || []); | ||
}; | ||
/** | ||
* Log values to the console, if it's available. | ||
@@ -1713,42 +1764,82 @@ */ | ||
/** | ||
* Execute a callback when the page loads. | ||
* Iterate over an object's keys, and call a function on each key value pair. | ||
*/ | ||
var onReady = window._ON_READY = function ( | ||
callbackOrElement | ||
var forIn = function ( | ||
object, // Object*: The object to iterate over. | ||
callback // Function*: The function to call on each pair. `callback(value, key, object)` | ||
) { | ||
// If there's no queue, create it as a property of this function. | ||
var queue = ensureProperty(onReady, '_QUEUE', []); | ||
if (object) { | ||
for (var key in object) { | ||
var result = callback(key, object[key], object); | ||
if (result === false) { | ||
break; | ||
} | ||
} | ||
} | ||
}; | ||
// If there's a callback, push it into the queue. | ||
if (typeof callbackOrElement == 'function') { | ||
// The 1st callback makes schedules onReady, if not waiting for scripts. | ||
if (!getLength(queue)) { | ||
// In production, there should be a single script, therefore no wait. | ||
var waitingForScripts = false; | ||
// In development, individual scripts might still be loading. | ||
//+env:dev,debug | ||
waitingForScripts = window._WAITING_FOR_SCRIPTS; | ||
//-env:dev,debug | ||
if (!waitingForScripts) { | ||
// At the next tick, we've excuted this whole script. | ||
addTimeout(onReady, onReady, 1); | ||
/** | ||
* Iterate over an object's keys, and call a function on each (value, key) pair. | ||
*/ | ||
var forOf = function ( | ||
object, // Object*: The object to iterate over. | ||
callback // Function*: The function to call on each pair. `callback(value, key, object)` | ||
) { | ||
if (object) { | ||
for (var key in object) { | ||
var result = callback(object[key], key, object); | ||
if (result === false) { | ||
break; | ||
} | ||
} | ||
// Put an item in the queue and wait. | ||
push(queue, callbackOrElement); | ||
} | ||
}; | ||
// If there's no callback, onReady has been triggered, so run callbacks. | ||
else { | ||
forEach(queue, function (callback) { | ||
callback(callbackOrElement || document); | ||
/** | ||
* Decorate an object with properties from another object. If the properties | ||
*/ | ||
var decorateObject = function ( | ||
object, // Object: The object to decorate. | ||
decorations // Object: The object to iterate over. | ||
) { | ||
if (object && decorations) { | ||
forIn(decorations, function (key, value) { | ||
object[key] = value; | ||
}); | ||
} | ||
return object; | ||
}; | ||
/** | ||
* Ensure that a property exists by creating it if it doesn't. | ||
*/ | ||
var ensureProperty = function ( | ||
object, | ||
property, | ||
defaultValue | ||
) { | ||
var value = object[property]; | ||
if (!value) { | ||
value = object[property] = defaultValue; | ||
} | ||
return value; | ||
}; | ||
var storage = window.localStorage; | ||
/** | ||
* Fetch an item from local storage. | ||
*/ | ||
var fetch = function (key) { | ||
return storage ? parse(storage.getItem(key)) : 0; | ||
}; | ||
/** | ||
* Store an item in local storage. | ||
*/ | ||
var store = function (key, value) { | ||
if (storage) { | ||
storage.setItem(key, stringify(value)); | ||
} | ||
}; | ||
/** | ||
* Ensure a value is a string. | ||
@@ -2042,1 +2133,50 @@ */ | ||
}; | ||
/** | ||
* Map of used module functions. | ||
*/ | ||
var useFns = {}; | ||
/** | ||
* Map of used function's return values. | ||
*/ | ||
var useMap = {}; | ||
/** | ||
* Depth of dependency uses. | ||
*/ | ||
var useDepth = 0; | ||
/** | ||
* Use a module, or use a previously used module. | ||
*/ | ||
var use = function (name, fn) { | ||
// If there's a function, map it, but don't execute now. | ||
if (fn) { | ||
useFns[name] = useFns[name] || fn; | ||
} | ||
// Otherwise, get a previously used module. | ||
else { | ||
fn = useFns[name]; | ||
// If the function exists, run it and cache the return value. | ||
if (fn && (fn !== 1)) { | ||
// Prevent stack overflow. | ||
if (useDepth > 99) { | ||
//+env:dev | ||
throw new Error('[Jymin] Circular "use" detected.'); | ||
//-env:dev | ||
return 0; | ||
} | ||
useDepth++; | ||
useMap[name] = fn(); | ||
useDepth--; | ||
useFns[name] = 1; | ||
} | ||
// Return a module's return value. | ||
return useMap[name]; | ||
} | ||
}; |
{ | ||
"name": "jymin", | ||
"description": "Minifier-friendly JavaScript for the real-time world", | ||
"version": "0.4.0", | ||
"description": "Minifier-friendly JavaScript built for speed and usefulness", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"exam": "^0.2.1", | ||
"coveralls": "2.10.0", | ||
"chug": "^0.3.0", | ||
"figlet": "1.0.9" | ||
}, | ||
"keywords": [ | ||
@@ -15,30 +23,9 @@ "jymin", | ||
], | ||
"version": "0.3.5", | ||
"main": "chug/chug.js", | ||
"homepage": "http://lighter.io/jymin", | ||
"repository": "http://github.com/lighterio/jymin.git", | ||
"bugs": { | ||
"url": "http://github.com/lighterio/jymin/issues" | ||
"main": "jymin.node.js", | ||
"engines": { | ||
"node": ">=0.2.6" | ||
}, | ||
"author": { | ||
"name": "Sam Eubank", | ||
"email": "sameubank@gmail.com" | ||
}, | ||
"contributors": { | ||
"name": "Sam Eubank", | ||
"email": "sameubank@gmail.com" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/lighterio/jymin/blob/master/MIT-LICENSE.md" | ||
} | ||
], | ||
"engines": [ | ||
"node >= 0.2.6" | ||
], | ||
"scripts": { | ||
"build": "node chug/chug", | ||
"build": "node .chug.js", | ||
"test": "./node_modules/exam/exam.js", | ||
"retest": "./node_modules/exam/exam.js --watch", | ||
"cover": "istanbul cover ./node_modules/exam/exam.js", | ||
@@ -48,10 +35,10 @@ "report": "open coverage/lcov-report/index.html", | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"zeriousify": "0.1.9", | ||
"exam": "0.0.5", | ||
"coveralls": "2.10.0", | ||
"chug": "0.1.30", | ||
"figlet": "1.0.9" | ||
} | ||
"repository": "https://github.com/lighterio/jymin.git", | ||
"bugs": "https://github.com/lighterio/jymin/issues", | ||
"homepage": "http://lighter.io/jymin", | ||
"author": "Sam Eubank <sameubank@gmail.com>", | ||
"contributors": [ | ||
"Sam Eubank <sameubank@gmail.com>" | ||
], | ||
"license": "MIT" | ||
} |
260
README.md
@@ -1,19 +0,255 @@ | ||
# Jymin - Tiny JavaScript for a Big World | ||
# <a href="http://lighter.io/jymin" style="font-size:40px;text-decoration:none;color:#000"><img src="https://cdn.rawgit.com/lighterio/lighter.io/master/public/jymin.svg" style="width:90px;height:90px"> Jymin</a> | ||
[![NPM Version](https://img.shields.io/npm/v/jymin.svg)](https://npmjs.org/package/jymin) | ||
[![Downloads](https://img.shields.io/npm/dm/jymin.svg)](https://npmjs.org/package/jymin) | ||
[![Build Status](https://img.shields.io/travis/lighterio/jymin.svg)](https://travis-ci.org/lighterio/jymin) | ||
[![Code Coverage](https://img.shields.io/coveralls/lighterio/jymin/master.svg)](https://coveralls.io/r/lighterio/jymin) | ||
[![Dependencies](https://img.shields.io/david/lighterio/jymin.svg)](https://david-dm.org/lighterio/jymin) | ||
[![Support](https://img.shields.io/gittip/zerious.png)](https://www.gittip.com/lighterio/) | ||
[![NPM Version](https://badge.fury.io/js/jymin.png)](http://badge.fury.io/js/jymin) | ||
[![Build Status](https://travis-ci.org/lighterio/jymin.png?branch=master)](https://travis-ci.org/lighterio/jymin) | ||
[![Code Coverage](https://coveralls.io/repos/lighterio/jymin/badge.png?branch=master)](https://coveralls.io/r/lighterio/jymin) | ||
[![Dependencies](https://david-dm.org/lighterio/jymin.png?theme=shields.io)](https://david-dm.org/lighterio/jymin) | ||
[![Support](http://img.shields.io/gittip/zerious.png)](https://www.gittip.com/lighterio/) | ||
Jymin is "JavaScript You Minify", meaning Jymin scripts get concatenated with | ||
your application code and minfied within a single function closure. Functions | ||
your application uses will remain intact after minification, and functions you | ||
don't use will drop out. The end result is that browsers will download and run | ||
you use will remain intact after minification, and functions you don't use | ||
will drop out. The end result is that browsers will download and run | ||
your code quickly, enabling the most responsive experiences possible. | ||
## Contributing | ||
<!-- | ||
doNothing | ||
responseSuccessHandler | ||
responseFailureHandler | ||
getXhr | ||
getUpload | ||
getResponse | ||
forEach | ||
each | ||
getLength | ||
getFirst | ||
getLast | ||
hasMany | ||
push | ||
pop | ||
merge | ||
padArray | ||
getAllCookies | ||
getCookie | ||
setCookie | ||
deleteCookie | ||
getTime | ||
getIsoDate | ||
formatLongDate | ||
formatShortDate | ||
getElement | ||
getElementsByTagName | ||
getElementsByTagAndClass | ||
getParent | ||
createTag | ||
createElement | ||
addElement | ||
appendElement | ||
prependElement | ||
wrapElement | ||
getChildren | ||
getIndex | ||
insertElement | ||
insertBefore | ||
insertAfter | ||
removeElement | ||
clearElement | ||
getHtml | ||
setHtml | ||
getText | ||
setText | ||
getAttribute | ||
setAttribute | ||
getData | ||
setData | ||
getClass | ||
setClass | ||
getFirstChild | ||
getPreviousSibling | ||
getNextSibling | ||
hasClass | ||
addClass | ||
removeClass | ||
flipClass | ||
toggleClass | ||
insertScript | ||
all | ||
one | ||
Emitter | ||
EmitterPrototype | ||
CLICK | ||
MOUSEDOWN | ||
MOUSEUP | ||
KEYDOWN | ||
KEYUP | ||
KEYPRESS | ||
bind | ||
on | ||
trigger | ||
stopPropagation | ||
preventDefault | ||
bindFocusChange | ||
bindHover | ||
onHover | ||
bindClick | ||
bindWindowLoad | ||
isLoaded | ||
focusElement | ||
doOnce | ||
addTimeout | ||
removeTimeout | ||
getType | ||
getValue | ||
setValue | ||
getHistory | ||
historyPush | ||
historyReplace | ||
historyPop | ||
onHistoryPop | ||
reservedWordPattern | ||
stringify | ||
parse | ||
execute | ||
parseBoolean | ||
parseNumber | ||
parseString | ||
parseObject | ||
parseArray | ||
error | ||
warn | ||
info | ||
log | ||
trace | ||
ifConsole | ||
ensureNumber | ||
zeroFill | ||
forIn | ||
forOf | ||
decorateObject | ||
ensureProperty | ||
storage | ||
fetch | ||
store | ||
ensureString | ||
contains | ||
startsWith | ||
trim | ||
splitByCommas | ||
splitBySpaces | ||
decorateString | ||
match | ||
extractLetters | ||
extractNumbers | ||
lower | ||
upper | ||
escape | ||
unescape | ||
buildQueryString | ||
getBrowserVersionOrZero | ||
isType | ||
isUndefined | ||
isBoolean | ||
isNumber | ||
isString | ||
isFunction | ||
isObject | ||
isInstance | ||
isArray | ||
isDate | ||
getHost | ||
getBaseUrl | ||
getQueryParams | ||
getHashParams | ||
use | ||
useFns | ||
useMap | ||
useDepth | ||
--> | ||
Jymin encourages community code contribution. Since the library is just | ||
getting started, please get in touch with Sam Eubank if you're interested in | ||
contributing. | ||
## Acknowledgements | ||
We would like to thank all of the amazing people who use, support, | ||
promote, enhance, document, patch, and submit comments & issues. | ||
Jymin couldn't exist without you. | ||
Additionally, huge thanks go to [TUNE](http://www.tune.com) for employing | ||
and supporting [Jymin](http://lighter.io/jymin) project maintainers, | ||
and for being an epically awesome place to work (and play). | ||
## MIT License | ||
Copyright (c) 2014 Sam Eubank | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
## How to Contribute | ||
We welcome contributions from the community and are happy to have them. | ||
Please follow this guide when logging issues or making code changes. | ||
### Logging Issues | ||
All issues should be created using the | ||
[new issue form](https://github.com/lighterio/jymin/issues/new). | ||
Please describe the issue including steps to reproduce. Also, make sure | ||
to indicate the version that has the issue. | ||
### Changing Code | ||
Code changes are welcome and encouraged! Please follow our process: | ||
1. Fork the repository on GitHub. | ||
2. Fix the issue ensuring that your code follows the | ||
[style guide](http://lighter.io/style-guide). | ||
3. Add tests for your new code, ensuring that you have 100% code coverage. | ||
(If necessary, we can help you reach 100% prior to merging.) | ||
* Run `npm test` to run tests quickly, without testing coverage. | ||
* Run `npm run cover` to test coverage and generate a report. | ||
* Run `npm run report` to open the coverage report you generated. | ||
4. [Pull requests](http://help.github.com/send-pull-requests/) should be made | ||
to the [master branch](https://github.com/lighterio/jymin/tree/master). | ||
### Contributor Code of Conduct | ||
As contributors and maintainers of Jymin, we pledge to respect all | ||
people who contribute through reporting issues, posting feature requests, | ||
updating documentation, submitting pull requests or patches, and other | ||
activities. | ||
If any participant in this project has issues or takes exception with a | ||
contribution, they are obligated to provide constructive feedback and never | ||
resort to personal attacks, trolling, public or private harassment, insults, or | ||
other unprofessional conduct. | ||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, edits, issues, and other contributions | ||
that are not aligned with this Code of Conduct. Project maintainers who do | ||
not follow the Code of Conduct may be removed from the project team. | ||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by opening an issue or contacting one or more of the project | ||
maintainers. | ||
We promise to extend courtesy and respect to everyone involved in this project | ||
regardless of gender, gender identity, sexual orientation, ability or | ||
disability, ethnicity, religion, age, location, native language, or level of | ||
experience. |
@@ -58,3 +58,3 @@ /** | ||
onFailure || responseFailureHandler; | ||
var data = parse(request.responseText); | ||
var data = parse(request.responseText) || {}; | ||
data._STATUS = status; | ||
@@ -61,0 +61,0 @@ data._REQUEST = request; |
@@ -54,3 +54,3 @@ /** | ||
*/ | ||
var deleteCookie = function deleteCookie( | ||
var deleteCookie = function ( | ||
name // string: Name of the cookie. | ||
@@ -57,0 +57,0 @@ ) { |
@@ -49,3 +49,3 @@ /** | ||
var minutes = date.getMinutes(); | ||
minutes = minutes > 10 ? minutes : "0" + minutes; | ||
minutes = minutes > 9 ? minutes : "0" + minutes; | ||
h > 12 ? (isAm = false, h -= 12) : (h === 0 ? h = 12 : 0); | ||
@@ -65,3 +65,3 @@ return m + " " + date.getDate() + ", " + date.getFullYear() + " at " + h + | ||
var minutes = date.getMinutes(); | ||
minutes = minutes > 10 ? minutes : "0" + minutes; | ||
minutes = minutes > 9 ? minutes : "0" + minutes; | ||
h > 12 ? (isAm = false, h -= 12) : (h === 0 ? h = 12 : 0); | ||
@@ -68,0 +68,0 @@ return m + "/" + date.getDate() + "/" + date.getFullYear() % 100 + " " + h + |
@@ -88,5 +88,12 @@ /** | ||
*/ | ||
var createElement = function ( | ||
tagIdentifier | ||
) { | ||
var createTag = function (tagName) { | ||
var isSvg = /^(svg|g|path|circle|line)$/.test(tagName); | ||
var uri = 'http://www.w3.org/' + (isSvg ? '2000/svg' : '1999/xhtml'); | ||
return document.createElementNS(uri, tagName); | ||
}; | ||
/** | ||
* Create a DOM element. | ||
*/ | ||
var createElement = function (tagIdentifier) { | ||
if (!isString(tagIdentifier)) { | ||
@@ -103,3 +110,3 @@ return tagIdentifier; | ||
var attributes = tagAndAttributes[1]; | ||
var cachedElement = createElement[tagName] || (createElement[tagName] = document.createElement(tagName)); | ||
var cachedElement = createTag[tagName] || (createTag[tagName] = createTag(tagName)); | ||
var element = cachedElement.cloneNode(true); | ||
@@ -465,3 +472,3 @@ if (id) { | ||
element = getElement(element); | ||
if (element) { | ||
if (element && !hasClass(element, className)) { | ||
element.className += ' ' + className; | ||
@@ -468,0 +475,0 @@ } |
@@ -0,1 +1,4 @@ | ||
// JavaScript reserved words. | ||
var reservedWordPattern = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/; | ||
/** | ||
@@ -5,23 +8,20 @@ * Create JSON that doesn't necessarily have to be strict. | ||
var stringify = function (data, strict, stack) { | ||
var reserved = /^(break|case|catch|continue|debugger|default|delete|do|else|finally|for|function|if|in|instanceof|new|return|switch|this|throw|try|typeof|var|void|while|with)$/; | ||
if (data === null) { | ||
data = 'null'; | ||
if (isString(data)) { | ||
data = '"' + data.replace(/\n\r"/g, function (c) { | ||
return c == '\n' ? '\\n' : c == '\r' ? '\\r' : '\\"'; | ||
}) + '"'; | ||
} | ||
else if (isFunction(data)) { | ||
data = data.toString(); | ||
if (strict) { | ||
data = '-1'; | ||
data = stringify(data); | ||
} | ||
else { | ||
data = ensureString(data).replace(/^function \(/, 'function('); | ||
} | ||
} | ||
else if (isDate(data)) { | ||
data = 'new Date(' + getTime(data) + ')'; | ||
if (strict) { | ||
data = '"' + getIsoDate() + '"'; | ||
data = stringify(data); | ||
} | ||
else { | ||
data = 'new Date(' + getTime(data) + ')'; | ||
} | ||
} | ||
else if (isObject(data)) { | ||
else if (data && isObject(data)) { | ||
stack = stack || []; | ||
@@ -51,3 +51,3 @@ var isCircular = false; | ||
forIn(data, function (key, value) { | ||
if (strict || reserved.test(key)) { | ||
if (strict || reservedWordPattern.test(key) || /(^\d|[^\w$])/.test(key)) { | ||
key = '"' + key + '"'; | ||
@@ -61,5 +61,2 @@ } | ||
} | ||
else if (isString(data) && stack) { | ||
data = '"' + data.replace(/"/g, '\\"') + '"'; | ||
} | ||
else { | ||
@@ -72,18 +69,15 @@ data = '' + data; | ||
/** | ||
* Parse JavaScript. | ||
* Parse JavaScript and return a value. | ||
*/ | ||
var parse = function (text) { | ||
if (text[0] == '{' || text[0] == '[') { | ||
try { | ||
var evil = window.eval; // jshint ignore:line | ||
evil('eval.J=' + text); | ||
text = evil.J; | ||
} | ||
catch (e) { | ||
//+env:debug | ||
error('[Jymin] Could not parse JS: "' + text + '"'); | ||
//-env:debug | ||
} | ||
var parse = function (value) { | ||
try { | ||
var evil = window.eval; // jshint ignore:line | ||
evil('eval.J=' + value); | ||
return evil.J; | ||
} | ||
return text; | ||
catch (e) { | ||
//+env:debug | ||
error('[Jymin] Could not parse JS: ' + value); | ||
//-env:debug | ||
} | ||
}; | ||
@@ -95,3 +89,43 @@ | ||
var execute = function (text) { | ||
parse('{};' + text); | ||
parse('0;' + text); | ||
}; | ||
/** | ||
* Parse a value and return a boolean no matter what. | ||
*/ | ||
var parseBoolean = function (value, alternative) { | ||
value = parse(value); | ||
return isBoolean(value) ? value : (alternative || false); | ||
}; | ||
/** | ||
* Parse a value and return a number no matter what. | ||
*/ | ||
var parseNumber = function (value, alternative) { | ||
value = parse(value); | ||
return isNumber(value) ? value : (alternative || 0); | ||
}; | ||
/** | ||
* Parse a value and return a string no matter what. | ||
*/ | ||
var parseString = function (value, alternative) { | ||
value = parse(value); | ||
return isString(value) ? value : (alternative || ''); | ||
}; | ||
/** | ||
* Parse a value and return an object no matter what. | ||
*/ | ||
var parseObject = function (value, alternative) { | ||
value = parse(value); | ||
return isObject(value) ? value : (alternative || {}); | ||
}; | ||
/** | ||
* Parse a value and return a number no matter what. | ||
*/ | ||
var parseArray = function (value, alternative) { | ||
value = parse(value); | ||
return isObject(value) ? value : (alternative || []); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
119494
4
29
4333
256
2
2
2