Skip to content

Commit 370718c

Browse files
Bumped version to 4.1.0
1 parent 612635a commit 370718c

8 files changed

Lines changed: 397 additions & 301 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Version 4.1.0
2+
- Added $.isWindow
3+
- Made the TypeScript type system stricter
4+
- $.guid: ensuring it’s properly exported
5+
- $.fn.siblings: ensuring it supports multi-element collections
6+
- $.fn.empty: ensuring it supports multi-element collections
7+
- $.fn.attr: doing nothing when the value equals undefined
8+
19
### Version 4.0.0
210
- Removed `$.fn.removeData`
311
- Removed `$.hasData`

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ If you're migrating from jQuery be sure to read our [migration guide](https://gi
3030

3131
## Usage
3232

33-
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:
33+
Get Cash from [CloudFlare](https://cdnjs.cloudflare.com/ajax/libs/cash/4.1.0/cash.min.js) or [jsDelivr](https://cdn.jsdelivr.net/npm/cash-dom@4.1.0/dist/cash.min.js) and use it like this:
3434

3535
```html
36-
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/4.0.0/cash.min.js"></script>
36+
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/4.1.0/cash.min.js"></script>
3737
<script>
3838
$(function () {
3939
$('html').addClass ( 'dom-loaded' );

dist/cash.d.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
interface Cash {
2-
[index: number]: Window & Document & HTMLElement & Element & Node;
2+
[index: number]: Ele;
33
length: number;
4-
splice(start: number, deleteCount?: number): any;
5-
splice(start: number, deleteCount: number, ...items: Ele[]): any;
4+
splice(start: number, deleteCount?: number): Ele[];
5+
splice(start: number, deleteCount: number, ...items: Ele[]): Ele[];
66
}
77
interface CashStatic {
88
fn: Cash;
@@ -12,9 +12,18 @@ declare type plainObject = {
1212
};
1313
declare type falsy = undefined | null | false | 0 | '';
1414
declare type Ele = Window | Document | HTMLElement | Element | Node;
15-
declare type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike<any> | Cash;
16-
declare type Comparator = string | Function | Ele | Cash;
15+
declare type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike<Ele> | Cash;
16+
declare type Comparator = string | Ele | Cash | ((this: Ele, index: number, ele: Ele) => boolean);
1717
declare type Context = Document | HTMLElement | Element;
18+
declare type EventObj = Event & {
19+
__delegate?: boolean;
20+
namespace?: string;
21+
data?: any;
22+
};
23+
declare type EventCallback = {
24+
(event: EventObj, data?: any): any;
25+
guid?: number;
26+
};
1827
declare class Cash {
1928
constructor(selector?: Selector, context?: Context | Cash);
2029
init(selector?: Selector, context?: Context | Cash): Cash;
@@ -33,20 +42,22 @@ interface Cash {
3342
interface Cash {
3443
last(): Cash;
3544
}
45+
declare type MapCallback<T> = (this: T, index: number, ele: T) => Ele;
3646
interface Cash {
37-
map(callback: Function): Cash;
47+
map(callback: MapCallback<Ele>): Cash;
3848
}
3949
interface Cash {
4050
slice(start?: number, end?: number): Cash;
4151
}
4252
interface CashStatic {
4353
camelCase(str: string): string;
4454
}
55+
declare type EachCallback<T> = (this: T, index: number, ele: T) => any;
4556
interface CashStatic {
46-
each(arr: ArrayLike<any>, callback: Function): void;
57+
each<T>(arr: ArrayLike<T>, callback: EachCallback<T>): void;
4758
}
4859
interface Cash {
49-
each(callback: Function): this;
60+
each(callback: EachCallback<Ele>): this;
5061
}
5162
interface Cash {
5263
removeProp(prop: string): this;
@@ -61,9 +72,10 @@ interface CashStatic {
6172
guid: number;
6273
}
6374
interface CashStatic {
64-
matches(ele: HTMLElement, selector: string): boolean;
75+
matches(ele: any, selector: string): boolean;
6576
}
6677
interface CashStatic {
78+
isWindow(x: any): x is Window;
6779
isFunction(x: any): x is Function;
6880
isString(x: any): x is string;
6981
isNumeric(x: any): boolean;
@@ -84,8 +96,9 @@ interface Cash {
8496
removeAttr(attrs: string): this;
8597
}
8698
interface Cash {
87-
attr(attrs: string): any;
88-
attr(attrs: string, value: any): this;
99+
attr(): undefined;
100+
attr(attrs: string): string | null;
101+
attr(attrs: string, value: string): this;
89102
attr(attrs: plainObject): this;
90103
}
91104
interface Cash {
@@ -98,7 +111,7 @@ interface Cash {
98111
removeClass(classes?: string): this;
99112
}
100113
interface CashStatic {
101-
unique(arr: ArrayLike<any>): ArrayLike<any>;
114+
unique<T>(arr: ArrayLike<T>): ArrayLike<T>;
102115
}
103116
interface Cash {
104117
add(selector: Selector, context?: Context): Cash;
@@ -107,8 +120,8 @@ interface CashStatic {
107120
prefixedProp(prop: string, isVariable?: boolean): string;
108121
}
109122
interface Cash {
110-
css(prop: string): any;
111-
css(prop: string, value: any): this;
123+
css(prop: string): string | undefined;
124+
css(prop: string, value: string): this;
112125
css(props: plainObject): this;
113126
}
114127
interface Cash {
@@ -118,8 +131,8 @@ interface Cash {
118131
data(datas: plainObject): this;
119132
}
120133
interface Cash {
121-
innerWidth(): number;
122-
innerHeight(): number;
134+
innerWidth(): number | undefined;
135+
innerHeight(): number | undefined;
123136
}
124137
interface Cash {
125138
width(): number;
@@ -143,31 +156,31 @@ interface Cash {
143156
interface Cash {
144157
off(): this;
145158
off(events: string): this;
146-
off(events: string, callback: Function): this;
147-
off(events: string, selector: string, callback: Function): this;
159+
off(events: string, callback: EventCallback): this;
160+
off(events: string, selector: string, callback: EventCallback): this;
148161
}
149162
interface Cash {
150163
on(events: plainObject): this;
151-
on(events: string, callback: Function, _one?: boolean): this;
152-
on(events: string, selector: string | Function, callback: Function, _one?: boolean): this;
164+
on(events: string, callback: EventCallback, _one?: boolean): this;
165+
on(events: string, selector: string | EventCallback, callback: EventCallback, _one?: boolean): this;
153166
}
154167
interface Cash {
155168
one(events: plainObject): this;
156-
one(events: string, callback: Function): this;
157-
one(events: string, selector: string | Function, callback: Function): this;
169+
one(events: string, callback: EventCallback): this;
170+
one(events: string, selector: string | EventCallback, callback: EventCallback): this;
158171
}
159172
interface Cash {
160173
ready(callback: Function): this;
161174
}
162175
interface Cash {
163-
trigger(event: string | Event, data?: any): this;
176+
trigger(event: Event | string, data?: any): this;
164177
}
165178
interface Cash {
166179
serialize(): string;
167180
}
168181
interface Cash {
169182
val(): string | string[];
170-
val(value: any): this;
183+
val(value: string | string[]): this;
171184
}
172185
interface Cash {
173186
clone(): this;

0 commit comments

Comments
 (0)