Skip to content

Commit

Permalink
feat: isArray; call reademe.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 committed Nov 21, 2019
1 parent 1599e55 commit e31bb0a
Show file tree
Hide file tree
Showing 14 changed files with 676 additions and 336 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 1.0.0 (2019-11-15)

* feat: 1 init project, 2 add jest, typescript; 3 add instanceof ([14e4bdc](https://github.com/Rain120/awesome-code-implementation/commit/14e4bdc))
* Initial commit ([f49c21c](https://github.com/Rain120/awesome-code-implementation/commit/f49c21c))
* feat: 1 init project, 2 add jest, typescript; 3 add instanceof ([14e4bdc](https://github.com/Rain120/awesome-javascript-code-implementation/commit/14e4bdc))
* Initial commit ([f49c21c](https://github.com/Rain120/awesome-javascript-code-implementation/commit/f49c21c))



58 changes: 52 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h3 align="center">
<a href="https://github.com/Rain120/awesome-code-implementation">Awesome code implementation for Javascript</a>
<a href="https://github.com/Rain120/awesome-javascript-code-implementation">Awesome code implementation for Javascript</a>
</h3>

## 😚 Welcome
Expand All @@ -21,21 +21,67 @@ Welcome to the Awesome Code Implementation.

<img src="plans.svg">

[Download](plans.xmind)
[Xmind Download](plans.xmind)

#### 🔨 Usage

⌨️ To be Continue...

#### 🤝 Contributing ![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor)

We welcome all contributions. You can submit any ideas as [pull requests](https://github.com/Rain120/awesome-code-implementation/pulls) or as a GitHub [issue](https://github.com/Rain120/awesome-code-implementation/issues).
We welcome all contributions. You can submit any ideas as [pull requests](https://github.com/Rain120/awesome-javascript-code-implementation/pulls) or as a GitHub [issue](https://github.com/Rain120/awesome-javascript-code-implementation/issues).

#### 🔗 Links

- [x] [instanceof](src/instanceof/README.md)
- [ ] Primitive

- [x] [new](src/new/README.md)
- [ ] Javascript Keys

- [x] [instanceof](src/instanceof/README.md)

- [x] [new](src/new/README.md)

- [ ] Array

- [ ] isArray

- [ ] Object

- [ ] ES6

- [ ] Promise

- [ ] Proxy

- [ ] async / await

- [ ] extends

- [ ] 方法

- [ ] debounce

- [ ] throttle

- [ ] curry

- [ ] Algorithm

- [ ] Sort

- [ ] DP

- [ ] Tree

- [ ] Graph

- [ ] 实用工具库

- [ ] Lodash

- [ ] 函数式编程库

- [ ] Ramda

#### 👨‍🏭 Author

Expand All @@ -47,6 +93,6 @@ We welcome all contributions. You can submit any ideas as [pull requests](https:

#### 📝 License

[MIT](https://github.com/Rain120/awesome-code-implementation/blob/master/LICENSE)
[MIT](https://github.com/Rain120/awesome-javascript-code-implementation/blob/master/LICENSE)

Copyright © 2019-present [Rain120](https://github.com/Rain120).
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "awesome-code-implementation",
"name": "awesome-javascript-code-implementation",
"author": "Rain120",
"repository": {
"type": "git",
"url": "git+https://github.com/Rain120/awesome-code-implementation.git"
"url": "git+https://github.com/Rain120/awesome-javascript-code-implementation.git"
},
"version": "1.0.0",
"description": "Awesome code implementation for Javascript",
"main": "index.js",
"scripts": {
"test": "jest --coverage",
"test:watchAll": "jest --coverage --watchAll",
"lint-staged": "lint-staged",
"lint-staged:ts": "tslint -c ./tslint.json src/**/**.ts",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
Expand All @@ -21,9 +22,9 @@
],
"license": "MIT",
"bugs": {
"url": "https://github.com/Rain120/awesome-code-implementation/issues"
"url": "https://github.com/Rain120/awesome-javascript-code-implementation/issues"
},
"homepage": "https://github.com/Rain120/awesome-code-implementation#readme",
"homepage": "https://github.com/Rain120/awesome-javascript-code-implementation#readme",
"lint-staged": {
"{src}/**/**.ts": [
"npm run test",
Expand Down
796 changes: 485 additions & 311 deletions plans.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plans.xmind
Binary file not shown.
7 changes: 7 additions & 0 deletions src/Array/isArray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### 原理

使用 `Object.prototype.toString` 取得对象的一个内部属性 `[[Class]]`,然后依据这个属性,返回 `"[object Array]"` 字符串作为结果(`ECMA`标准中使用`[[]]`来表示语言内部用到的、外部不可直接访问的属性,称为`内部属性`)。利用这 个方法,再配合 `call`,我们可以取得任何对象的内部属性 `[[Class]]`,然后把类型检测转化为字符串比较,以达到我们的目的。

### 参考

[绝对准确地确定JavaScript对象是否为数组](http://web.mit.edu/jwalden/www/isArray.html)
32 changes: 32 additions & 0 deletions src/Array/isArray/__tests__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* @Author: Rainy
* @Date: 2019-11-14 19:25:01
* @LastEditors: Rainy
* @LastEditTime: 2019-11-21 19:12:43
*/

import { _isArray } from '.';

test('_isArray([]) should true', () => {
expect(_isArray([])).toBe(true);
});

test('_isArray([1, 2]) should true', () => {
expect(_isArray([1, 2])).toBe(true);
});

test('_isArray({ a: 1 }) should false', () => {
expect(_isArray({ a: 1 })).toBe(false);
});

test('_isArray({}) should false', () => {
expect(_isArray({})).toBe(false);
});

test('_isArray(null) should false', () => {
expect(_isArray(null)).toBe(false);
});

test('_isArray(undefined) should false', () => {
expect(_isArray(undefined)).toBe(false);
});
12 changes: 12 additions & 0 deletions src/Array/isArray/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* @Author: Rainy
* @Date: 2019-11-14 19:25:01
* @LastEditors: Rainy
* @LastEditTime: 2019-11-21 19:08:54
*/

import { isAbsType } from '../../utils/type';

export function _isArray(target: any): boolean {
return isAbsType(target).toLowerCase() === 'array';
}
6 changes: 6 additions & 0 deletions src/call/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
### 原理

使用一个指定的 `this` 值和单独给出的一个或多个参数来调用一个函数。

### 参考

[call](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/call)
4 changes: 2 additions & 2 deletions src/model/__test__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* @Author: Rainy
* @Date: 2019-11-14 19:25:01
* @LastEditors: Rainy
* @LastEditTime: 2019-11-15 13:47:32
* @LastEditTime: 2019-11-21 10:14:26
*/

import { name } from '.';

test('Foo instanceof Foo should false', () => {
expect(name()).toBe(null);
expect(name()).toBe(undefined);
});
File renamed without changes.
15 changes: 15 additions & 0 deletions src/utils/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* @Author: Rainy
* @Date: 2019-11-21 19:02:37
* @LastEditors: Rainy
* @LastEditTime: 2019-11-21 20:12:23
*/

export function isAbsType(target: any): string {
// [object Object] -> object
return Object.prototype.toString
.call(target)
.split(' ')[1]
.slice(0, -1)
.toLowerCase();
}
67 changes: 57 additions & 10 deletions zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<h3 align="center">
<a href="https://github.com/Rain120/awesome-code-implementation">非常好的Javascript源码实现</a>
<a href="https://github.com/Rain120/awesome-javascript-code-implementation">非常好的Javascript源码实现</a>
</h3>

## 😚 Welcome
## 😚 欢迎

欢迎来到 **源码实现**现场和我们一起学习编程 😁😁.
欢迎来到 JavaScript **源码实现**现场和我们一起学习编程 😁😁.

[EN Version](README.md)

Expand All @@ -21,21 +21,68 @@

<img src="plans.svg">

[下载地址](plans.xmind)
[Xmind 下载地址](plans.xmind)

#### 🔨 Usage
#### 🔨 使用

⌨️ 正在拼命开发中...

#### 🤝 Contributing ![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor)
#### 🤝 贡献 ![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor)

我们非常欢迎您来贡献. 你可以通过 [Pull Requests](https://github.com/Rain120/awesome-code-implementation/pulls) 或者 [GitHub Issue](https://github.com/Rain120/awesome-code-implementation/issues)来给我提建议、代码`bug`.
我们非常欢迎您来贡献. 你可以通过 [Pull Requests](https://github.com/Rain120/awesome-javascript-code-implementation/pulls) 或者 [GitHub Issue](https://github.com/Rain120/awesome-javascript-code-implementation/issues)来给我提建议、代码`bug`.

#### 🔗 快速链接

- [x] [instanceof](src/instanceof/README.md)
- [ ] Primitive

- [ ] Javascript Keys

- [x] [instanceof](src/instanceof/README.md)

- [x] [new](src/new/README.md)

- [ ] Array

- [ ] isArray

- [ ] Object

- [ ] ES6

- [ ] Promise

- [ ] Proxy

- [ ] async / await

- [ ] extends

- [ ] 方法

- [ ] debounce

- [ ] throttle

- [ ] curry

- [ ] Algorithm

- [ ] Sort

- [ ] DP

- [ ] Tree

- [ ] Graph

- [ ] 实用工具库

- [ ] Lodash

- [ ] 函数式编程库

- [ ] Ramda

- [x] [new](src/new/README.md)

#### 👨‍🏭 作者

Expand All @@ -47,6 +94,6 @@

#### 📝 License

[MIT](https://github.com/Rain120/awesome-code-implementation/blob/master/LICENSE)
[MIT](https://github.com/Rain120/awesome-javascript-code-implementation/blob/master/LICENSE)

Copyright © 2019-present [Rain120](https://github.com/Rain120).

0 comments on commit e31bb0a

Please sign in to comment.