Skip to content

Commit

Permalink
chore(zh-tw): run prettier format for js global objects (#13994)
Browse files Browse the repository at this point in the history
  • Loading branch information
yin1999 committed Jul 9, 2023
1 parent 555aa50 commit 35800cf
Show file tree
Hide file tree
Showing 29 changed files with 912 additions and 785 deletions.
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,3 @@ build/

# zh-cn
/files/zh-cn/**/*.md

# zh-tw
/files/zh-tw/web/javascript/reference/global_objects/[p-t]*/**/*.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ slug: Web/JavaScript/Reference/Global_Objects/parseInt

## 語法

```plain
```js-nolint
parseInt(string, radix);
```

Expand Down Expand Up @@ -72,7 +72,7 @@ parseInt("12", 13);

```js
parseInt("Hello", 8); // 根本不是數字
parseInt("546", 2); // 在二進位無效
parseInt("546", 2); // 在二進位無效
```

以下的範例,回傳的值均為 **`-15`**
Expand All @@ -81,7 +81,7 @@ parseInt("546", 2); // 在二進位無效
parseInt("-F", 16);
parseInt("-0F", 16);
parseInt("-0XF", 16);
parseInt(-15.1, 10)
parseInt(-15.1, 10);
parseInt(" -17", 8);
parseInt(" -15", 10);
parseInt("-1111", 2);
Expand Down Expand Up @@ -124,23 +124,22 @@ Many implementations have not adopted this behavior as of 2013, and because olde

## 嚴謹的解析 function

有的時候,使用更嚴謹的 code 能夠更精確地轉換整數值。 Regular expressions 可以幫你:
有的時候,使用更嚴謹的 code 能夠更精確地轉換整數值。Regular expression 可以幫你:

```js
filterInt = function (value) {
if(/^(\-|\+)?([0-9]+|Infinity)$/.test(value))
return Number(value);
if (/^(\-|\+)?([0-9]+|Infinity)$/.test(value)) return Number(value);
return NaN;
}

console.log(filterInt('421')); // 421
console.log(filterInt('-421')); // -421
console.log(filterInt('+421')); // 421
console.log(filterInt('Infinity')); // Infinity
console.log(filterInt('421e+0')); // NaN
console.log(filterInt('421hop')); // NaN
console.log(filterInt('hop1.61803398875')); // NaN
console.log(filterInt('1.61803398875')); // NaN
};

console.log(filterInt("421")); // 421
console.log(filterInt("-421")); // -421
console.log(filterInt("+421")); // 421
console.log(filterInt("Infinity")); // Infinity
console.log(filterInt("421e+0")); // NaN
console.log(filterInt("421hop")); // NaN
console.log(filterInt("hop1.61803398875")); // NaN
console.log(filterInt("1.61803398875")); // NaN
```

## 規範
Expand All @@ -151,7 +150,7 @@ console.log(filterInt('1.61803398875')); // NaN

{{Compat}}

## 延伸閱讀
## 參見

- {{jsxref("Global_Objects/parseFloat", "parseFloat()")}}
- {{jsxref("Number.parseFloat()")}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ slug: Web/JavaScript/Reference/Global_Objects/Promise/all

## 語法

```plain
```js
Promise.all(iterable);
```

Expand Down Expand Up @@ -42,10 +42,10 @@ Promise.all(iterable);
var p1 = Promise.resolve(3);
var p2 = 1337;
var p3 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, 'foo');
setTimeout(resolve, 100, "foo");
});

Promise.all([p1, p2, p3]).then(values => {
Promise.all([p1, p2, p3]).then((values) => {
console.log(values); // [3, 1337, "foo"]
});
```
Expand All @@ -54,17 +54,17 @@ Promise.all([p1, p2, p3]).then(values => {

```js
// this will be counted as if the iterable passed is empty, so it gets fulfilled
var p = Promise.all([1,2,3]);
var p = Promise.all([1, 2, 3]);
// this will be counted as if the iterable passed contains only the resolved promise with value "444", so it gets fulfilled
var p2 = Promise.all([1,2,3, Promise.resolve(444)]);
var p2 = Promise.all([1, 2, 3, Promise.resolve(444)]);
// this will be counted as if the iterable passed contains only the rejected promise with value "555", so it gets rejected
var p3 = Promise.all([1,2,3, Promise.reject(555)]);
var p3 = Promise.all([1, 2, 3, Promise.reject(555)]);

// using setTimeout we can execute code after the stack is empty
setTimeout(function(){
console.log(p);
console.log(p2);
console.log(p3);
setTimeout(function () {
console.log(p);
console.log(p2);
console.log(p3);
});

// logs
Expand All @@ -87,9 +87,9 @@ var p = Promise.all(resolvedPromisesArray);
console.log(p);

// using setTimeout we can execute code after the stack is empty
setTimeout(function(){
console.log('the stack is now empty');
console.log(p);
setTimeout(function () {
console.log("the stack is now empty");
console.log(p);
});

// logs, in order:
Expand All @@ -104,9 +104,9 @@ setTimeout(function(){
var mixedPromisesArray = [Promise.resolve(33), Promise.reject(44)];
var p = Promise.all(mixedPromisesArray);
console.log(p);
setTimeout(function(){
console.log('the stack is now empty');
console.log(p);
setTimeout(function () {
console.log("the stack is now empty");
console.log(p);
});

// logs
Expand All @@ -121,10 +121,10 @@ setTimeout(function(){
var p = Promise.all([]); // will be immediately resolved
var p2 = Promise.all([1337, "hi"]); // non-promise values will be ignored, but the evaluation will be done asynchronously
console.log(p);
console.log(p2)
setTimeout(function(){
console.log('the stack is now empty');
console.log(p2);
console.log(p2);
setTimeout(function () {
console.log("the stack is now empty");
console.log(p2);
});

// logs
Expand All @@ -140,36 +140,41 @@ setTimeout(function(){

```js
var p1 = new Promise((resolve, reject) => {
setTimeout(resolve, 1000, 'one');
setTimeout(resolve, 1000, "one");
});
var p2 = new Promise((resolve, reject) => {
setTimeout(resolve, 2000, 'two');
setTimeout(resolve, 2000, "two");
});
var p3 = new Promise((resolve, reject) => {
setTimeout(resolve, 3000, 'three');
setTimeout(resolve, 3000, "three");
});
var p4 = new Promise((resolve, reject) => {
setTimeout(resolve, 4000, 'four');
setTimeout(resolve, 4000, "four");
});
var p5 = new Promise((resolve, reject) => {
reject('reject');
reject("reject");
});

Promise.all([p1, p2, p3, p4, p5]).then(values => {
console.log(values);
}, reason => {
console.log(reason)
});
Promise.all([p1, p2, p3, p4, p5]).then(
(values) => {
console.log(values);
},
(reason) => {
console.log(reason);
}
);

//From console:
//"reject"

//You can also use .catch
Promise.all([p1, p2, p3, p4, p5]).then(values => {
console.log(values);
}).catch(reason => {
console.log(reason)
});
Promise.all([p1, p2, p3, p4, p5])
.then((values) => {
console.log(values);
})
.catch((reason) => {
console.log(reason);
});

//From console:
//"reject"
Expand Down
Loading

0 comments on commit 35800cf

Please sign in to comment.