Socket
Socket
Sign inDemoInstall

get-clean-string

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

29

index.js

@@ -8,17 +8,24 @@ const charFile = require('./charactersMap.json')

function assignToMap (custom) {
Object.keys(custom).filter(x => x.length === 1).forEach(k => {
charMap.set(k, custom[k])
})
if (custom && typeof (custom) === 'object') {
Object.keys(custom).filter(x => x.length === 1).forEach(k => {
charMap.set(k, custom[k])
})
}
}
module.exports = function (str, sep = ' ', custom) {
if (custom && typeof (custom) === 'object') {
function getReplacament (charater) {
const rep = charMap.has(charater) ? charMap.get(charater) : charater
return betweenFn(rep.charCodeAt(0), aRange[0], aRange[1]) ? rep : ''
}
module.exports = function (sep = ' ', custom) {
const defaultSeparator = sep
assignToMap(custom)
return function (str = '', sep = defaultSeparator, custom) {
assignToMap(custom)
return String(str).toLowerCase()
.split('')
.map(s => getReplacament(s))
.join('').trim().replace(/\s{1,}/g, sep)
}
return (str || '')
.toLowerCase()
.split('')
.map(s => charMap.has(s) ? charMap.get(s) : s)
.map(s => betweenFn(s.charCodeAt(0), aRange[0], aRange[1]) ? s : '')
.join('').trim().replace(/\s{1,}/g, sep)
}

@@ -1,2 +0,2 @@

const clean = require('./index')
const clean = require('./index')(' ', {8: 'eight'})

@@ -69,1 +69,5 @@ test('Test nothing is changed', () => {

})
test('Test global change', () => {
expect(clean(1998)).toBe('199eight')
})
{
"name": "get-clean-string",
"version": "1.0.0",
"version": "2.0.0",
"description": "Module to clean a string removing special characters and replacing accents for asccii equivalents.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,9 +16,14 @@ # get-clean-string

The module requires just one argument: The string to be cleaned.
The module needs to be initialized when importing:
```js
// Example1: Sorting the countries by the name
const clean = require('get-clean-string')()
const clean = require('get-clean-string');
```
Then it requires only the string to be cleaned as an argument:
```js
clean(' remove these: !@#$%^&^*&() ')

@@ -31,7 +36,6 @@

Nevertheless it's possible to define a custom separator
It's possible to define a custom separator
```js
const clean = require('get-clean-string');
clean(' remove these: !@#$%^&^*&() ', '-')

@@ -48,10 +52,21 @@

const clean = require('get-clean-string');
clean(' remove these: !@#$%^&^*&() ', '-', {o: '0'})
//Returns
'rem0ve these'
'rem0ve-these'
```
The second and third parameter can be applied globally when importing the module, so they apply everytime a clean operation is performed:
```js
const clean = require('get-clean-string')('-', {o: '0'})
clean(' remove these: !@#$%^&^*&() ')
clean(' remove those: !@#$%^&^*&() ')
//Returns
'rem0ve-these'
'rem0ve-th0se'
```
### Running tests

@@ -58,0 +73,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc