Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aligay/safe-trim

🈳 trim all unsafe space
https://github.com/aligay/safe-trim

trim trimming zero-width-space

Last synced: 6 days ago
JSON representation

🈳 trim all unsafe space

Awesome Lists containing this project

README

        

# safe-trim
---

[![Build Status](https://travis-ci.org/aligay/safe-trim.svg?branch=master)](https://travis-ci.org/aligay/safe-trim/branches)
[![codecov](https://codecov.io/gh/aligay/safe-trim/branch/master/graph/badge.svg)](https://codecov.io/gh/aligay/safe-trim)
[![dependencies Status](https://david-dm.org/aligay/safe-trim/status.svg)](https://david-dm.org/aligay/safe-trim)
[![devDependencies Status](https://david-dm.org/aligay/safe-trim/dev-status.svg)](https://david-dm.org/aligay/safe-trim?type=dev)

## install
```
npm install safe-trim
```
## use
```
import safeTrim from 'safe-trim'
safeTrim(' aβ€‡β€ˆβ€‰β€Šβ€―βŸb ')
```

## remove Invisible spaces

```
let str = ' "a":1 a \r\n\r\tΒ αš€α Žβ€‚β€ƒβ€‚β€ƒβ€„β€…β€†β€‡β€ˆβ€‰β€Šβ€―βŸγ€€b '
let ret = safeTrim(str)
expect(ret).toEqual('"a":1 a\n\nb')
```

## convert CR CR-LR into LR
```
a\r\n\r\nb => 'a\n\nb'
a\r\rb => 'a\n\nb'
a\r\r\nb => 'a\n\nb'
```

## remove BOM
```
JSON.parse('ο»Ώ{"a":1}') // ❗️Error because BOM

JSON.parse(safeTrim('ο»Ώ{"a":1}')) // βœ…
```

## more feature
[more feature](spec/test_spec.js)