Giter Site home page Giter Site logo

dream2023 / all-trim Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 1.0 7 KB

支持字符串、数组、对象、嵌套数组等等的去除空格

License: MIT License

JavaScript 100.00%
all-trim trim array-trim object-trim string whitespace space strip delete remove

all-trim's Introduction

all-trim

MIT Licence npm size download

说明

极少代码实现字符串、数组、对象、嵌套数组等类型的去除空格

安装 & 使用

npm install all-trim
const allTrim = require('all-trim')

示例

// 字符串
let str = ' apple '

console.log(allTrim(str)) // 'apple'
// 数组
let arr = [' apple ', ' orange ']

console.log(allTrim(arr)) // ['apple', 'orange']
// 对象
let obj = {
  name: ' zhang ',
  age: 19,
  hobbies: [' programming ', ' badminton ']
}

console.log(allTrim(obj)) // { name: 'zhang', age: 19, hobbies: ['programming', 'badminton'] }
// 嵌套数组
let arr = [
  { city: [' 河南 ', ' 广东 '] },
  { food: [[' 烩面 ', ' 胡辣汤 '], [' 煲仔饭 ', ' 肠粉 ']] }
]

console.log(allTrim(arr)) // [{ city: ['河南 ', '广东']}, {food: [['烩面', '胡辣汤'], ['煲仔饭', '肠粉']]}]
// 去除对象key的空格
let obj = { ' name ': ' zhang ' }
console.log(allTrim(arr, true)) // { 'name': 'zhang' }

all-trim's People

Contributors

dream2023 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

klguang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.