Skip to content

Commit

Permalink
feat: add stripBom
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Feb 23, 2023
1 parent 9559fa0 commit dc33a76
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 0 deletions.
20 changes: 20 additions & 0 deletions DOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -11931,6 +11931,26 @@ Strip ansi codes from a string.
stripAnsi('\u001b[4mcake\u001b[0m'); // -> 'cake'
```

## stripBom

Strip UTF-8 byte order mark.

<details>
<summary>Type Definition</summary>
<pre>
<code class="language-typescript">function stripBom(str: string): string;</code>
</pre>
</details>

|Name |Desc |
|------|---------------|
|str |String to strip|
|return|Result string |

```javascript
stripBom('\uFEFFlicia'); // -> 'licia'
```

## stripCmt

Strip comments from source code.
Expand Down
20 changes: 20 additions & 0 deletions DOC_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11922,6 +11922,26 @@ stringifyAll(function test() {}); // -> '{"value":"function test() {}","type":"F
stripAnsi('\u001b[4mcake\u001b[0m'); // -> 'cake'
```

## stripBom

清除 UTF-8 BOM。

<details>
<summary>类型定义</summary>
<pre>
<code class="language-typescript">function stripBom(str: string): string;</code>
</pre>
</details>

|参数名|说明|
|-----|---|
|str|源字符串|
|返回值|目标字符串|

```javascript
stripBom('\uFEFFlicia'); // -> 'licia'
```

## stripCmt

清除源码中的注释。
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
"stringify",
"stringifyAll",
"stripAnsi",
"stripBom",
"stripCmt",
"stripColor",
"stripHtmlTag",
Expand Down
8 changes: 8 additions & 0 deletions i18n/stripBom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## CN

清除 UTF-8 BOM。

|参数名|说明|
|-----|---|
|str|源字符串|
|返回值|目标字符串|
13 changes: 13 additions & 0 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -6171,6 +6171,19 @@
"browser"
]
},
"stripBom": {
"dependencies": [],
"description": "Strip UTF-8 byte order mark.",
"env": [
"node",
"browser",
"miniprogram"
],
"test": [
"node",
"browser"
]
},
"stripCmt": {
"dependencies": [],
"description": "Strip comments from source code.",
Expand Down
26 changes: 26 additions & 0 deletions src/stripBom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Strip UTF-8 byte order mark.
*
* |Name |Desc |
* |------|---------------|
* |str |String to strip|
* |return|Result string |
*/

/* example
* stripBom('\uFEFFlicia'); // -> 'licia'
*/

/* module
* env: all
*/

/* typescript
* export declare function stripBom(str: string): string;
*/

exports = function(str) {
if (str.charCodeAt(0) === 0xfeff) {
return str.slice(1);
}
return str;
};
1 change: 1 addition & 0 deletions test/stripBom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test(['\uFEFFlicia', 'licia']);

0 comments on commit dc33a76

Please sign in to comment.