https://github.com/dream2023/all-trim
支持字符串、数组、对象、嵌套数组等等的去除空格
https://github.com/dream2023/all-trim
all-trim array-trim delete object-trim remove space string strip trim whitespace
Last synced: 5 months ago
JSON representation
支持字符串、数组、对象、嵌套数组等等的去除空格
- Host: GitHub
- URL: https://github.com/dream2023/all-trim
- Owner: dream2023
- License: mit
- Created: 2019-05-26T10:59:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-22T05:35:04.000Z (almost 4 years ago)
- Last Synced: 2025-03-25T11:51:39.724Z (12 months ago)
- Topics: all-trim, array-trim, delete, object-trim, remove, space, string, strip, trim, whitespace
- Language: JavaScript
- Size: 6.84 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# all-trim
[](https://opensource.org/licenses/mit-license.php)
[](https://www.npmjs.com/package/all-trim)
[](https://www.npmjs.com/package/all-trim)
[](https://npmcharts.com/compare/all-trim?minimal=true)
## 说明
极少代码实现字符串、数组、对象、嵌套数组等类型的去除空格
## 安装 & 使用
```bash
npm install all-trim
```
```js
const allTrim = require('all-trim')
```
## 示例
```js
// 字符串
let str = ' apple '
console.log(allTrim(str)) // 'apple'
```
```js
// 数组
let arr = [' apple ', ' orange ']
console.log(allTrim(arr)) // ['apple', 'orange']
```
```js
// 对象
let obj = {
name: ' zhang ',
age: 19,
hobbies: [' programming ', ' badminton ']
}
console.log(allTrim(obj)) // { name: 'zhang', age: 19, hobbies: ['programming', 'badminton'] }
```
```js
// 嵌套数组
let arr = [
{ city: [' 河南 ', ' 广东 '] },
{ food: [[' 烩面 ', ' 胡辣汤 '], [' 煲仔饭 ', ' 肠粉 ']] }
]
console.log(allTrim(arr)) // [{ city: ['河南 ', '广东']}, {food: [['烩面', '胡辣汤'], ['煲仔饭', '肠粉']]}]
```
```js
// 去除对象key的空格
let obj = { ' name ': ' zhang ' }
console.log(allTrim(arr, true)) // { 'name': 'zhang' }
```