Socket
Socket
Sign inDemoInstall

cash-dom

Package Overview
Dependencies
Maintainers
3
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cash-dom - npm Package Compare versions

Comparing version 3.2.0 to 4.0.0

6

CHANGELOG.md

@@ -0,1 +1,7 @@

### Version 4.0.0
- Removed `$.fn.removeData`
- Removed `$.hasData`
- `$.fn.data`: removed caching mechanism
- `$.fn.data`: added a missing TypeScript method overload
### Version 3.2.0

@@ -2,0 +8,0 @@ - Readme: updated sizes

7

dist/cash.d.ts

@@ -114,6 +114,4 @@ interface Cash {

}
interface CashStatic {
hasData(ele: HTMLElement): boolean;
}
interface Cash {
data(): plainObject | undefined;
data(name: string): any;

@@ -124,5 +122,2 @@ data(name: string, value: any): this;

interface Cash {
removeData(key: string): this;
}
interface Cash {
innerWidth(): number;

@@ -129,0 +124,0 @@ innerHeight(): number;

@@ -347,46 +347,25 @@ /* MIT https://github.com/kenwheeler/cash */

// @optional ./css.ts
const dataNamespace = '__cashData', dataAttributeRe = /^data-(.*)/;
// @require core/cash.ts
// @require ./helpers/variables.ts
function hasData(ele) {
return dataNamespace in ele;
}
cash.hasData = hasData;
// @require ./variables.ts
function getDataCache(ele) {
return ele[dataNamespace] = (ele[dataNamespace] || {});
}
// @require attributes/attr.ts
// @require ./get_data_cache.ts
// @require core/camel_case.ts
function getData(ele, key) {
const cache = getDataCache(ele);
if (key) {
if (!(key in cache)) {
let value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : cash(ele).attr(`data-${key}`);
if (value !== undefined) {
try {
value = JSON.parse(value);
}
catch (e) { }
cache[key] = value;
}
}
return cache[key];
const value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : ele.getAttribute(`data-${key}`);
try {
return JSON.parse(value);
}
return cache;
catch (_a) { }
return value;
}
// @require ./variables.ts
// @require ./get_data_cache.ts
function removeData(ele, key) {
if (key === undefined) {
delete ele[dataNamespace];
// @require core/camel_case.ts
function setData(ele, key, value) {
try {
value = JSON.stringify(value);
}
catch (_a) { }
if (ele.dataset) {
ele.dataset[camelCase(key)] = value;
}
else {
delete getDataCache(ele)[key];
ele.setAttribute(`data-${key}`, value);
}
}
// @require ./get_data_cache.ts
function setData(ele, key, value) {
getDataCache(ele)[key] = value;
}
const dataAttributeRe = /^data-(.+)/;
function data(name, value) {

@@ -396,2 +375,3 @@ if (!name) {

return;
const datas = {};
each(this[0].attributes, (i, attr) => {

@@ -401,5 +381,5 @@ const match = attr.name.match(dataAttributeRe);

return;
this.data(match[1]);
datas[match[1]] = this.data(match[1]);
});
return getData(this[0]);
return datas;
}

@@ -417,7 +397,3 @@ if (isString(name)) {

Cash.prototype.data = data;
Cash.prototype.removeData = function (key) {
return this.each((i, ele) => removeData(ele, key));
};
// @optional ./data.ts
// @optional ./remove_data.ts
// @require css/helpers/compute_style_int.ts

@@ -424,0 +400,0 @@ function getExtraSpace(ele, xAxis) {

@@ -448,56 +448,29 @@ /* MIT https://github.com/kenwheeler/cash */

Cash.prototype.css = css; // @optional ./css.ts
// @require core/camel_case.ts
var dataNamespace = '__cashData',
dataAttributeRe = /^data-(.*)/; // @require core/cash.ts
// @require ./helpers/variables.ts
function hasData(ele) {
return dataNamespace in ele;
}
cash.hasData = hasData; // @require ./variables.ts
function getDataCache(ele) {
return ele[dataNamespace] = ele[dataNamespace] || {};
} // @require attributes/attr.ts
// @require ./get_data_cache.ts
function getData(ele, key) {
var cache = getDataCache(ele);
var value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : ele.getAttribute("data-" + key);
if (key) {
if (!(key in cache)) {
var value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase(key)] : cash(ele).attr("data-" + key);
try {
return JSON.parse(value);
} catch (_a) {}
if (value !== undefined) {
try {
value = JSON.parse(value);
} catch (e) {}
return value;
} // @require core/camel_case.ts
cache[key] = value;
}
}
return cache[key];
}
function setData(ele, key, value) {
try {
value = JSON.stringify(value);
} catch (_a) {}
return cache;
} // @require ./variables.ts
// @require ./get_data_cache.ts
function removeData(ele, key) {
if (key === undefined) {
delete ele[dataNamespace];
if (ele.dataset) {
ele.dataset[camelCase(key)] = value;
} else {
delete getDataCache(ele)[key];
ele.setAttribute("data-" + key, value);
}
} // @require ./get_data_cache.ts
}
var dataAttributeRe = /^data-(.+)/;
function setData(ele, key, value) {
getDataCache(ele)[key] = value;
}
function data(name, value) {

@@ -508,9 +481,9 @@ var _this = this;

if (!this[0]) return;
var datas_1 = {};
each(this[0].attributes, function (i, attr) {
var match = attr.name.match(dataAttributeRe);
if (!match) return;
_this.data(match[1]);
datas_1[match[1]] = _this.data(match[1]);
});
return getData(this[0]);
return datas_1;
}

@@ -532,13 +505,5 @@

Cash.prototype.data = data;
Cash.prototype.removeData = function (key) {
return this.each(function (i, ele) {
return removeData(ele, key);
});
}; // @optional ./data.ts
// @optional ./remove_data.ts
Cash.prototype.data = data; // @optional ./data.ts
// @require css/helpers/compute_style_int.ts
function getExtraSpace(ele, xAxis) {

@@ -545,0 +510,0 @@ return computeStyleInt(ele, "border" + (xAxis ? 'Left' : 'Top') + "Width") + computeStyleInt(ele, "padding" + (xAxis ? 'Left' : 'Top')) + computeStyleInt(ele, "padding" + (xAxis ? 'Right' : 'Bottom')) + computeStyleInt(ele, "border" + (xAxis ? 'Right' : 'Bottom') + "Width");

/* MIT https://github.com/kenwheeler/cash */
(function(){
'use strict';var e=document,f=window,k=e.createElement("div"),l=Array.prototype,m=l.filter,n=l.indexOf,aa=l.map,q=l.push,r=l.reverse,u=l.slice,v=l.some,ba=l.splice,ca=/^#[\w-]*$/,da=/^\.[\w-]*$/,ea=/<.+>/,fa=/^\w+$/;function w(a,b){void 0===b&&(b=e);return b!==e&&1!==b.nodeType&&9!==b.nodeType?[]:da.test(a)?b.getElementsByClassName(a.slice(1)):fa.test(a)?b.getElementsByTagName(a):b.querySelectorAll(a)}
var x=function(){function a(a,c){void 0===c&&(c=e);if(a){if(a instanceof x)return a;var b=a;if(y(a)){if(b=c instanceof x?c[0]:c,b=ca.test(a)?b.getElementById(a.slice(1)):ea.test(a)?A(a):w(a,b),!b)return}else if(B(a))return this.ready(a);if(b.nodeType||b===f)b=[b];this.length=b.length;a=0;for(c=this.length;a<c;a++)this[a]=b[a]}}a.prototype.init=function(b,c){return new a(b,c)};return a}(),C=x.prototype.init;C.fn=C.prototype=x.prototype;x.prototype.length=0;x.prototype.splice=ba;
"function"===typeof Symbol&&(x.prototype[Symbol.iterator]=Array.prototype[Symbol.iterator]);x.prototype.get=function(a){return void 0===a?u.call(this):this[0>a?a+this.length:a]};x.prototype.eq=function(a){return C(this.get(a))};x.prototype.first=function(){return this.eq(0)};x.prototype.last=function(){return this.eq(-1)};x.prototype.map=function(a){return C(aa.call(this,function(b,c){return a.call(b,c,b)}))};x.prototype.slice=function(){return C(u.apply(this,arguments))};var ha=/-([a-z])/g;
function ia(a,b){return b.toUpperCase()}function D(a){return a.replace(ha,ia)}C.camelCase=D;function E(a,b){for(var c=0,d=a.length;c<d&&!1!==b.call(a[c],c,a[c]);c++);}C.each=E;x.prototype.each=function(a){E(this,a);return this};x.prototype.removeProp=function(a){return this.each(function(b,c){delete c[a]})};function F(a){for(var b=1;b<arguments.length;b++);b=arguments;for(var c=b.length,d=2>c?0:1;d<c;d++)for(var g in b[d])a[g]=b[d][g];return a}x.prototype.extend=function(a){return F(C.fn,a)};
C.extend=F;var G=1;C.guid=G;function H(a,b){var c=a&&(a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector);return!!c&&c.call(a,b)}C.matches=H;function I(a,b,c){for(var d=[],g=0,h=a.length;g<h;g++)for(var p=a[g][b];null!=p;){d.push(p);if(!c)break;p=p[b]}return d}function B(a){return"function"===typeof a}function y(a){return"string"===typeof a}function ja(a){return!isNaN(parseFloat(a))&&isFinite(a)}var J=Array.isArray;C.isFunction=B;C.isString=y;
C.isNumeric=ja;C.isArray=J;x.prototype.prop=function(a,b){if(a){if(y(a))return 2>arguments.length?this[0]&&this[0][a]:this.each(function(c,g){g[a]=b});for(var c in a)this.prop(c,a[c]);return this}};function K(a){return y(a)?function(b,c){return H(c,a)}:B(a)?a:a instanceof x?function(b,c){return a.is(c)}:function(b,c){return c===a}}x.prototype.filter=function(a){if(!a)return C();var b=K(a);return C(m.call(this,function(a,d){return b.call(a,d,a)}))};
function L(a,b){return b&&a.length?a.filter(b):a}var ka=/\S+/g;function M(a){return y(a)?a.match(ka)||[]:[]}x.prototype.hasClass=function(a){return a&&v.call(this,function(b){return b.classList.contains(a)})};x.prototype.removeAttr=function(a){var b=M(a);return b.length?this.each(function(a,d){E(b,function(a,b){d.removeAttribute(b)})}):this};
x.prototype.attr=function(a,b){if(a){if(y(a)){if(2>arguments.length){if(!this[0])return;var c=this[0].getAttribute(a);return null===c?void 0:c}return null===b?this.removeAttr(a):this.each(function(c,g){g.setAttribute(a,b)})}for(c in a)this.attr(c,a[c]);return this}};x.prototype.toggleClass=function(a,b){var c=M(a),d=void 0!==b;return c.length?this.each(function(a,h){E(c,function(a,c){d?b?h.classList.add(c):h.classList.remove(c):h.classList.toggle(c)})}):this};
x.prototype.addClass=function(a){return this.toggleClass(a,!0)};x.prototype.removeClass=function(a){return arguments.length?this.toggleClass(a,!1):this.attr("class","")};function N(a){return 1<a.length?m.call(a,function(a,c,d){return n.call(d,a)===c}):a}C.unique=N;x.prototype.add=function(a,b){return C(N(this.get().concat(C(a,b).get())))};function O(a,b,c){if(1===a.nodeType&&b)return a=f.getComputedStyle(a,null),b?c?a.getPropertyValue(b)||void 0:a[b]:a}
function P(a,b){return parseInt(O(a,b),10)||0}var Q=/^--/,R={},la=k.style,ma=["webkit","moz","ms","o"];function na(a,b){void 0===b&&(b=Q.test(a));if(b)return a;if(!R[a]){b=D(a);var c=""+b.charAt(0).toUpperCase()+b.slice(1);b=(b+" "+ma.join(c+" ")+c).split(" ");E(b,function(b,c){if(c in la)return R[a]=c,!1})}return R[a]}C.prefixedProp=na;var oa={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};
function pa(a,b,c){void 0===c&&(c=Q.test(a));return c||oa[a]||!ja(b)?b:b+"px"}x.prototype.css=function(a,b){if(y(a)){var c=Q.test(a);a=na(a,c);if(2>arguments.length)return this[0]&&O(this[0],a,c);if(!a)return this;b=pa(a,b,c);return this.each(function(d,h){1===h.nodeType&&(c?h.style.setProperty(a,b):h.style[a]=b)})}for(var d in a)this.css(d,a[d]);return this};var qa=/^data-(.*)/;C.hasData=function(a){return"__cashData"in a};function S(a){return a.__cashData=a.__cashData||{}}
function ra(a,b){var c=S(a);if(b){if(!(b in c)&&(a=a.dataset?a.dataset[b]||a.dataset[D(b)]:C(a).attr("data-"+b),void 0!==a)){try{a=JSON.parse(a)}catch(d){}c[b]=a}return c[b]}return c}x.prototype.data=function(a,b){var c=this;if(!a){if(!this[0])return;E(this[0].attributes,function(a,b){(a=b.name.match(qa))&&c.data(a[1])});return ra(this[0])}if(y(a))return void 0===b?this[0]&&ra(this[0],a):this.each(function(c,d){S(d)[a]=b});for(var d in a)this.data(d,a[d]);return this};
x.prototype.removeData=function(a){return this.each(function(b,c){void 0===a?delete c.__cashData:delete S(c)[a]})};function sa(a,b){return P(a,"border"+(b?"Left":"Top")+"Width")+P(a,"padding"+(b?"Left":"Top"))+P(a,"padding"+(b?"Right":"Bottom"))+P(a,"border"+(b?"Right":"Bottom")+"Width")}E(["Width","Height"],function(a,b){x.prototype["inner"+b]=function(){if(this[0])return this[0]===f?f["inner"+b]:this[0]["client"+b]}});
E(["width","height"],function(a,b){x.prototype[b]=function(c){if(!this[0])return void 0===c?void 0:this;if(!arguments.length)return this[0]===f?this[0][D("outer-"+b)]:this[0].getBoundingClientRect()[b]-sa(this[0],!a);var d=parseInt(c,10);return this.each(function(c,h){1===h.nodeType&&(c=O(h,"boxSizing"),h.style[b]=pa(b,d+("border-box"===c?sa(h,!a):0)))})}});
E(["Width","Height"],function(a,b){x.prototype["outer"+b]=function(c){if(this[0])return this[0]===f?f["outer"+b]:this[0]["offset"+b]+(c?P(this[0],"margin"+(a?"Top":"Left"))+P(this[0],"margin"+(a?"Bottom":"Right")):0)}});var T={};
x.prototype.toggle=function(a){return this.each(function(b,c){if(a=void 0!==a?a:"none"===O(c,"display")){if(c.style.display="","none"===O(c,"display")){b=c.style;c=c.tagName;if(T[c])c=T[c];else{var d=e.createElement(c);e.body.appendChild(d);var g=O(d,"display");e.body.removeChild(d);c=T[c]="none"!==g?g:"block"}b.display=c}}else c.style.display="none"})};x.prototype.hide=function(){return this.toggle(!1)};x.prototype.show=function(){return this.toggle(!0)};
function ta(a,b){return!b||!v.call(b,function(b){return 0>a.indexOf(b)})}var U={focus:"focusin",blur:"focusout"},ua={mouseenter:"mouseover",mouseleave:"mouseout"},va=/^(?:mouse|pointer|contextmenu|drag|drop|click|dblclick)/i;function wa(a,b,c,d,g){g.guid=g.guid||G++;var h=a.__cashEvents=a.__cashEvents||{};h[b]=h[b]||[];h[b].push([c,d,g]);a.addEventListener(b,g)}function V(a){a=a.split(".");return[a[0],a.slice(1).sort()]}
function W(a,b,c,d,g){var h=a.__cashEvents=a.__cashEvents||{};if(b)h[b]&&(h[b]=h[b].filter(function(h){var p=h[0],za=h[1];h=h[2];if(g&&h.guid!==g.guid||!ta(p,c)||d&&d!==za)return!0;a.removeEventListener(b,h)}));else{for(b in h)W(a,b,c,d,g);delete a.__cashEvents}}x.prototype.off=function(a,b,c){var d=this;void 0===a?this.each(function(a,b){return W(b)}):(B(b)&&(c=b,b=""),E(M(a),function(a,h){a=V(ua[h]||U[h]||h);var g=a[0],z=a[1];d.each(function(a,d){return W(d,g,z,b,c)})}));return this};
x.prototype.on=function(a,b,c,d){var g=this;if(!y(a)){for(var h in a)this.on(h,b,a[h]);return this}B(b)&&(c=b,b="");E(M(a),function(a,h){a=V(ua[h]||U[h]||h);var p=a[0],z=a[1];g.each(function(a,h){a=function Aa(a){if(!a.namespace||ta(z,a.namespace.split("."))){var g=h;if(b){for(var t=a.target;!H(t,b);){if(t===h)return;t=t.parentNode;if(!t)return}g=t;a.__delegate=!0}a.__delegate&&Object.defineProperty(a,"currentTarget",{configurable:!0,get:function(){return g}});t=c.call(g,a,a.data);d&&W(h,p,z,b,Aa);
!1===t&&(a.preventDefault(),a.stopPropagation())}};a.guid=c.guid=c.guid||G++;wa(h,p,z,b,a)})});return this};x.prototype.one=function(a,b,c){return this.on(a,b,c,!0)};x.prototype.ready=function(a){function b(){return a(C)}"loading"!==e.readyState?setTimeout(b):e.addEventListener("DOMContentLoaded",b);return this};
x.prototype.trigger=function(a,b){var c=a;if(y(a)){var d=V(a);a=d[0];d=d[1];var g=va.test(a)?"MouseEvents":"HTMLEvents";c=e.createEvent(g);c.initEvent(a,!0,!0);c.namespace=d.join(".")}c.data=b;var h=c.type in U;return this.each(function(a,b){if(h&&B(b[c.type]))b[c.type]();else b.dispatchEvent(c)})};function xa(a){return a.multiple?I(m.call(a.options,function(a){return a.selected&&!a.disabled&&!a.parentNode.disabled}),"value"):a.value||""}var ya=/%20/g,Ba=/file|reset|submit|button|image/i,Ca=/radio|checkbox/i;
x.prototype.serialize=function(){var a="";this.each(function(b,c){E(c.elements||[c],function(b,c){c.disabled||!c.name||"FIELDSET"===c.tagName||Ba.test(c.type)||Ca.test(c.type)&&!c.checked||(b=xa(c),void 0!==b&&(b=J(b)?b:[b],E(b,function(b,d){b=a;d="&"+encodeURIComponent(c.name)+"="+encodeURIComponent(d).replace(ya,"+");a=b+d})))})});return a.substr(1)};
x.prototype.val=function(a){return void 0===a?this[0]&&xa(this[0]):this.each(function(b,c){if("SELECT"===c.tagName){var d=J(a)?a:null===a?[]:[a];E(c.options,function(a,b){b.selected=0<=d.indexOf(b.value)})}else c.value=null===a?"":a})};x.prototype.clone=function(){return this.map(function(a,b){return b.cloneNode(!0)})};x.prototype.detach=function(){return this.each(function(a,b){b.parentNode&&b.parentNode.removeChild(b)})};var Da=/^\s*<(\w+)[^>]*>/,Ea=/^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/,X;
function A(a){if(!X){var b=e.createElement("table"),c=e.createElement("tr");X={"*":k,tr:e.createElement("tbody"),td:c,th:c,thead:b,tbody:b,tfoot:b}}if(!y(a))return[];if(Ea.test(a))return[e.createElement(RegExp.$1)];b=Da.test(a)&&RegExp.$1;b=X[b]||X["*"];b.innerHTML=a;return C(b.childNodes).detach().get()}C.parseHTML=A;x.prototype.empty=function(){var a=this[0];if(a)for(;a.firstChild;)a.removeChild(a.firstChild);return this};
x.prototype.html=function(a){return void 0===a?this[0]&&this[0].innerHTML:this.each(function(b,c){c.innerHTML=a})};x.prototype.remove=function(){return this.detach().off()};x.prototype.text=function(a){return void 0===a?this[0]?this[0].textContent:"":this.each(function(b,c){c.textContent=a})};x.prototype.unwrap=function(){this.parent().each(function(a,b){a=C(b);a.replaceWith(a.children())});return this};var Fa=e.documentElement;
x.prototype.offset=function(){var a=this[0];if(a)return a=a.getBoundingClientRect(),{top:a.top+f.pageYOffset-Fa.clientTop,left:a.left+f.pageXOffset-Fa.clientLeft}};x.prototype.offsetParent=function(){return C(this[0]&&this[0].offsetParent)};x.prototype.position=function(){var a=this[0];if(a)return{left:a.offsetLeft,top:a.offsetTop}};x.prototype.children=function(a){var b=[];this.each(function(a,d){q.apply(b,d.children)});return L(C(N(b)),a)};
x.prototype.contents=function(){var a=[];this.each(function(b,c){q.apply(a,"IFRAME"===c.tagName?[c.contentDocument]:c.childNodes)});return C(N(a))};x.prototype.find=function(a){for(var b=[],c=0,d=this.length;c<d;c++){var g=w(a,this[c]);g.length&&q.apply(b,g)}return C(N(b))};var Ga=/^$|^module$|\/(?:java|ecma)script/i,Ha=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
function Y(a){a=C(a);a.filter("script").add(a.find("script")).each(function(a,c){!c.src&&Ga.test(c.type)&&c.ownerDocument.documentElement.contains(c)&&eval(c.textContent.replace(Ha,""))})}function Z(a,b,c){E(a,function(a,g){E(b,function(b,d){b=a?d.cloneNode(!0):d;c?g.insertBefore(b,c&&g.firstChild):g.appendChild(b);Y(b)})})}x.prototype.append=function(){var a=this;E(arguments,function(b,c){Z(a,C(c))});return this};x.prototype.appendTo=function(a){Z(C(a),this);return this};
x.prototype.insertAfter=function(a){var b=this;C(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,g){b=a?g.cloneNode(!0):g;c.insertBefore(b,d.nextSibling);Y(b)})});return this};x.prototype.after=function(){var a=this;E(r.apply(arguments),function(b,c){r.apply(C(c).slice()).insertAfter(a)});return this};x.prototype.insertBefore=function(a){var b=this;C(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,g){b=a?g.cloneNode(!0):g;c.insertBefore(b,d);Y(b)})});return this};
x.prototype.before=function(){var a=this;E(arguments,function(b,c){C(c).insertBefore(a)});return this};x.prototype.prepend=function(){var a=this;E(arguments,function(b,c){Z(a,C(c),!0)});return this};x.prototype.prependTo=function(a){Z(C(a),r.apply(this.slice()),!0);return this};x.prototype.replaceWith=function(a){return this.before(a).remove()};x.prototype.replaceAll=function(a){C(a).replaceWith(this);return this};
x.prototype.wrapAll=function(a){if(this[0]){a=C(a);this.first().before(a);for(a=a[0];a.children.length;)a=a.firstElementChild;this.appendTo(a)}return this};x.prototype.wrap=function(a){return this.each(function(b,c){var d=C(a)[0];C(c).wrapAll(b?d.cloneNode(!0):d)})};x.prototype.wrapInner=function(a){return this.each(function(b,c){b=C(c);c=b.contents();c.length?c.wrapAll(a):b.append(a)})};
x.prototype.has=function(a){var b=y(a)?function(b,d){return!!w(a,d).length}:function(b,d){return d.contains(a)};return this.filter(b)};x.prototype.is=function(a){if(!a||!this[0])return!1;var b=K(a),c=!1;this.each(function(a,g){c=b.call(g,a,g);return!c});return c};x.prototype.next=function(a,b){return L(C(N(I(this,"nextElementSibling",b))),a)};x.prototype.nextAll=function(a){return this.next(a,!0)};
x.prototype.not=function(a){if(!a||!this[0])return this;var b=K(a);return this.filter(function(a,d){return!b.call(d,a,d)})};x.prototype.parent=function(a){return L(C(N(I(this,"parentNode"))),a)};x.prototype.index=function(a){var b=a?C(a)[0]:this[0];a=a?this:C(b).parent().children();return n.call(a,b)};x.prototype.closest=function(a){if(!a||!this[0])return C();var b=this.filter(a);return b.length?b:this.parent().closest(a)};
x.prototype.parents=function(a){return L(C(N(I(this,"parentElement",!0))),a)};x.prototype.prev=function(a,b){return L(C(N(I(this,"previousElementSibling",b))),a)};x.prototype.prevAll=function(a){return this.prev(a,!0)};x.prototype.siblings=function(a){var b=this[0];return L(this.parent().children().filter(function(a,d){return d!==b}),a)};"undefined"!==typeof exports?module.exports=C:f.cash=f.$=C;
'use strict';var e=document,f=window,k=e.createElement("div"),l=Array.prototype,m=l.filter,n=l.indexOf,aa=l.map,q=l.push,r=l.reverse,u=l.slice,v=l.some,ba=l.splice,ca=/^#[\w-]*$/,da=/^\.[\w-]*$/,ea=/<.+>/,fa=/^\w+$/;function x(a,b){void 0===b&&(b=e);return b!==e&&1!==b.nodeType&&9!==b.nodeType?[]:da.test(a)?b.getElementsByClassName(a.slice(1)):fa.test(a)?b.getElementsByTagName(a):b.querySelectorAll(a)}
var y=function(){function a(a,c){void 0===c&&(c=e);if(a){if(a instanceof y)return a;var b=a;if(z(a)){if(b=c instanceof y?c[0]:c,b=ca.test(a)?b.getElementById(a.slice(1)):ea.test(a)?A(a):x(a,b),!b)return}else if(B(a))return this.ready(a);if(b.nodeType||b===f)b=[b];this.length=b.length;a=0;for(c=this.length;a<c;a++)this[a]=b[a]}}a.prototype.init=function(b,c){return new a(b,c)};return a}(),C=y.prototype.init;C.fn=C.prototype=y.prototype;y.prototype.length=0;y.prototype.splice=ba;
"function"===typeof Symbol&&(y.prototype[Symbol.iterator]=Array.prototype[Symbol.iterator]);y.prototype.get=function(a){return void 0===a?u.call(this):this[0>a?a+this.length:a]};y.prototype.eq=function(a){return C(this.get(a))};y.prototype.first=function(){return this.eq(0)};y.prototype.last=function(){return this.eq(-1)};y.prototype.map=function(a){return C(aa.call(this,function(b,c){return a.call(b,c,b)}))};y.prototype.slice=function(){return C(u.apply(this,arguments))};var ha=/-([a-z])/g;
function ia(a,b){return b.toUpperCase()}function D(a){return a.replace(ha,ia)}C.camelCase=D;function E(a,b){for(var c=0,d=a.length;c<d&&!1!==b.call(a[c],c,a[c]);c++);}C.each=E;y.prototype.each=function(a){E(this,a);return this};y.prototype.removeProp=function(a){return this.each(function(b,c){delete c[a]})};function F(a){for(var b=1;b<arguments.length;b++);b=arguments;for(var c=b.length,d=2>c?0:1;d<c;d++)for(var g in b[d])a[g]=b[d][g];return a}y.prototype.extend=function(a){return F(C.fn,a)};
C.extend=F;var G=1;C.guid=G;function H(a,b){var c=a&&(a.matches||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector);return!!c&&c.call(a,b)}C.matches=H;function I(a,b,c){for(var d=[],g=0,h=a.length;g<h;g++)for(var p=a[g][b];null!=p;){d.push(p);if(!c)break;p=p[b]}return d}function B(a){return"function"===typeof a}function z(a){return"string"===typeof a}function J(a){return!isNaN(parseFloat(a))&&isFinite(a)}var K=Array.isArray;C.isFunction=B;C.isString=z;
C.isNumeric=J;C.isArray=K;y.prototype.prop=function(a,b){if(a){if(z(a))return 2>arguments.length?this[0]&&this[0][a]:this.each(function(c,g){g[a]=b});for(var c in a)this.prop(c,a[c]);return this}};function L(a){return z(a)?function(b,c){return H(c,a)}:B(a)?a:a instanceof y?function(b,c){return a.is(c)}:function(b,c){return c===a}}y.prototype.filter=function(a){if(!a)return C();var b=L(a);return C(m.call(this,function(a,d){return b.call(a,d,a)}))};function M(a,b){return b&&a.length?a.filter(b):a}
var ja=/\S+/g;function N(a){return z(a)?a.match(ja)||[]:[]}y.prototype.hasClass=function(a){return a&&v.call(this,function(b){return b.classList.contains(a)})};y.prototype.removeAttr=function(a){var b=N(a);return b.length?this.each(function(a,d){E(b,function(a,b){d.removeAttribute(b)})}):this};
y.prototype.attr=function(a,b){if(a){if(z(a)){if(2>arguments.length){if(!this[0])return;var c=this[0].getAttribute(a);return null===c?void 0:c}return null===b?this.removeAttr(a):this.each(function(c,g){g.setAttribute(a,b)})}for(c in a)this.attr(c,a[c]);return this}};y.prototype.toggleClass=function(a,b){var c=N(a),d=void 0!==b;return c.length?this.each(function(a,h){E(c,function(a,c){d?b?h.classList.add(c):h.classList.remove(c):h.classList.toggle(c)})}):this};
y.prototype.addClass=function(a){return this.toggleClass(a,!0)};y.prototype.removeClass=function(a){return arguments.length?this.toggleClass(a,!1):this.attr("class","")};function O(a){return 1<a.length?m.call(a,function(a,c,d){return n.call(d,a)===c}):a}C.unique=O;y.prototype.add=function(a,b){return C(O(this.get().concat(C(a,b).get())))};function P(a,b,c){if(1===a.nodeType&&b)return a=f.getComputedStyle(a,null),b?c?a.getPropertyValue(b)||void 0:a[b]:a}
function Q(a,b){return parseInt(P(a,b),10)||0}var R=/^--/,S={},ka=k.style,la=["webkit","moz","ms","o"];function ma(a,b){void 0===b&&(b=R.test(a));if(b)return a;if(!S[a]){b=D(a);var c=""+b.charAt(0).toUpperCase()+b.slice(1);b=(b+" "+la.join(c+" ")+c).split(" ");E(b,function(b,c){if(c in ka)return S[a]=c,!1})}return S[a]}C.prefixedProp=ma;var na={animationIterationCount:!0,columnCount:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0};
function oa(a,b,c){void 0===c&&(c=R.test(a));return c||na[a]||!J(b)?b:b+"px"}y.prototype.css=function(a,b){if(z(a)){var c=R.test(a);a=ma(a,c);if(2>arguments.length)return this[0]&&P(this[0],a,c);if(!a)return this;b=oa(a,b,c);return this.each(function(d,h){1===h.nodeType&&(c?h.style.setProperty(a,b):h.style[a]=b)})}for(var d in a)this.css(d,a[d]);return this};function pa(a,b){a=a.dataset?a.dataset[b]||a.dataset[D(b)]:a.getAttribute("data-"+b);try{return JSON.parse(a)}catch(c){}return a}var qa=/^data-(.+)/;
y.prototype.data=function(a,b){var c=this;if(!a){if(!this[0])return;var d={};E(this[0].attributes,function(a,b){(a=b.name.match(qa))&&(d[a[1]]=c.data(a[1]))});return d}if(z(a))return void 0===b?this[0]&&pa(this[0],a):this.each(function(c,d){c=b;try{c=JSON.stringify(c)}catch(w){}d.dataset?d.dataset[D(a)]=c:d.setAttribute("data-"+a,c)});for(var g in a)this.data(g,a[g]);return this};
function ra(a,b){return Q(a,"border"+(b?"Left":"Top")+"Width")+Q(a,"padding"+(b?"Left":"Top"))+Q(a,"padding"+(b?"Right":"Bottom"))+Q(a,"border"+(b?"Right":"Bottom")+"Width")}E(["Width","Height"],function(a,b){y.prototype["inner"+b]=function(){if(this[0])return this[0]===f?f["inner"+b]:this[0]["client"+b]}});
E(["width","height"],function(a,b){y.prototype[b]=function(c){if(!this[0])return void 0===c?void 0:this;if(!arguments.length)return this[0]===f?this[0][D("outer-"+b)]:this[0].getBoundingClientRect()[b]-ra(this[0],!a);var d=parseInt(c,10);return this.each(function(c,h){1===h.nodeType&&(c=P(h,"boxSizing"),h.style[b]=oa(b,d+("border-box"===c?ra(h,!a):0)))})}});
E(["Width","Height"],function(a,b){y.prototype["outer"+b]=function(c){if(this[0])return this[0]===f?f["outer"+b]:this[0]["offset"+b]+(c?Q(this[0],"margin"+(a?"Top":"Left"))+Q(this[0],"margin"+(a?"Bottom":"Right")):0)}});var T={};
y.prototype.toggle=function(a){return this.each(function(b,c){if(a=void 0!==a?a:"none"===P(c,"display")){if(c.style.display="","none"===P(c,"display")){b=c.style;c=c.tagName;if(T[c])c=T[c];else{var d=e.createElement(c);e.body.appendChild(d);var g=P(d,"display");e.body.removeChild(d);c=T[c]="none"!==g?g:"block"}b.display=c}}else c.style.display="none"})};y.prototype.hide=function(){return this.toggle(!1)};y.prototype.show=function(){return this.toggle(!0)};
function sa(a,b){return!b||!v.call(b,function(b){return 0>a.indexOf(b)})}var U={focus:"focusin",blur:"focusout"},ta={mouseenter:"mouseover",mouseleave:"mouseout"},ua=/^(?:mouse|pointer|contextmenu|drag|drop|click|dblclick)/i;function va(a,b,c,d,g){g.guid=g.guid||G++;var h=a.__cashEvents=a.__cashEvents||{};h[b]=h[b]||[];h[b].push([c,d,g]);a.addEventListener(b,g)}function V(a){a=a.split(".");return[a[0],a.slice(1).sort()]}
function W(a,b,c,d,g){var h=a.__cashEvents=a.__cashEvents||{};if(b)h[b]&&(h[b]=h[b].filter(function(h){var p=h[0],ya=h[1];h=h[2];if(g&&h.guid!==g.guid||!sa(p,c)||d&&d!==ya)return!0;a.removeEventListener(b,h)}));else{for(b in h)W(a,b,c,d,g);delete a.__cashEvents}}y.prototype.off=function(a,b,c){var d=this;void 0===a?this.each(function(a,b){return W(b)}):(B(b)&&(c=b,b=""),E(N(a),function(a,h){a=V(ta[h]||U[h]||h);var g=a[0],w=a[1];d.each(function(a,d){return W(d,g,w,b,c)})}));return this};
y.prototype.on=function(a,b,c,d){var g=this;if(!z(a)){for(var h in a)this.on(h,b,a[h]);return this}B(b)&&(c=b,b="");E(N(a),function(a,h){a=V(ta[h]||U[h]||h);var p=a[0],w=a[1];g.each(function(a,h){a=function za(a){if(!a.namespace||sa(w,a.namespace.split("."))){var g=h;if(b){for(var t=a.target;!H(t,b);){if(t===h)return;t=t.parentNode;if(!t)return}g=t;a.__delegate=!0}a.__delegate&&Object.defineProperty(a,"currentTarget",{configurable:!0,get:function(){return g}});t=c.call(g,a,a.data);d&&W(h,p,w,b,za);
!1===t&&(a.preventDefault(),a.stopPropagation())}};a.guid=c.guid=c.guid||G++;va(h,p,w,b,a)})});return this};y.prototype.one=function(a,b,c){return this.on(a,b,c,!0)};y.prototype.ready=function(a){function b(){return a(C)}"loading"!==e.readyState?setTimeout(b):e.addEventListener("DOMContentLoaded",b);return this};
y.prototype.trigger=function(a,b){var c=a;if(z(a)){var d=V(a);a=d[0];d=d[1];var g=ua.test(a)?"MouseEvents":"HTMLEvents";c=e.createEvent(g);c.initEvent(a,!0,!0);c.namespace=d.join(".")}c.data=b;var h=c.type in U;return this.each(function(a,b){if(h&&B(b[c.type]))b[c.type]();else b.dispatchEvent(c)})};function wa(a){return a.multiple?I(m.call(a.options,function(a){return a.selected&&!a.disabled&&!a.parentNode.disabled}),"value"):a.value||""}var xa=/%20/g,Aa=/file|reset|submit|button|image/i,Ba=/radio|checkbox/i;
y.prototype.serialize=function(){var a="";this.each(function(b,c){E(c.elements||[c],function(b,c){c.disabled||!c.name||"FIELDSET"===c.tagName||Aa.test(c.type)||Ba.test(c.type)&&!c.checked||(b=wa(c),void 0!==b&&(b=K(b)?b:[b],E(b,function(b,d){b=a;d="&"+encodeURIComponent(c.name)+"="+encodeURIComponent(d).replace(xa,"+");a=b+d})))})});return a.substr(1)};
y.prototype.val=function(a){return void 0===a?this[0]&&wa(this[0]):this.each(function(b,c){if("SELECT"===c.tagName){var d=K(a)?a:null===a?[]:[a];E(c.options,function(a,b){b.selected=0<=d.indexOf(b.value)})}else c.value=null===a?"":a})};y.prototype.clone=function(){return this.map(function(a,b){return b.cloneNode(!0)})};y.prototype.detach=function(){return this.each(function(a,b){b.parentNode&&b.parentNode.removeChild(b)})};var Ca=/^\s*<(\w+)[^>]*>/,Da=/^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/,X;
function A(a){if(!X){var b=e.createElement("table"),c=e.createElement("tr");X={"*":k,tr:e.createElement("tbody"),td:c,th:c,thead:b,tbody:b,tfoot:b}}if(!z(a))return[];if(Da.test(a))return[e.createElement(RegExp.$1)];b=Ca.test(a)&&RegExp.$1;b=X[b]||X["*"];b.innerHTML=a;return C(b.childNodes).detach().get()}C.parseHTML=A;y.prototype.empty=function(){var a=this[0];if(a)for(;a.firstChild;)a.removeChild(a.firstChild);return this};
y.prototype.html=function(a){return void 0===a?this[0]&&this[0].innerHTML:this.each(function(b,c){c.innerHTML=a})};y.prototype.remove=function(){return this.detach().off()};y.prototype.text=function(a){return void 0===a?this[0]?this[0].textContent:"":this.each(function(b,c){c.textContent=a})};y.prototype.unwrap=function(){this.parent().each(function(a,b){a=C(b);a.replaceWith(a.children())});return this};var Ea=e.documentElement;
y.prototype.offset=function(){var a=this[0];if(a)return a=a.getBoundingClientRect(),{top:a.top+f.pageYOffset-Ea.clientTop,left:a.left+f.pageXOffset-Ea.clientLeft}};y.prototype.offsetParent=function(){return C(this[0]&&this[0].offsetParent)};y.prototype.position=function(){var a=this[0];if(a)return{left:a.offsetLeft,top:a.offsetTop}};y.prototype.children=function(a){var b=[];this.each(function(a,d){q.apply(b,d.children)});return M(C(O(b)),a)};
y.prototype.contents=function(){var a=[];this.each(function(b,c){q.apply(a,"IFRAME"===c.tagName?[c.contentDocument]:c.childNodes)});return C(O(a))};y.prototype.find=function(a){for(var b=[],c=0,d=this.length;c<d;c++){var g=x(a,this[c]);g.length&&q.apply(b,g)}return C(O(b))};var Fa=/^$|^module$|\/(?:java|ecma)script/i,Ga=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
function Y(a){a=C(a);a.filter("script").add(a.find("script")).each(function(a,c){!c.src&&Fa.test(c.type)&&c.ownerDocument.documentElement.contains(c)&&eval(c.textContent.replace(Ga,""))})}function Z(a,b,c){E(a,function(a,g){E(b,function(b,d){b=a?d.cloneNode(!0):d;c?g.insertBefore(b,c&&g.firstChild):g.appendChild(b);Y(b)})})}y.prototype.append=function(){var a=this;E(arguments,function(b,c){Z(a,C(c))});return this};y.prototype.appendTo=function(a){Z(C(a),this);return this};
y.prototype.insertAfter=function(a){var b=this;C(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,g){b=a?g.cloneNode(!0):g;c.insertBefore(b,d.nextSibling);Y(b)})});return this};y.prototype.after=function(){var a=this;E(r.apply(arguments),function(b,c){r.apply(C(c).slice()).insertAfter(a)});return this};y.prototype.insertBefore=function(a){var b=this;C(a).each(function(a,d){var c=d.parentNode;c&&b.each(function(b,g){b=a?g.cloneNode(!0):g;c.insertBefore(b,d);Y(b)})});return this};
y.prototype.before=function(){var a=this;E(arguments,function(b,c){C(c).insertBefore(a)});return this};y.prototype.prepend=function(){var a=this;E(arguments,function(b,c){Z(a,C(c),!0)});return this};y.prototype.prependTo=function(a){Z(C(a),r.apply(this.slice()),!0);return this};y.prototype.replaceWith=function(a){return this.before(a).remove()};y.prototype.replaceAll=function(a){C(a).replaceWith(this);return this};
y.prototype.wrapAll=function(a){if(this[0]){a=C(a);this.first().before(a);for(a=a[0];a.children.length;)a=a.firstElementChild;this.appendTo(a)}return this};y.prototype.wrap=function(a){return this.each(function(b,c){var d=C(a)[0];C(c).wrapAll(b?d.cloneNode(!0):d)})};y.prototype.wrapInner=function(a){return this.each(function(b,c){b=C(c);c=b.contents();c.length?c.wrapAll(a):b.append(a)})};
y.prototype.has=function(a){var b=z(a)?function(b,d){return!!x(a,d).length}:function(b,d){return d.contains(a)};return this.filter(b)};y.prototype.is=function(a){if(!a||!this[0])return!1;var b=L(a),c=!1;this.each(function(a,g){c=b.call(g,a,g);return!c});return c};y.prototype.next=function(a,b){return M(C(O(I(this,"nextElementSibling",b))),a)};y.prototype.nextAll=function(a){return this.next(a,!0)};
y.prototype.not=function(a){if(!a||!this[0])return this;var b=L(a);return this.filter(function(a,d){return!b.call(d,a,d)})};y.prototype.parent=function(a){return M(C(O(I(this,"parentNode"))),a)};y.prototype.index=function(a){var b=a?C(a)[0]:this[0];a=a?this:C(b).parent().children();return n.call(a,b)};y.prototype.closest=function(a){if(!a||!this[0])return C();var b=this.filter(a);return b.length?b:this.parent().closest(a)};
y.prototype.parents=function(a){return M(C(O(I(this,"parentElement",!0))),a)};y.prototype.prev=function(a,b){return M(C(O(I(this,"previousElementSibling",b))),a)};y.prototype.prevAll=function(a){return this.prev(a,!0)};y.prototype.siblings=function(a){var b=this[0];return M(this.parent().children().filter(function(a,d){return d!==b}),a)};"undefined"!==typeof exports?module.exports=C:f.cash=f.$=C;
})();

@@ -796,75 +796,32 @@

const dataNamespace = '__cashData',
dataAttributeRe = /^data-(.*)/;
// @require core/camel_case.ts
function getData ( ele: HTMLElement, key: string ) {
// @require core/cash.ts
// @require ./helpers/variables.ts
const value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase ( key )] : ele.getAttribute ( `data-${key}` );
function hasData ( ele: HTMLElement ): boolean {
return dataNamespace in ele;
}
try {
return JSON.parse ( value );
} catch {}
interface CashStatic {
hasData ( ele: HTMLElement ): boolean;
}
return value;
cash.hasData = hasData;
// @require ./variables.ts
function getDataCache ( ele: HTMLElement ): plainObject {
return ele[dataNamespace] = ( ele[dataNamespace] || {} );
}
// @require attributes/attr.ts
// @require ./get_data_cache.ts
// @require core/camel_case.ts
function getData ( ele: HTMLElement, key?: string ): plainObject {
function setData ( ele: HTMLElement, key: string, value ): void {
const cache = getDataCache ( ele );
try {
value = JSON.stringify ( value );
} catch {}
if ( key ) {
if ( ele.dataset ) {
if ( !( key in cache ) ) {
ele.dataset[camelCase ( key )] = value;
let value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase ( key )] : cash ( ele ).attr ( `data-${key}` );
if ( value !== undefined ) {
try {
value = JSON.parse ( value );
} catch ( e ) {}
cache[key] = value;
}
}
return cache[key];
}
return cache;
}
// @require ./variables.ts
// @require ./get_data_cache.ts
function removeData ( ele: HTMLElement, key: string ): void {
if ( key === undefined ) {
delete ele[dataNamespace];
} else {
delete getDataCache ( ele )[key];
ele.setAttribute ( `data-${key}`, value );

@@ -876,9 +833,5 @@ }

// @require ./get_data_cache.ts
const dataAttributeRe = /^data-(.+)/;
function setData ( ele: HTMLElement, key: string, value ): void {
getDataCache ( ele )[key] = value;
}
// @require core/cash.ts

@@ -892,2 +845,3 @@ // @require core/type_checking.ts

interface Cash {
data (): plainObject | undefined;
data ( name: string );

@@ -898,6 +852,7 @@ data ( name: string, value ): this;

function data ( this: Cash ): plainObject | undefined;
function data ( this: Cash, name: string );
function data ( this: Cash, name: string, value ): Cash;
function data ( this: Cash, name: plainObject ): Cash;
function data ( this: Cash, name: string | plainObject, value? ) {
function data ( this: Cash, name?: string | plainObject, value? ) {

@@ -908,2 +863,4 @@ if ( !name ) {

const datas = {};
each ( this[0].attributes, ( i, attr ) => {

@@ -915,7 +872,7 @@

this.data ( match[1] );
datas[match[1]] = this.data ( match[1] );
});
return getData ( this[0] );
return datas;

@@ -945,17 +902,3 @@ }

// @require core/cash.ts
// @require collection/each.ts
// @require ./helpers/remove_data.ts
interface Cash {
removeData ( key: string ): this;
}
Cash.prototype.removeData = function ( this: Cash, key: string ) {
return this.each ( ( i, ele ) => removeData ( ele, key ) );
};
// @optional ./data.ts
// @optional ./remove_data.ts

@@ -962,0 +905,0 @@

@@ -27,2 +27,6 @@

### Data caching
In jQuery the `$.fn.data` function caches retrieved values, and doesn't refresh them when they are updated outside of jQuery (e.g. via the `dataset` API), this makes jQuery's `$.fn.data` function unusable with libraries like React. Cash doesn't implement such caching functionality and doesn't have this problem, the retrieved values are always fresh.
### Events

@@ -29,0 +33,0 @@

{
"name": "cash-dom",
"description": "An absurdly small jQuery alternative for modern browsers.",
"version": "3.2.0",
"version": "4.0.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "./dist/cash.js",

@@ -33,6 +33,6 @@

Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/3.2.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@3.2.0/dist/cash.min.js) and use it like this:
Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/4.0.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@4.0.0/dist/cash.min.js) and use it like this:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/3.2.0/cash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/4.0.0/cash.min.js"></script>
<script>

@@ -82,14 +82,14 @@ $(function () {

| Attributes | Collection | CSS | Data | Dimensions | Effects |
| ------------------------------------ | -------------------------- | -------------------- | ---------------------------------- | ------------------------------------ | -------------------------- |
| [fn.addClass ()](#fnaddclass-) | [fn.add ()](#fnadd-) | [fn.css ()](#fncss-) | [fn.data ()](#fndata-) | [fn.height ()](#fnheight-) | [fn.hide ()](#fnhide-) |
| [fn.attr ()](#fnattr-) | [fn.each ()](#fneach-) | | [fn.removeData ()](#fnremovedata-) | [fn.innerHeight ()](#fninnerheight-) | [fn.show ()](#fnshow-) |
| [fn.hasClass ()](#fnhasclass-) | [fn.eq ()](#fneq-) | | | [fn.innerWidth ()](#fninnerwidth-) | [fn.toggle ()](#fntoggle-) |
| [fn.prop ()](#fnprop-) | [fn.filter ()](#fnfilter-) | | | [fn.outerHeight ()](#fnouterheight-) | |
| [fn.removeAttr ()](#fnremoveattr-) | [fn.first ()](#fnfirst-) | | | [fn.outerWidth ()](#fnouterwidth-) | |
| [fn.removeClass ()](#fnremoveclass-) | [fn.get ()](#fnget-) | | | [fn.width ()](#fnwidth-) | |
| [fn.removeProp ()](#fnremoveprop-) | [fn.index ()](#fnindex-) | | | | |
| [fn.toggleClass ()](#fntoggleclass-) | [fn.last ()](#fnlast-) | | | | |
| | [fn.map ()](#fnmap-) | | | | |
| | [fn.slice ()](#fnslice-) | | | | |
| Attributes | Collection | CSS | Data | Dimensions | Effects |
| ------------------------------------ | -------------------------- | -------------------- | ---------------------- | ------------------------------------ | -------------------------- |
| [fn.addClass ()](#fnaddclass-) | [fn.add ()](#fnadd-) | [fn.css ()](#fncss-) | [fn.data ()](#fndata-) | [fn.height ()](#fnheight-) | [fn.hide ()](#fnhide-) |
| [fn.attr ()](#fnattr-) | [fn.each ()](#fneach-) | | | [fn.innerHeight ()](#fninnerheight-) | [fn.show ()](#fnshow-) |
| [fn.hasClass ()](#fnhasclass-) | [fn.eq ()](#fneq-) | | | [fn.innerWidth ()](#fninnerwidth-) | [fn.toggle ()](#fntoggle-) |
| [fn.prop ()](#fnprop-) | [fn.filter ()](#fnfilter-) | | | [fn.outerHeight ()](#fnouterheight-) | |
| [fn.removeAttr ()](#fnremoveattr-) | [fn.first ()](#fnfirst-) | | | [fn.outerWidth ()](#fnouterwidth-) | |
| [fn.removeClass ()](#fnremoveclass-) | [fn.get ()](#fnget-) | | | [fn.width ()](#fnwidth-) | |
| [fn.removeProp ()](#fnremoveprop-) | [fn.index ()](#fnindex-) | | | | |
| [fn.toggleClass ()](#fntoggleclass-) | [fn.last ()](#fnlast-) | | | | |
| | [fn.map ()](#fnmap-) | | | | |
| | [fn.slice ()](#fnslice-) | | | | |

@@ -263,6 +263,8 @@ | Events | Forms | Manipulation | Offset | Traversal |

Link some data (string, object, array, etc.) to an element when both key and value are supplied.
Without arguments, returns an object mapping all the `data-*` attributes to their values.
If only a key is supplied, returns the linked data and falls back to data attribute value if no data is already linked.
With a `key`, return the value of the corresponding `data-*` attribute.
With both a `key` and `value`, sets the value of the corresponding `data-*` attribute to `value`.
Multiple data can be set when an object is supplied.

@@ -681,11 +683,2 @@

#### fn.removeData ()
Removes linked data and data-attributes from collection elements.
```js
$(element).removeData ( name ) // => collection
$(element).removeData () // => collection
```
#### fn.removeProp ()

@@ -837,3 +830,2 @@

| [$.isString ()](#isstring-) | [$.extend ()](#extend-) |
| | [$.hasData ()](#hasdata-) |
| | [$.matches ()](#matches-) |

@@ -876,10 +868,2 @@ | | [$.parseHTML ()](#parsehtml-) |

#### $.hasData ()
Determine whether an element has any Cash data associated with it.
```js
$.hasData ( document.body ) // => boolean
```
#### $.isArray ()

@@ -886,0 +870,0 @@

@@ -10,2 +10,3 @@

interface Cash {
data (): plainObject | undefined;
data ( name: string );

@@ -16,6 +17,7 @@ data ( name: string, value ): this;

function data ( this: Cash ): plainObject | undefined;
function data ( this: Cash, name: string );
function data ( this: Cash, name: string, value ): Cash;
function data ( this: Cash, name: plainObject ): Cash;
function data ( this: Cash, name: string | plainObject, value? ) {
function data ( this: Cash, name?: string | plainObject, value? ) {

@@ -26,2 +28,4 @@ if ( !name ) {

const datas = {};
each ( this[0].attributes, ( i, attr ) => {

@@ -33,7 +37,7 @@

this.data ( match[1] );
datas[match[1]] = this.data ( match[1] );
});
return getData ( this[0] );
return datas;

@@ -40,0 +44,0 @@ }

// @require attributes/attr.ts
// @require ./get_data_cache.ts
// @require core/camel_case.ts
function getData ( ele: HTMLElement, key?: string ): plainObject {
function getData ( ele: HTMLElement, key: string ) {
const cache = getDataCache ( ele );
const value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase ( key )] : ele.getAttribute ( `data-${key}` );
if ( key ) {
try {
return JSON.parse ( value );
} catch {}
if ( !( key in cache ) ) {
return value;
let value = ele.dataset ? ele.dataset[key] || ele.dataset[camelCase ( key )] : cash ( ele ).attr ( `data-${key}` );
if ( value !== undefined ) {
try {
value = JSON.parse ( value );
} catch ( e ) {}
cache[key] = value;
}
}
return cache[key];
}
return cache;
}
// @require ./get_data_cache.ts
// @require core/camel_case.ts
function setData ( ele: HTMLElement, key: string, value ): void {
getDataCache ( ele )[key] = value;
try {
value = JSON.stringify ( value );
} catch {}
if ( ele.dataset ) {
ele.dataset[camelCase ( key )] = value;
} else {
ele.setAttribute ( `data-${key}`, value );
}
}
const dataNamespace = '__cashData',
dataAttributeRe = /^data-(.*)/;
const dataAttributeRe = /^data-(.+)/;
// @optional ./data.ts
// @optional ./remove_data.ts
var fixture = '\
<div class="data" data-one="one" data-two="two"></div>\
<div class="types" data-true="true" data-false="false" data-null="null" data-int="3" data-float="3.14" data-string="foo" data-object=\'{"json": true}\' data-array="[1,2,3]"></div>\
';

@@ -22,4 +21,13 @@

var ele = $('.types');
var ele = $('.data');
ele.data ( 'true', true );
ele.data ( 'false', false );
ele.data ( 'null', null );
ele.data ( 'int', 3 );
ele.data ( 'float', 3.14 );
ele.data ( 'string', 'foo' );
ele.data ( 'object', { json: true } );
ele.data ( 'array', [1, 2, 3] );
t.is ( ele.data ( 'true' ), true );

@@ -36,2 +44,12 @@ t.is ( ele.data ( 'false' ), false );

it ( 'doesn\'t cache the values', function ( t ) {
var ele = $('.data');
t.is ( ele.data ( 'one' ), 'one' );
ele[0].dataset.one = 'uno';
t.is ( ele.data ( 'one' ), 'uno' );
});
it ( 'gets all data', function ( t ) {

@@ -72,32 +90,2 @@

describe ( '$.fn.removeData', function ( it ) {
it ( 'removes data', function ( t ) {
var ele = $('.data');
ele.data ( 'one', 'uno' );
ele.removeData ( 'one' );
t.is ( ele.data ( 'one' ), 'one' );
});
it ( 'removes all data', function ( t ) {
var ele = $('.data');
ele.data ( 'one', 'uno' );
ele.data ( 'two', 'due' );
ele.data ( 'three', 3 );
ele.removeData ();
t.is ( ele.data ( 'one' ), 'one' );
t.is ( ele.data ( 'two' ), 'two' );
t.is ( ele.data ( 'three' ), undefined );
});
});
});

@@ -73,18 +73,2 @@

describe ( '$.hasData', function ( it ) {
it ( 'determines whether an element has any cash data associated with it', function ( t ) {
var ele = $('<div data-foo="content">');
t.false ( $.hasData ( ele[0] ) );
t.is ( ele.data ( 'foo' ), 'content' );
t.true ( $.hasData ( ele[0] ) );
});
});
describe ( '$.isArray', function ( it ) {

@@ -91,0 +75,0 @@

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