Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

skaleb-string-utils

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skaleb-string-utils - npm Package Compare versions

Comparing version 0.4.0 to 0.5.1

src/enums/Delimination.ts

2

package.json
{
"name": "skaleb-string-utils",
"version": "0.4.0",
"version": "0.5.1",
"description": "Simple string utilities provided in an easy to consume interface",

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

@@ -45,23 +45,37 @@ # String Utils

`toBinary(string, ?deliminate)` converts the given string or sentence into binary code. This by default is returned as
a single string however the response can be set to be deliminated. This delimination is spaces.
a single string however the response can be set to be deliminated.
```typescript
import { toBinary } from './index'
import { Delimination } from './enums/Delimination'
// No delimination
// 1110011110111111011011100101100000110001011010011101110110000111100101111001
return toBinary('some binary')
// Space deliminated
// 1110011 1101111 1101101 1100101 100000 1100010 1101001 1101110 1100001 1110010 1111001
return toBinary('some binary', true)
return toBinary('some binary', Delimination.SPACES)
// Retain original delimination
// 1110011110111111011011100101 110001011010011101110110000111100101111001
return toBinary('some binary', Delimination.ORIGINAL)
```
`toHexadecimal(string, ?deliminate)` converts the given string or sentence into hexadecimal. This be default is returned
as a single string however the response can be set to be deliminated. This delimination is spaces.
as a single string however the response can be set to be deliminated.
```typescript
import { toHexadecimal } from './index'
import { Delimination } from './enums/Delimination'
// No delimination
// 68657861646563696d616c
return toHexadecimal('hexadecimal')
// Space deliminated
// 73 6f 6d 65 20 68 65 78 61 64 65 63 69 6d 61 6c
return toHexadecimal('some hexadecimal', true)
return toHexadecimal('some hexadecimal', Delimination.SPACES)
// Retain original delimination
// 736f6d65 68657861646563696d616c
return toHexadecimal('some hexadecimal', Delimination.ORIGINAL)
```

@@ -68,0 +82,0 @@

@@ -6,3 +6,4 @@ import { reverse } from './Reverse'

import { toHexadecimal } from './ToHexadecimal'
import { Delimination } from './enums/Delimination'
export { reverse, toBinary, camelCase, capitalCase, toHexadecimal }
export { reverse, toBinary, camelCase, capitalCase, toHexadecimal, Delimination }

@@ -0,14 +1,33 @@

import { Delimination } from './enums/Delimination'
/**
* Converts the string into binary code. By default the response is concatenated together but can be set to be space deliminated
* @param {string} str The given string to convert to binary
* @param {boolean} deliminate Whether or not the response should be space deliminated
* @param {Delimination} deliminate The manner of delimination that should be implemented
*/
export function toBinary(str: string, deliminate: boolean = false): string {
export function toBinary(str: string, deliminate: Delimination = Delimination.NONE): string {
const conversion = (item: string) => item.charCodeAt(0)
.toString(2)
// Retain original spacing delimination
if (deliminate === Delimination.ORIGINAL) {
const originalSpacing = (word: string) => word.split('')
.map(conversion)
.join('')
return str.split(' ')
.map(originalSpacing)
.join(' ')
}
const binary = str.split('')
.map(conversion)
return deliminate ? binary.join(' ') : binary.join('')
// Deliminate each character by spaces
if (deliminate === Delimination.SPACES) {
return binary.join(' ')
}
// Remove all delimination
return binary.join('')
}

@@ -0,13 +1,33 @@

import { Delimination } from './enums/Delimination'
/**
* Converts the string into hexadecimal. By default the response is concatenated together but can be set to be space deliminated
* @param {string} str The given string to convert to hexadecimal
* @param {boolean} deliminate Whether or not the response should be space deliminated
* @param {Delimination} deliminate The manner of delimination that should be implemented
*/
export function toHexadecimal(str: string, deliminate: boolean = false) {
const conversion = (item: string) => item.charCodeAt(0).toString(16)
export function toHexadecimal(str: string, deliminate: Delimination = Delimination.NONE): string {
const conversion = (item: string) => item.charCodeAt(0)
.toString(16)
// Retain original spacing delimination
if (deliminate === Delimination.ORIGINAL) {
const originalSpacing = (word: string): string => word.split('')
.map(conversion)
.join('')
return str.split(' ')
.map(originalSpacing)
.join(' ')
}
const hexadecimal = str.split('')
.map(conversion)
return deliminate ? hexadecimal.join(' ') : hexadecimal.join('')
// Deliminate each character by spaces
if (deliminate === Delimination.SPACES) {
return hexadecimal.join(' ')
}
// Remove all delimination
return hexadecimal.join('')
}

@@ -1,8 +0,10 @@

import { camelCase } from '../../src/CamelCase'
import { camelCase } from '../../src'
describe('CamelCase', () => {
it('returns a case in camelCase format', () => {
return camelCase('some string to camel case')
.should.deep.equal('someStringToCamelCase')
describe('#camelCase', () => {
it('returns a case in camelCase format', () => {
return camelCase('some string to camel case')
.should.deep.equal('someStringToCamelCase')
})
})
})

@@ -1,13 +0,15 @@

import { capitalCase } from '../../src/CapitalCase'
import { capitalCase } from '../../src'
describe('CapitalCase', () => {
it('returns a string with each word capitalized when only one word is given', () => {
return capitalCase('word')
.should.deep.equal('Word')
})
describe('#capitalCase', () => {
it('returns a string with each word capitalized when only one word is given', () => {
return capitalCase('word')
.should.deep.equal('Word')
})
it('returns a string with each word capitalized when multiple words are given', () => {
return capitalCase('all words are capital case')
.should.deep.equal('All Words Are Capital Case')
it('returns a string with each word capitalized when multiple words are given', () => {
return capitalCase('all words are capital case')
.should.deep.equal('All Words Are Capital Case')
})
})
})

@@ -1,13 +0,15 @@

import { reverse } from '../../src/Reverse'
import { reverse } from '../../src'
describe('Reverse', () => {
it('returns a reversed string when a singular word is given', () => {
return reverse('word')
.should.deep.equal('drow')
})
describe('#reverse', () => {
it('returns a reversed string when a singular word is given', () => {
return reverse('word')
.should.deep.equal('drow')
})
it('returns a reversed string when multiple words are given', () => {
return reverse('multiple words in a string')
.should.deep.equal('gnirts a ni sdrow elpitlum')
it('returns a reversed string when multiple words are given', () => {
return reverse('multiple words in a string')
.should.deep.equal('gnirts a ni sdrow elpitlum')
})
})
})

@@ -1,13 +0,21 @@

import { toBinary } from '../../src/ToBinary'
import { toBinary } from '../../src'
import { Delimination } from '../../src/enums/Delimination'
describe('ToBinary', () => {
it('returns a converted string in equivalent binary', () => {
return toBinary('some binary')
.should.deep.equal('1110011110111111011011100101100000110001011010011101110110000111100101111001')
})
describe('#toBinary', () => {
it('returns a converted string into equivalent binary', () => {
return toBinary('some binary')
.should.deep.equal('1110011110111111011011100101100000110001011010011101110110000111100101111001')
})
it('returns a converted string in equivalent binary, deliminated by spaces', () => {
return toBinary('some binary', true)
.should.deep.equal('1110011 1101111 1101101 1100101 100000 1100010 1101001 1101110 1100001 1110010 1111001')
it('returns a converted string into equivalent binary and deliminates the response with spaces', () => {
return toBinary('some binary', Delimination.SPACES)
.should.deep.equal('1110011 1101111 1101101 1100101 100000 1100010 1101001 1101110 1100001 1110010 1111001')
})
it('returns a converted string into equivalent binary retaining initial delimination', () => {
return toBinary('some binary', Delimination.ORIGINAL)
.should.deep.equal('1110011110111111011011100101 110001011010011101110110000111100101111001')
})
})
})

@@ -1,18 +0,21 @@

import { toHexadecimal } from '../../src/ToHexadecimal'
import { toHexadecimal } from '../../src'
import { Delimination } from '../../src/enums/Delimination'
describe('ToHexadecimal', () => {
it('converts the given string to a hexadecimal string', () => {
return toHexadecimal('hexadecimal')
.should.deep.equal('68657861646563696d616c')
})
describe('#toHexadecimal', () => {
it('returns a converted string into equivalent hexadecimal', () => {
return toHexadecimal('some hexadecimal')
.should.deep.equal('736f6d652068657861646563696d616c')
})
it('converts the given sentence to a hexadecimal string', () => {
return toHexadecimal('some hexadecimal')
.should.deep.equal('736f6d652068657861646563696d616c')
})
it('returns a converted string into equivalent hexadecimal and deliminates the response with spaces', () => {
return toHexadecimal('some hexadecimal', Delimination.SPACES)
.should.deep.equal('73 6f 6d 65 20 68 65 78 61 64 65 63 69 6d 61 6c')
})
it('converts the given sentence to hexadecimal and deliminates the response', () => {
return toHexadecimal('some hexadecimal', true)
.should.deep.equal('73 6f 6d 65 20 68 65 78 61 64 65 63 69 6d 61 6c')
it('returns a converted string into equivalent hexadecimal retaining initial delimination', () => {
return toHexadecimal('some hexadecimal', Delimination.ORIGINAL)
.should.deep.equal('736f6d65 68657861646563696d616c')
})
})
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc