-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathstring-utils.cjs
39 lines (36 loc) · 1.37 KB
/
string-utils.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* global describe, it */
const { strictEqual } = require('assert')
const { camelCase, decamelize, looksLikeNumber } = require('../build/index.cjs')
describe('string-utils', function () {
describe('camelCase', () => {
it('converts string with hypen in middle to camel case', () => {
strictEqual(camelCase('hello-world'), 'helloWorld')
})
it('removes leading hyphens', () => {
strictEqual(camelCase('-goodnight-moon'), 'goodnightMoon')
})
it('camelCase string stays as is', () => {
strictEqual(camelCase('iAmCamelCase'), 'iAmCamelCase')
})
it('uppercase string with underscore to camel case', () => {
strictEqual(camelCase('NODE_VERSION'), 'nodeVersion')
})
})
describe('decamelize', () => {
it('adds hyphens back to camelcase string', () => {
strictEqual(decamelize('helloWorld'), 'hello-world')
})
})
describe('looksLikeNumber', () => {
it('it detects strings that could be parsed as numbers', () => {
strictEqual(looksLikeNumber('3293'), true)
strictEqual(looksLikeNumber('0x10'), true)
strictEqual(looksLikeNumber('.1'), true)
strictEqual(looksLikeNumber('0.1'), true)
strictEqual(looksLikeNumber('0.10'), true)
strictEqual(looksLikeNumber('00.1'), false)
strictEqual(looksLikeNumber('0100'), false)
strictEqual(looksLikeNumber('apple'), false)
})
})
})