Skip to content

Commit 731d006

Browse files
committed
Update.
1 parent e5ef0fd commit 731d006

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ A tiny JavaScript utility library.
44

55
## 简介
66

7-
一个非常小巧的 JavaScript 工具库,适用于用户脚本(userscript)、演示案例等比较紧凑的场景。
7+
一个非常小巧的 JavaScript 工具库,适用于用户脚本、演示案例等比较紧凑的场景。
88

99
因为使用了一些较先进的 JavaScript/DOM API,仅适用于现代浏览器。
1010

1111
**注意**:仍在开发中,API 仍不稳定。
1212

13+
## 安装
14+
15+
```bash
16+
$ bower install tiny.js
17+
```
18+
19+
***
20+
1321
## License
1422

1523
[MIT License](http://www.opensource.org/licenses/mit-license.php)

bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"globals"
1212
],
1313
"keywords": [
14-
"weibo",
15-
"v5"
14+
"JavaScript",
15+
"utility",
16+
"library"
1617
],
1718
"license": "MIT",
1819
"ignore": [

src/tiny.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
/*!
2-
* Tiny.js
2+
* Tiny.js v0.4.0
33
* https://github.com/UserScript/tiny.js
44
*/
55

6-
void function () {
6+
void function (root) {
77
'use strict'
88

99
//namespace
1010
var $ = function (s, eWrapper) {
1111
return (eWrapper || document).querySelectorAll(s)
1212
}
1313

14-
//utilities
14+
//type
15+
$.isArray = function (arr) {
16+
return Array.isArray(arr)
17+
}
18+
19+
//data collection
1520
//TODO
1621
//$.extend()
17-
$.each = function (a, fn, context) {
22+
$.each = function (arr, fn, context) {
1823
//todo: object
19-
for (var i = 0, l = a.length; i < l; ++i) {
20-
fn.call(context || window, a[i], i, a)
24+
for (var i = 0, l = arr.length; i < l; ++i) {
25+
fn.call(context || window, arr[i], i, arr)
2126
}
2227
}
28+
$.inArray = function (arr, item) {
29+
if (!$.isArray(arr)) return false
30+
return arr.indexOf(item) > -1
31+
}
2332

2433
//str
2534
$.str = {}
@@ -122,12 +131,6 @@ void function () {
122131
}
123132

124133
//exports
125-
if (
126-
!('jQuery' in window) &&
127-
!('Zepto' in window) &&
128-
!('$' in window)
129-
) {
130-
window.$ = $
131-
}
134+
root.$ = $
132135

133-
}()
136+
}(this)

0 commit comments

Comments
 (0)