New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

elements-lite

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elements-lite - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

74

elements.js

@@ -183,45 +183,45 @@

proto.set = function(args, val) {
var t = this
proto.set = function(args) {
var val
, t = this
, key = typeof args
if (args) {
if (key == "string" || key == "number" || args.nodeType || "length" in args) t.append(args)
else for (key in args)
/** hasOwnProperty
if (args.hasOwnProperty(arg))
//*/
{
val = args[key]
// El uses class
if (key == "class") t.addClass(val)
else if (typeof val == "string") {
/*
* Note: IE5-7 doesn't set styles and removes events when you try to set them.
*
* in IE6, a label with a for attribute linked to a select list
* will cause a re-selection of the first option instead of just giving focus.
* http://webbugtrack.blogspot.com/2007/09/bug-116-for-attribute-woes-in-ie6.html
*/
t.setAttribute(key, val)
if (!args) return t
if (key == "string" || key == "number" || args.nodeType || "length" in args) t.append(args)
else for (key in args)
/** hasOwnProperty
if (args.hasOwnProperty(arg))
//*/
{
val = args[key]
// El uses class
if (key == "class") t.addClass(val)
else if (!val) t.removeAttribute(key)
else if (typeof val == "string") {
/*
* Note: IE5-7 doesn't set styles and removes events when you try to set them.
*
* in IE6, a label with a for attribute linked to a select list
* will cause a re-selection of the first option instead of just giving focus.
* http://webbugtrack.blogspot.com/2007/09/bug-116-for-attribute-woes-in-ie6.html
*/
t.setAttribute(key, val)
/*
* there are bug in IE<9 where changed 'name' param not accepted on form submit
* The JScript engine used in IE doesn't recognize vertical tabulation character
* oldIE = "\v" == "v"
*
* IE8 and below also support document.createElement('<P>')
*
* http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/
* http://msdn.microsoft.com/en-us/library/ms536614(VS.85).aspx
*/
/*
* there are bug in IE<9 where changed 'name' param not accepted on form submit
* The JScript engine used in IE doesn't recognize vertical tabulation character
* oldIE = "\v" == "v"
*
* IE8 and below also support document.createElement('<P>')
*
* http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/
* http://msdn.microsoft.com/en-us/library/ms536614(VS.85).aspx
*/
if (key == "name" && "\v" == "v") {
t.mergeAttributes(doc.createElement("<INPUT name='" + key + "'/>"), false)
}
if ((key == "id" || key == "name") && "\v" == "v") {
t.mergeAttributes(doc.createElement('<INPUT '+key+'="' + val + '"/>'), false)
}
}
else if (!val) t.removeAttribute(key)
else t[key] = val
}
else t[key] = val
}

@@ -228,0 +228,0 @@ return t

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

Date.prototype.lang = function(lang) {
return this.format( i18n("date") )
return this.format( i18n("date", lang) )
}

@@ -59,0 +59,0 @@

{
"name": "elements-lite",
"version": "0.2.2",
"version": "0.2.3",
"stability": 1,

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -6,9 +6,12 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

/*
* @version 0.1.15
* @date 2014-03-20
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
* @version 0.2.2
* @date 2014-05-24
* @stability 1 - Experimental
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
/* TODO: find ways for automated testing

@@ -51,3 +54,3 @@ * http://www.browserscope.org/user/tests/howto

return fnCache[name] && fnCache[name](el, args) || el.set(args)
return fnCache[name] && fnCache[name].call(el, args) || el.set(args)
}

@@ -88,22 +91,22 @@

proto.append = function(e, before) {
proto.append = function(child, before) {
var t = this
if (e) {
if (typeof e == "string" || typeof e == "number") e = El.text(e)
else if ( !("nodeType" in e) && "length" in e ) {
if (child) {
if (typeof child == "string" || typeof child == "number") child = El.text(child)
else if ( !("nodeType" in child) && "length" in child ) {
/*
* document.createDocumentFragment is unsupported in IE5.5
* f = "createDocumentFragment" in doc ? doc.createDocumentFragment() : El("div")
* fragment = "createDocumentFragment" in doc ? doc.createDocumentFragment() : El("div")
*/
for (
var len = e.length
var len = child.length
, i = 0
, f = doc.createDocumentFragment();
, fragment = doc.createDocumentFragment();
i < len
; ) t.append.call(f, e[i++]);
e = f
; ) proto.append.call(fragment, child[i++]);
child = fragment
}
if (e.nodeType) t.insertBefore(e,
if (child.nodeType) t.insertBefore(child,
(before === true ? t.firstChild :

@@ -114,3 +117,3 @@ typeof before == "number" ? t.childNodes[

)
e.append_hook && e.append_hook()
child.append_hook && child.append_hook()
//"child_hook" in t && t.child_hook()

@@ -121,9 +124,12 @@ }

proto.after = function(e, before) {
e.parentNode.append(this, before ? e : e.nextSibling)
proto.after = function(silbing, before) {
/*
* call append from proto so it works with DocumentFragment
*/
proto.append.call(silbing.parentNode, this, before ? silbing : silbing.nextSibling)
return this
}
proto.to = function(e, before) {
e.append(this, before)
proto.to = function(parent, before) {
proto.append.call(parent, this, before)
return this

@@ -152,11 +158,11 @@ }

proto.toggleClass = function(name, s) {
if (arguments.length == 1) s = !this.hasClass(name)
this[ s ? "addClass" : "rmClass" ](name)
return s
proto.toggleClass = function(name, force) {
if (arguments.length == 1) force = !this.hasClass(name)
this[ force ? "addClass" : "rmClass" ](name)
return force
}
proto.empty = function() {
var t = this, n
while (n = t.firstChild) t.kill.call(n)
var t = this, node
while (node = t.firstChild) t.kill.call(node)
return t

@@ -184,7 +190,9 @@ }

proto.set = function(args) {
var t = this, k = typeof args, v
proto.set = function(args, val) {
var t = this
, key = typeof args
if (args) {
if (k == "string" || k == "number" || args.nodeType || "length" in args) t.append(args)
else for (k in args)
if (key == "string" || key == "number" || args.nodeType || "length" in args) t.append(args)
else for (key in args)
/** hasOwnProperty

@@ -194,6 +202,6 @@ if (args.hasOwnProperty(arg))

{
v = args[k]
val = args[key]
// El uses class
if (k == "class") t.addClass(v)
else if (typeof v == "string") {
if (key == "class") t.addClass(val)
else if (typeof val == "string") {
/*

@@ -206,3 +214,3 @@ * Note: IE5-7 doesn't set styles and removes events when you try to set them.

*/
t.setAttribute(k, v)
t.setAttribute(key, val)

@@ -220,9 +228,9 @@ /*

if (k == "name" && "\v" == "v") {
t.mergeAttributes(doc.createElement("<INPUT name='" + k + "'/>"), false)
if (key == "name" && "\v" == "v") {
t.mergeAttributes(doc.createElement("<INPUT name='" + key + "'/>"), false)
}
}
else if (!v) t.removeAttribute(k)
else t[k] = v
else if (!val) t.removeAttribute(key)
else t[key] = val
}

@@ -233,3 +241,21 @@ }

/*
* In Safari 2.x, innerText functions properly only
* if an element is neither hidden (via style.display == "none")
* nor orphaned from the document.
* Otherwise, innerText results in an empty string.
*
* textContent is suported from IE9
*
* Opera 9-10 have Node.text, Node.textContent
*/
proto.txt = function(newText) {
var t = this
, attr = "textContent" in t ? "textContent" : "innerText"
return arguments.length ? (t[attr] = newText) : t[attr]
}
/*
* Expose slow find for testing

@@ -272,8 +298,5 @@ *

function extend(e, p, k) {
if (e) {
p = El[protoStr]
for (k in p) e[k] = p[k]
}
return e
function extend(node, key) {
if (node) for (key in proto) node[key] = proto[key]
return node
}

@@ -329,2 +352,818 @@

},{}],2:[function(require,module,exports){
/*
* @version 0.2.2
* @date 2014-05-24
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
!function(root, doc) {
var hamlRe = /^([ \t]*)(\:?)((?:(["'\/])(?:\\.|.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm
function to_array(a) {
for (var b=[], c=a.length; c--;) b[c] = a[c]
return b
}
function This() {
return this
}
function haml(str) {
var root = doc.createDocumentFragment()
, parent = root
, stack = [-1]
function work(all, indent, plugin, name, q, text) {
for (var i = indent.length; i <= stack[0]; ) {
stack.shift()
parent = (parent.plugin) ? parent.plugin.done() : parent.parentNode
}
if (plugin) {
if (haml.plugins[name]) {
parent = (new haml.plugins[name](parent, text)).el
stack.unshift(i)
}
else {
parent.append(El.text( all ))
}
} else {
if (name) {
parent = El(name).to(parent)
stack.unshift(i)
}
if (text) {
if (text.charAt(0)==">") (indent +" "+ text.slice(1)).replace(hamlRe, work)
else if (text.charAt(0)=="=") parent.set({"data-bind": text.slice(1)})
else parent.append(text.replace(/\\([=>:])/g, "$1"))
}
}
}
str.replace(hamlRe, work)
stack = root.childNodes
return stack.length == 1 ? stack[0] : to_array(stack)
}
function template(parent, name) {
var t = this
t.name = name
t.parent = parent
t.el = El("div")
t.el.plugin = t
return t
}
template.prototype = {
cloneNode: This,
set: This,
done: function() {
var t = this
El.cache(t.name, t.el.removeChild(t.el.firstChild), render)
t.el.plugin = null
return t.parent
}
}
var ifFn = template.extend({
done: function(){
var t = this
El.cache(t.name, t.el.firstChild, render)
t.el.plugin = null
return t.parent
}
})
haml.plugins = {
/*
* - Declaration
* mixin list
*
* mixin link(href, name)
* a(class!=attributes.class, href=href)= name
*
* +link('/foo', 'foo')(class="btn")
*
* :include
* :doctype
* - http://stackoverflow.com/questions/8227612/how-to-create-document-objects-with-javascript
*/
"template": template,
"if": ifFn,
"for": function(parent, name, text) {
}
}
root.haml = haml
root.include = function(id, data, parent) {
var src = El.get(id)
new template(null, id).el.append( El.haml(src.innerHTML) ).plugin.done()
src.kill()
}
function getLa(node) {
var la = node.la
if (!la) {
node.la = la = []
for (var child; child = node.firstChild;) {
la.push(child);
node.removeChild(child)
}
}
return la
}
var attrMap = {
"text": "textContent" in doc ? "textContent" : "innerText",
"html": "innerHTML",
"if": function(node, data, bind) {
console.log("if", arguments)
var la = getLa(node)
var arr = data && data[bind]
if (arr) node.empty().append( Fn(bind)(data) && arr )
},
"each": function(node, data, bind) {
var la = getLa(node)
var arr = data && data[bind]
if (arr) node.empty().append(arr.map(function(obj){
return la.map(function(el){
return render.call(el.cloneNode(true), obj)
})
}))
}
}
function render(data) {
var attr, bind, lang
, node = this
//console.log("render", data, node)
if (bind = node.getAttribute("data-bind")) {
lang = node.getAttribute("lang") || lang
if (attr = bind.match(/(\w+)\:/)) {
bind = bind.slice( attr[0].length )
attr = attrMap[attr[1]] || attr[1]
}
if (typeof attr == "function") {
attr(node, data, bind)
return node
}
else {
node[ attr || attrMap.text ] = i18n(bind, lang).format(data)
}
}
for (node = node.firstChild; node; node = node.nextSibling) {
if (node.nodeType == 1) render.call(node, data)
}
return this
}
root.prototype.render = render
}(window.El || this, window.document)
},{}],3:[function(require,module,exports){
/*
* @version 0.2.2
* @date 2014-05-24
* @stability 1 - Experimental
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
!function(root) {
var current;
function i18n(text, lang) {
return (i18n[lang ? getLang(lang) : current][text] || text)
}
function getLang(lang) {
if (!lang) return current
lang = (lang||"").toLowerCase()
return i18n[lang] ? lang : (lang = lang.split("-")[0]), i18n[lang] ? lang : current
}
function setLang(lang) {
lang = i18n.getLang(lang)
if (current != (current = lang)) {
i18n[lang] = i18n[lang] || {}
}
return lang
}
i18n.getLang = getLang
i18n.setLang = setLang
//i18n.main = i18n.current = "en"
i18n.en = {
date: "%a, %d %b %Y %H:%M:%S %z",
name: "Name {date|lang}"
}
i18n.et = {
date: "%Y %H:%M:%S %z",
name: "Nimi {date|lang:'et'}"
}
//i18n.setLang(navigator.language || navigator.userLanguage)
Date.prototype.lang = function(lang) {
return this.format( i18n("date", lang) )
}
String.prototype.lang = function(lang) {
return i18n(this, lang)
}
root.i18n = i18n
}(this)
},{}],4:[function(require,module,exports){
/*
* @version 0.1.8
* @date 2014-02-18
* @stability 2 - Unstable
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
!function(win) {
var a, b
, c = Object
, P = "prototype"
, A = Array[P]
, S = String[P]
, F = Function
, esc = escape
, patched = win._patched = []
function I(obj, key, src, force) {
if (force || !obj[key]) {
obj[key] = new F("a,b,c","var P='"+P+"';"+src)
patched.push(key)
}
}
F.Nop = function(){}
/*
* The HTML5 document.head DOM tree accessor
*/
//doc.head = doc.head || doc.getElementsByTagName("head")[0]
/*
* Function.prototype.bind from ECMAScript5
* Basic support: Chrome 7 Firefox (Gecko) 4.0 (2) IE 9 Opera 11.60 Safari 5.1.4
*
* http://msdn.microsoft.com/en-us/library/s4esdbwz(v=vs.94).aspx
*/
I(F[P], "bind", "var t=this;b=[].slice.call(arguments,1);c=function(){return t.apply(this instanceof c?this:a,b.concat.apply(b,arguments))};if(t[P])c[P]=t[P];return c")
// Object extensions
// -----------------
I(c, "create" , "b=Function.Nop;b[P]=a;return new b")
I(c, "keys" , "c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c")
// Array extensions
// ----------------
I(Array, "isArray", "return a instanceof Array")
a = "var t=this,l=t.length,o=[],i=-1;"
c = "if(t[i]===a)return i;return -1"
I(A, "indexOf", a+"i+=b|0;while(++i<l)"+c)
I(A, "lastIndexOf", a+"i=(b|0)||l;i>--l&&(i=l)||i<0&&(i+=l);++i;while(--i>-1)"+c)
b = a+"if(arguments.length<2)b=t"
c = "b=a.call(null,b,t[i],i,t);return b"
I(A, "reduce", b+"[++i];while(++i<l)"+c)
I(A, "reduceRight", b+"[--l];i=l;while(i--)"+c)
b = a+"while(++i<l)if(i in t)"
I(A, "forEach", b+"a.call(b,t[i],i,t)")
I(A, "every", b+"if(!a.call(b,t[i],i,t))return!1;return!0")
c = ";return o"
I(A, "map", b+"o[i]=a.call(b,t[i],i,t)"+c)
b += "if(a.call(b,t[i],i,t))"
I(A, "filter", b+"o.push(t[i])"+c)
I(A, "some", b+"return!0;return!1")
I(S, "trim", "return this.replace(/^\\s+|\\s+$/g, '')")
/*
* `Date.prototype.format` is implemented in `date-format-lite` module.
*/
I(Date[P], "toISOString", "return this.format('isoUtcDateTime')")
I(Date, "now", "return+new Date")
if (!win.JSON) {
patched.push("JSON")
win.JSON = {
map: {"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t",'"':'\\"',"\\":"\\\\"},
parse: new F("t", "return new Function('return('+t+')')()"),
//parse: Fn("t->new Function('return('+t+')')()"),
stringify: new F("o", "if(o==null)return'null';if(o instanceof Date)return'\"'+o.toISOString()+'\"';var i,s=[],c;if(Array.isArray(o)){for(i=o.length;i--;s[i]=JSON.stringify(o[i]));return'['+s.join()+']'}c=typeof o;if(c=='string'){for(i=o.length;c=o.charAt(--i);s[i]=JSON.map[c]||(c<' '?'\\\\u00'+((c=c.charCodeAt(0))|4)+(c%16).toString(16):c));return'\"'+s.join('')+'\"'}if(c=='object'){for(i in o)o.hasOwnProperty(i)&&s.push(JSON.stringify(i)+':'+JSON.stringify(o[i]));return'{'+s.join()+'}'}return''+o")
}
}
// Ignore FF3 escape second non-standard argument
// https://bugzilla.mozilla.org/show_bug.cgi?id=666448
if (esc("a",0) != "a") {
patched.push("escape")
win.escape = function(s) {
return esc(s)
}
}
}(this)
},{}],5:[function(require,module,exports){
/*
* @version 0.2.3
* @date 2014-02-28
* @stability 2 - Unstable
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
!function(root) {
var P = "prototype"
, A = Array[P], F = Function[P], S = String[P]
, O = Object
, sl = F.call.bind(A.slice)
, cs = []
// Function extensions
// -------------------
F.construct = function(a) {
/*
* bind version have bad performance and memory consumption
* return new(F.bind.apply(this, A.concat.apply([null], a)))
*/
var l = a.length
return l ? (cs[l] || (cs[l] = Fn("t a->new t(a["+O.keys(sl(a)).join("],a[")+"])")))(this, a) : new this
}
F.partial = function() {
var self = this, a = sl(arguments)
return function() {return self.apply(this, a.concat.apply(a, arguments))}
}
/*
* **argi** - index of argument, which will be split
* **re** - optional RegExp for matching words
*/
F.byWords = function(argi, re) {
var self = this
return function() {
var s = this
, r = s
, a = arguments
;(a[argi |= 0]||"").replace(re || /\S+/g, function(w) {
a[argi] = w
r = self.apply(s, a)
})
return r
}
}
F.byKeyVal = function() {
var self = this
return function(o) {
var r, s = this, a = sl(arguments)
if (typeof o == "object") for (r in o) {
a[0] = r
a[1] = o[r]
r = self.apply(s, a)
} else r = self.apply(s, a)
return r
}
}
// Run function once and return cached value or cached instance
F.cache = function(instance, keyFn, cache) {
var self = this
, c = cache || {}
, f = function() {
var a = arguments
, i = !!instance || this instanceof f
, k = keyFn ? keyFn.apply(self, a) : i + ":" + a.length + ":" + sl(a)
return k in c ? c[k] : (c[k] = i ? self.construct(a) : self.apply(this, a))
}
f.origin = self
f.cached = c
f.extend = function() {
return self.extend.apply(self, arguments).cache(instance, keyFn, cache)
}
f[P] = self[P] // prototype for better access on extending
return f
}
F.extend = function() {
var a
, self = this
, i = 0
, f = function() {
return self.apply(this, arguments)
}
f[P] = O.create(self[P])
f[P].constructor = f
while (a = arguments[i++]) O.merge(f[P], a)
return f
}
// Time to live - Run *fun* if Function not called on time
F.ttl = function(ms, fun) {
var self = this
, tick = setTimeout(function(){ms=0;fun&&fun()}, ms)
return function() {
clearTimeout(tick)
ms && self.apply(null, arguments)
}
}
// Run Function one time after last call
F.once = function(ms) {
var tick, args, self = this
return function() {
clearTimeout(tick)
args = arguments
tick = setTimeout(function(){self.apply(null, args)}, ms)
}
}
// Maximum call rate for Function
F.rate = function(ms, last_call) {
var tick, args, self = this, next = 0
return function() {
var now = +new Date()
clearTimeout(tick)
if (now > next) {
next = now + ms
self.apply(null, arguments)
} else if (last_call) {
args = arguments
tick = setTimeout(function(){self.apply(null, args)}, next-now)
}
}
}
// Non-standard
O.each = function(obj, fn, scope, key) {
if (obj) for (key in obj) obj.hasOwnProperty(key) && fn.call(scope, obj[key], key, obj)
}
// Object.assign ( target, source ) in ECMAScript 6
O.merge = function(target, source) {
for (var k, i = 1; source = arguments[i++];)
for (k in source) if (source.hasOwnProperty(k)) target[k] = source[k]
return target
}
// Note: use for Object literals only,
// as it returns false for custom objects,
// like new Date or new YourObject.
function isObject(obj) {
return obj && obj.constructor === O
}
O.clone = function(source, temp, key) {
if (isObject(source)) {
temp = {}
for (key in source) if (source.hasOwnProperty(key))
temp[key] = O.clone(source[key])
source = temp
}
return source
}
O.deepMerge = O.deepCopy = function(target, source, path, changed, key, val) {
path = path || ""
changed = changed || []
for (key in source) if (source.hasOwnProperty(key) && target[key] !== source[key]) {
val = source[key]
changed.push(path+key)
if (val === null) delete target[key]
else if (isObject(val)) {
if (!isObject(target[key])) target[key] = {}
O.deepMerge(target[key], val, path+key+".", changed)
}
else target[key] = val
}
return changed
}
O.zip = function(keys, vals) {
return keys.fold(function(_, key, i) {
_[key] = vals[i]
return _
}, {})
}
/*
Array.flatten = function(arr) {
for(var i=arr.length;i--;)
0 in arr[i] && A.splice.apply(arr, [i, 1].concat(Array.flatten(arr[i])))
return arr
}
flat([1,2,[3,4,[5,6]],7])
*/
// Non-standard
// // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
A.remove = function() {
var self = this
, l = self.length
, o = sl(arguments)
, last_id = -1
while (l--) if (~o.indexOf(self[l])) self.splice(last_id = l, 1)
return last_id
}
A.each = A.forEach
A.fold = A.reduce
A.foldr = A.reduceRight
// uniq
A.unique = A.filter.partial(function(s,i,a){return i == a.lastIndexOf(s)})
!function(n) {
F[n] = S[n] = function() {
var a = arguments, l = a[0]
a[0] = this.fn()
return A[n].apply(l, a)
}
}.byWords()("every filter each map fold foldr some")
F.fn = function() {
return this
}
S.fn = function() {
return Fn(this)
}
/*
* Copyright 2007 by Oliver Steele. MIT License
* http://osteele.com/javascripts/functional
* Modifyed by Lauri Rooden
*/
function Fn(expr) {
var args = "_"
, body = expr
, arr = expr.split("->")
while (arr.length > 1) {
body = arr.pop()
args = arr.pop().match(/\w+/g)||""
arr.length && arr.push("(function("+args+"){return("+body+")})")
}
return new Function(args, "return(" + body + ")")
}
root.Fn = Fn.cache()
}(this)
},{}],6:[function(require,module,exports){
/*
* @version 0.0.7
* @date 2014-03-16
* @stability 2 - Unstable
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
!function(P) {
var A = Array[P]
, D = Date[P]
, N = Number[P]
, S = String[P]
, formatRe = /\{(?!\\)\s*([$\w]+)((?:(["'\/])(?:\\.|.)*?\3|\-?\d*\.?\d+|[,\s\w|:])*)\}/g
, filterRe = /\s*\|\s*(\w+)(?:\s*\:((?:(["'\/])(?:\\.|.)*?\3|\-?\d*\.?\d+|[,\s])*))?/g
S.format = function(data) {
var args = typeof data == "object" ? data : arguments
return this.replace(formatRe, function(_, arg, filter) {
if (filter) {
var fn = "(_['"+arg+"']||''" + filter.replace(filterRe, ").$1($2") + ")"
return Fn(fn)(args).format(data)
}
return arg in args ? args[arg] : ""
}).replace(/{\\/g,"{")
}
S.safe = function() {
return this
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/\"/g, "&quot;")
}
S.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1)
}
S.lower = S.downcase = S.toLowerCase // lower
S.upper = S.upcase = S.toUpperCase // upper
S.size = A.size = function() {
return this.length
}
S.truncate = function(num) {
return this.slice(0, num)
}
S.truncatewords = function(num) {
return this.split(" ").splice(0, num).join(" ")
}
S.remove = function(str) {
return this.split(str).join("")
}
S.remove_first = function(str) {
var arr = this.split(str)
return arr.shift() + arr.join(str)
}
S.camelback = function() {
return this.replace(/[ _-]+([a-z])/g, function(_, a){return a.toUpperCase()})
}
S.camelcase = function() {
return this.camelback().capitalize()
}
//*
S.repeat = S.times = function(times) {
return times < 1 ? "" : Array(++times).join(this)
}
/*/
// High porformance replace when we should need it
// http://stackoverflow.com/questions/202605/repeat-string-javascript
function stringFill3(x, n) {
var s = '';
for (;;) {
if (n & 1) s += x;
n >>= 1;
if (n) x += x;
else break;
}
return s;
}
//*/
A.first = function() {
return this[0]
}
A.last = function() {
return this[this.length - 1]
}
A.pluck = function(name) {
var t = this, i = t.length, out = []
while (i--) out[i] = t[i][name]
return out
}
S.step = N.step = S.toAccuracy = N.toAccuracy = function(a) {
var x = (""+a).split("."), n = ~~((this/a)+.5) * a
return ""+(1 in x ? n.toFixed(x[1].length) : n)
}
S.pick = N.pick = function() {
var val = this + "="
for (var s, a = arguments, i = 0, len = a.length; i < len;) {
s = a[i++]
if (s.indexOf(val) == 0) {
s = s.slice(val.length)
i = len
}
}
return s.replace("#", this)
}
S.plural = N.plural = function() {
// Plural-Forms: nplurals=2; plural=n != 1;
// http://www.gnu.org/software/gettext/manual/html_mono/gettext.html#Plural-forms
return arguments[ +Fn("n->n != 1")( parseFloat(this) ) ].replace("#", this)
}
S.ordinal = N.ordinal = function() {
return this+'{0|substr:-1|pick:"1=st","2=nd","3=rd","th"}'.format(""+this)
}
function words(input, steps, units, strings, overflow) {
var n = +input
, i = 0
, s = strings || {"default":"{0} {1}{2}"}
while(n>steps[i])n/=steps[i++]
if (i == steps.length && overflow) return overflow(this)
i=units[i]
n=(n+.5)|0
return (s[n<2?i:i+"s"]||s["default"]).format(n, i, n<2?"":"s")
}
S.humanSize = N.humanSize = function() {
return words(this, [1024,1024,1024], ["byte","KB","MB","GB"])
}
S.humanTime = N.humanTime = function(texts) {
return words(this, [60,60,24,7,30], ["second","minute","hour","day","week","month"], texts)
}
//** Date.daysInMonth
D.daysInMonth = function() {
return (new Date(this.getFullYear(),this.getMonth()+1,0)).getDate()
}
//*/
//** Date.startOfWeek
D.startOfWeek = function() {
var t = this
return new Date(t.getFullYear(), t.getMonth(), t.getDate() - (t.getDay() || 7) +1)
}
//*/
//** Date.timeAgo convert dates to human-readable
D.timeAgo = function(format, custom) {
var t = this, d = (new Date() - t + 1) / 1000
return d.humanTime({"default":"{0} {1}{2} ago", "day":"Yesterday"}, function(){return t.format(format)})
}
//*/
}("prototype")
},{}],7:[function(require,module,exports){
(function (process){

@@ -596,33 +1435,29 @@

}).call(this,require("/usr/lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))
},{"/usr/lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":4}],3:[function(require,module,exports){
},{"/usr/lib/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":9}],8:[function(require,module,exports){
(function (global){
global.Event = global.Event || {}
global.i18n = require("../i18n.js").i18n
require("browser-upgrade-lite")
require("liquid-filters-lite")
require("functional-lite")
require("../")
require("../haml")
var getString = (function() {
var DIV = document.createElement("div");
function getString(node) {
if ('outerHTML' in node)
return node.outerHTML.toLowerCase().replace(/>[\n\r]+</g, "><").trim();
if (DIV.hasOwnProperty("toString")) {
console.log("toString")
return function(node) {
return node.toString()
}
}
var div = document.createElement("div");
div.appendChild(node.cloneNode(true));
return div.innerHTML;
}
if ('outerHTML' in DIV)
return function(node) {
return node.outerHTML;
};
i18n.setLang("en")
return function(node) {
var div = document.createElement("div");
div.appendChild(node.cloneNode(true));
return div.innerHTML;
};
var el, h1, h2, h3, h4, select, t1
})();
require("testman").
var el, h1, h2, h3, h4, select
require("testman")
.describe("El").
describe("El").
it ("should build elements").

@@ -642,8 +1477,93 @@ run(function(){

equal(getString(h4), "<h4></h4>").
equal(getString(el.append(h2)), "<div><h2></h2></div>").
anyOf(getString(h2.append(select)), [ '<h2><select id="id2" disabled="disabled" class="cl2"></select></h2>'
, '<h2><select disabled="disabled" class="cl2" id="id2"></select></h2>'
, '<h2><select id="id2" class="cl2" disabled="disabled"></select></h2>'
equal(getString(El("")), "<div></div>").
equal(getString(El("div")), "<div></div>").
equal(getString(El("", "element")), "<div>element</div>").
equal(getString(El("div", "element")), "<div>element</div>").
equal(getString(El("p", "element")), "<p>element</p>").
anyOf(getString(El("#123")), [ '<div id="123"></div>'
, '<div id=123></div>'
]).
anyOf(getString(El("div#123")), [ '<div id="123"></div>'
, '<div id=123></div>'
]).
anyOf(getString(El("p#123")), [ '<p id="123"></p>'
, '<p id=123></p>'
]).
anyOf(getString(El(".c-1")), [ '<div class="c-1"></div>'
, '<div class=c-1></div>'
]).
anyOf(getString(El("div.c1")), [ '<div class="c1"></div>'
, '<div class=c1></div>'
]).
anyOf(getString(El("p.c1")), [ '<p class="c1"></p>'
, '<p class=c1></p>'
]).
equal(getString(El(".c1.c2")), '<div class="c1 c2"></div>').
equal(getString(El("div.c1.c2")), '<div class="c1 c2"></div>').
equal(getString(El("p.c1.c2")), '<p class="c1 c2"></p>').
anyOf(getString(El("#123.c1")), [ '<div id="123" class="c1"></div>'
, '<div class="c1" id="123"></div>'
, '<div class=c1 id=123></div>'
, '<div id=123 class=c1></div>'
]).
anyOf(getString(El("div#123.c1")), [ '<div id="123" class="c1"></div>'
, '<div class="c1" id="123"></div>'
, '<div class=c1 id=123></div>'
, '<div id=123 class=c1></div>'
]).
equal(getString(El("a[href='http://example.com/']")), '<a href="http://example.com/"></a>').
equal(getString(El('a[href="http://example.com/"]')), '<a href="http://example.com/"></a>').
anyOf(getString(El("a[href='http://example.com/'][title=link]")),
[ '<a href="http://example.com/" title="link"></a>'
, '<a title="link" href="http://example.com/"></a>',
, '<a title=link href="http://example.com/"></a>'
]).
anyOf(getString(El('a[href="http://example.com/"][title="link to site"]')),
[ '<a href="http://example.com/" title="link to site"></a>'
, '<a title="link to site" href="http://example.com/"></a>'
]).
it ("shoult set attributes").
equal(select.set({title:"set title"}), select).
equal(select.title, "set title").
equal(select.set({title:"change title", name:"new name"}), select).
equal(select.title, "change title").
equal(select.name, "new name").
equal(select.set({title: null}), select).
equal(select.set({name: null}), select).
ok(!select.title).
ok(!select.name).
it ("has kill() and empty() methods").
equal(select.kill(), select).
equal(h2.innerHTML, "").
equal(el.empty(), el).
equal(el.innerHTML, "").
it ("set childs").
equal(getString(el.to(document.body)), "<div></div>").
equal(getString(el.append(h2)), "<div><h2></h2></div>").
equal(getString(el.append(h1, h2)), "<div><h1></h1><h2></h2></div>").
equal(getString(h4.after(h2)), "<h4></h4>").
equal(getString(el), "<div><h1></h1><h2></h2><h4></h4></div>").
equal(getString(h3.after(h4, true)), "<h3></h3>").
equal(getString(el), "<div><h1></h1><h2></h2><h3></h3><h4></h4></div>").
equal(getString(h3.to(el, h4)), "<h3></h3>").
equal(getString(el), "<div><h1></h1><h2></h2><h3></h3><h4></h4></div>").
equal(getString(h1.append([h2, h3])), "<h1><h2></h2><h3></h3></h1>").
equal(getString(el), "<div><h1><h2></h2><h3></h3></h1><h4></h4></div>").
anyOf(getString(select.to(h2)), [ '<select id="id2" disabled="disabled" class="cl2"></select>'
, '<select disabled="disabled" class="cl2" id="id2"></select>'
, '<select id="id2" class="cl2" disabled="disabled"></select>'
, '<select class=cl2 id=id2 disabled></select>'
, '<select id=id2 class=cl2 disabled></select>'
]).
it ("should get element by id").
equal(El.get("id2"), select).
it ("find childs").
equal(el.find("#id2"), select).

@@ -667,31 +1587,104 @@ equal(el.find(".cl2"), select).

equal(select.kill(), select).
equal(getString(El("")), "<div></div>").
equal(getString(El("div")), "<div></div>").
equal(getString(El("", "element")), "<div>element</div>").
equal(getString(El("div", "element")), "<div>element</div>").
equal(getString(El("#123")), '<div id="123"></div>').
equal(getString(El("div#123")), '<div id="123"></div>').
equal(getString(El(".c1")), '<div class="c1"></div>').
equal(getString(El("div.c1")), '<div class="c1"></div>').
equal(getString(El(".c1.c2")), '<div class="c1 c2"></div>').
equal(getString(El("div.c1.c2")), '<div class="c1 c2"></div>').
anyOf(getString(El("#123.c1")), [ '<div id="123" class="c1"></div>'
, '<div class="c1" id="123"></div>'
]).
anyOf(getString(El("div#123.c1")), [ '<div id="123" class="c1"></div>'
, '<div class="c1" id="123"></div>'
]).
it ("supports boolean attributes").
equal(getString(El("input:selected")), '<input selected="selected">').
equal(getString(El("a[href='http://example.com/']")), '<a href="http://example.com/"></a>').
equal(getString(El('a[href="http://example.com/"]')), '<a href="http://example.com/"></a>').
anyOf(getString(El("a[href='http://example.com/'][title=Link]")),
[ '<a href="http://example.com/" title="Link"></a>'
, '<a title="Link" href="http://example.com/"></a>',
it ("has txt() method").
equal(el.txt(), "").
equal(el.txt("hello"), "hello").
equal(el.txt(), "hello").
it ("has class methods").
equal(el.className, "").
equal(el.hasClass("c1"), false).
equal(el.hasClass("c2"), false).
equal(el.hasClass("c3"), false).
equal(el.addClass("c1"), el).
equal(el.hasClass("c1"), true).
equal(el.hasClass("c2"), false).
equal(el.hasClass("c3"), false).
equal(el.addClass("c2"), el).
equal(el.hasClass("c1"), true).
equal(el.hasClass("c2"), true).
equal(el.hasClass("c3"), false).
equal(el.rmClass("c3"), el).
equal(el.hasClass("c1"), true).
equal(el.hasClass("c2"), true).
equal(el.hasClass("c3"), false).
equal(el.rmClass("c2"), el).
equal(el.hasClass("c1"), true).
equal(el.hasClass("c2"), false).
equal(el.hasClass("c3"), false).
equal(el.rmClass("c1"), el).
equal(el.hasClass("c1"), false).
equal(el.hasClass("c2"), false).
equal(el.hasClass("c3"), false).
equal(el.className, "").
equal(el.toggleClass("c1"), true).
equal(el.hasClass("c1"), true).
equal(el.toggleClass("c1", true), true).
equal(el.hasClass("c1"), true).
equal(el.toggleClass("c1"), false).
equal(el.hasClass("c1"), false).
equal(el.toggleClass("c1", false), false).
equal(el.hasClass("c1"), false).
equal(el.className, "").
describe( "Haml" ).
it ("supports haml").
equal(getString(El.haml("a\n b\n i")), '<a><b><i></i></b></a>').
equal(getString(El.haml("a \n b\n i")), '<a><b><i></i></b></a>').
equal(getString(El.haml("a\n b\n i link")), '<a><b><i>link</i></b></a>').
equal(getString(El.haml("a\n b \n i link")), '<a><b><i>link</i></b></a>').
equal(getString(El.haml("a\n b\n i link>to")), '<a><b><i>link&gt;to</i></b></a>').
anyOf(getString(El.haml("a[href='#a>b']\n b.bold \n i#ital link")),
[ '<a href="#a>b"><b class=bold><i id=ital>link</i></b></a>'
, '<a href="#a>b"><b class="bold"><i id="ital">link</i></b></a>'
, '<a href="#a&gt;b"><b class="bold"><i id="ital">link</i></b></a>'
, '<a href="#a%3Eb"><b class="bold"><i id="ital">link</i></b></a>'
]).
anyOf(getString(El('a[href="http://example.com/"][title="Link to site"]')),
[ '<a href="http://example.com/" title="Link to site"></a>'
, '<a title="Link to site" href="http://example.com/"></a>'
it ("supports block expansion").
equal(getString(El.haml("a>b>i")), '<a><b><i></i></b></a>').
equal(getString(El.haml("a > b>i")), '<a><b><i></i></b></a>').
equal(getString(El.haml("a>b>i link")), '<a><b><i>link</i></b></a>').
equal(getString(El.haml("a>b > i link")), '<a><b><i>link</i></b></a>').
equal(getString(El.haml("a>b>i link>to")), '<a><b><i>link&gt;to</i></b></a>').
anyOf(getString(El.haml("a[href='#a>b']>b.bold > i#ital link")),
[ '<a href="#a>b"><b class=bold><i id=ital>link</i></b></a>'
, '<a href="#a>b"><b class="bold"><i id="ital">link</i></b></a>'
, '<a href="#a&gt;b"><b class="bold"><i id="ital">link</i></b></a>'
, '<a href="#a%3Eb"><b class="bold"><i id="ital">link</i></b></a>'
]).
it ("supports templates").
anyOf(getString(El.haml(":template t1\n .temp1 t123\nt1")),
[ '<div class=temp1>t123</div>'
, '<div class="temp1">t123</div>'
]).
anyOf(getString(El.haml(":template t2\n .temp2>b t123\nt2")),
[ '<div class=temp2><b>t123</b></div>'
, '<div class="temp2"><b>t123</b></div>'
]).
anyOf(getString(El.haml(":template t3\n .temp3\n b t123\nt3")),
[ '<div class=temp3><b>t123</b></div>'
, '<div class="temp3"><b>t123</b></div>'
]).
it ( "should render data to elements" ).
equal(getString(t1 = El.haml("a>b>i =text:hello {name}")), '<a><b><i data-bind="text:hello {name}"></i></b></a>').
equal(getString(t1.render({name:"world"})), '<a><b><i data-bind="text:hello {name}">hello world</i></b></a>').
equal(getString(t1.render({name:"moon"})), '<a><b><i data-bind="text:hello {name}">hello moon</i></b></a>').
done()

@@ -779,3 +1772,4 @@

},{"../":1,"testman":2}],4:[function(require,module,exports){
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../":1,"../haml":2,"../i18n.js":3,"browser-upgrade-lite":4,"functional-lite":5,"liquid-filters-lite":6,"testman":7}],9:[function(require,module,exports){
// shim for using process in browser

@@ -835,2 +1829,2 @@

},{}]},{},[3])
},{}]},{},[8])
global.Event = global.Event || {}
global.i18n = require("../i18n.js").i18n

@@ -20,3 +21,3 @@ require("browser-upgrade-lite")

var el, h1, h2, h3, h4, select, t1
var el, h1, h2, h3, h4, input, select, t1

@@ -30,2 +31,3 @@ require("testman").

select = El("select#id2.cl2:disabled")
input = El("input")
h1 = El("h1")

@@ -92,11 +94,11 @@ h2 = El("h2")

it ("shoult set attributes").
equal(el.set({title:"set title"}), el).
equal(el.title, "set title").
equal(el.set({title:"change title", name:"new name"}), el).
equal(el.title, "change title").
equal(el.name, "new name").
equal(el.set({title: null}), el).
equal(el.set({name: null}), el).
ok(!el.title).
ok(!el.name).
equal(input.set({id: "set_id", title:"set title"}), input).
equal(input.id, "set_id").
equal(input.title, "set title").
equal(input.set({title:"change title", name:"new name", id: "new_id"}), input).
equal(input.title, "change title").
equal(input.name, "new name").
equal(input.id, "new_id").
equal(input.set({title: null}), input).
ok(!input.title).

@@ -103,0 +105,0 @@ it ("has kill() and empty() methods").

@@ -7,3 +7,2 @@ var dom = require("dom-lite")

global.navigator = {language: "en-US"}
global.i18n = require("../i18n.js").i18n

@@ -10,0 +9,0 @@ global.document.querySelector = global.document.querySelectorAll = null

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc