Skip to content

Commit

Permalink
Bumped version to 8.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Sep 12, 2020
1 parent 4b8ca35 commit 90fa855
Show file tree
Hide file tree
Showing 9 changed files with 431 additions and 311 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### [v8.1.0](https://github.com/fabiospampinato/cash/releases/tag/8.1.0) (2020-09-12)

- Added `$.isPlainObject`
- $.each: added support for iterating over objects
- $.extend: added support for extending deeply
- Readme: updated dimensions
- Updated changelog template

### [v8.0.0](https://github.com/fabiospampinato/cash/releases/tag/8.0.0) (2020-06-20)

- Improved alignment with jQuery regarding handling of non-bubbling events significantly
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ If you're migrating from jQuery be sure to read our [migration guide](https://gi

## Usage

Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/8.0.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@8.0.0/dist/cash.min.js) and use it like this:
Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@8.1.0/dist/cash.min.js) and use it like this:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/8.0.0/cash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.0/cash.min.js"></script>
<script>
$(function () {
$('html').addClass ( 'dom-loaded' );
Expand Down
2 changes: 1 addition & 1 deletion bump.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"changelog": {
"version": "### [v[version]](https://github.com/fabiospampinato/cash/releases/tag/[version]) ([version_date])"
"version": "### [v[version]](https://github.com/fabiospampinato/cash/releases/tag/[version]) ([version_date])\n"
},
"files": {
"README.md": [
Expand Down
51 changes: 28 additions & 23 deletions dist/cash.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ declare type EleLoose = HTMLElement & Element & Node;
declare type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike<Ele> | Cash;
declare type Comparator = string | Ele | Cash | ((this: EleLoose, index: number, ele: EleLoose) => boolean);
declare type Context = Document | HTMLElement | Element;
declare type PlainObject<T> = Record<string, T>;
declare type EventCallback = {
(event: any, data?: any): any;
guid?: number;
Expand All @@ -39,50 +40,54 @@ interface Cash {
interface Cash {
slice(start?: number, end?: number): Cash;
}
declare type EachCallback<T> = (this: T, index: number, ele: T) => any;
interface CashStatic {
each<T>(arr: ArrayLike<T>, callback: EachCallback<T>): void;
guid: number;
}
interface CashStatic {
isWindow(x: any): x is Window;
isFunction(x: any): x is Function;
isArray(x: any): x is Array<any>;
isNumeric(x: any): boolean;
isPlainObject(x: any): x is PlainObject<any>;
}
interface Cash {
each(callback: EachCallback<EleLoose>): this;
get(): EleLoose[];
get(index: number): EleLoose | undefined;
}
interface Cash {
removeProp(prop: string): this;
eq(index: number): Cash;
}
interface CashStatic {
extend(): any;
extend(target: any): typeof cash;
extend(target: any, ...objs: any[]): any;
interface Cash {
first(): Cash;
}
interface Cash {
extend(plugins: Record<any, any>): this;
last(): Cash;
}
declare type EachArrayCallback<T> = (this: T, index: number, ele: T) => any;
declare type EachObjectCallback<T> = (this: T, key: string, value: T) => any;
interface CashStatic {
guid: number;
each<T>(arr: ArrayLike<T>, callback: EachArrayCallback<T>): void;
each<T>(obj: PlainObject<T>, callback: EachObjectCallback<T>): void;
}
interface CashStatic {
isWindow(x: any): x is Window;
isFunction(x: any): x is Function;
isNumeric(x: any): boolean;
isArray(x: any): x is Array<any>;
interface Cash {
each(callback: EachArrayCallback<EleLoose>): this;
}
interface Cash {
prop(prop: string): any;
prop(prop: string, value: any): this;
prop(props: Record<string, any>): this;
}
interface Cash {
get(): EleLoose[];
get(index: number): EleLoose | undefined;
}
interface Cash {
eq(index: number): Cash;
removeProp(prop: string): this;
}
interface Cash {
first(): Cash;
interface CashStatic {
extend(): any;
extend(deep: true, target: any, ...sources: any[]): any;
extend(target: any): typeof cash;
extend(target: any, ...sources: any[]): any;
}
interface Cash {
last(): Cash;
extend(plugins: Record<any, any>): this;
}
interface Cash {
filter(comparator?: Comparator): Cash;
Expand Down
134 changes: 80 additions & 54 deletions dist/cash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,6 @@ const dashAlphaRe = /-([a-z])/g;
function camelCase(str) {
return str.replace(dashAlphaRe, (match, letter) => letter.toUpperCase());
}
function each(arr, callback, _reverse) {
if (_reverse) {
let i = arr.length;
while (i--) {
if (callback.call(arr[i], i, arr[i]) === false)
return arr;
}
}
else {
for (let i = 0, l = arr.length; i < l; i++) {
if (callback.call(arr[i], i, arr[i]) === false)
return arr;
}
}
return arr;
}
cash.each = each;
fn.each = function (callback) {
return each(this, callback);
};
fn.removeProp = function (prop) {
return this.each((i, ele) => { delete ele[propMap[prop] || prop]; });
};
function extend(target, ...objs) {
const length = arguments.length;
if (!length)
return {};
if (length === 1)
return extend(cash, target);
for (let i = 1; i < length; i++) {
for (const key in arguments[i]) {
target[key] = arguments[i][key];
}
}
return target;
}
cash.extend = extend;
fn.extend = function (plugins) {
return extend(fn, plugins);
};
cash.guid = 1;
// @require ./cash.ts
function matches(ele, selector) {
Expand All @@ -144,6 +104,9 @@ function isDocument(x) {
function isElement(x) {
return !!x && x.nodeType === 1;
}
function isBoolean(x) {
return typeof x === 'boolean';
}
function isFunction(x) {
return typeof x === 'function';
}
Expand All @@ -159,10 +122,60 @@ function isNull(x) {
function isNumeric(x) {
return !isNaN(parseFloat(x)) && isFinite(x);
}
function isPlainObject(x) {
if (typeof x !== 'object' || x === null)
return false;
const proto = Object.getPrototypeOf(x);
return proto === null || proto === Object.prototype;
}
cash.isWindow = isWindow;
cash.isFunction = isFunction;
cash.isNumeric = isNumeric;
cash.isArray = isArray;
cash.isNumeric = isNumeric;
cash.isPlainObject = isPlainObject;
fn.get = function (index) {
if (isUndefined(index))
return slice.call(this);
index = Number(index);
return this[index < 0 ? index + this.length : index];
};
fn.eq = function (index) {
return cash(this.get(index));
};
fn.first = function () {
return this.eq(0);
};
fn.last = function () {
return this.eq(-1);
};
function each(arr, callback, _reverse) {
if (_reverse) {
let i = arr.length;
while (i--) {
if (callback.call(arr[i], i, arr[i]) === false)
return arr;
}
}
else if (isPlainObject(arr)) {
const keys = Object.keys(arr);
for (let i = 0, l = keys.length; i < l; i++) {
const key = keys[i];
if (callback.call(arr[key], key, arr[key]) === false)
return arr;
}
}
else {
for (let i = 0, l = arr.length; i < l; i++) {
if (callback.call(arr[i], i, arr[i]) === false)
return arr;
}
}
return arr;
}
cash.each = each;
fn.each = function (callback) {
return each(this, callback);
};
fn.prop = function (prop, value) {
if (!prop)
return;
Expand All @@ -177,20 +190,33 @@ fn.prop = function (prop, value) {
}
return this;
};
fn.get = function (index) {
if (isUndefined(index))
return slice.call(this);
index = Number(index);
return this[index < 0 ? index + this.length : index];
};
fn.eq = function (index) {
return cash(this.get(index));
};
fn.first = function () {
return this.eq(0);
fn.removeProp = function (prop) {
return this.each((i, ele) => { delete ele[propMap[prop] || prop]; });
};
fn.last = function () {
return this.eq(-1);
function extend(...sources) {
const deep = isBoolean(sources[0]) ? sources.shift() : false, target = sources.shift(), length = sources.length;
if (!target)
return {};
if (!length)
return extend(deep, cash, target);
for (let i = 0; i < length; i++) {
const source = sources[i];
for (const key in source) {
if (deep && (isArray(source[key]) || isPlainObject(source[key]))) {
if (!target[key] || target[key].constructor !== source[key].constructor)
target[key] = new source[key].constructor();
extend(deep, target[key], source[key]);
}
else {
target[key] = source[key];
}
}
}
return target;
}
cash.extend = extend;
fn.extend = function (plugins) {
return extend(fn, plugins);
};
// @require ./matches.ts
// @require ./type_checking.ts
Expand Down
Loading

0 comments on commit 90fa855

Please sign in to comment.