Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@ditojs/utils

Package Overview
Dependencies
Maintainers
2
Versions
424
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ditojs/utils - npm Package Compare versions

Comparing version
2.75.0
to
2.77.0
+2
-2
package.json
{
"name": "@ditojs/utils",
"version": "2.75.0",
"version": "2.77.0",
"type": "module",

@@ -42,3 +42,3 @@ "description": "Dito.js Utility Functions – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",

},
"gitHead": "cfc4ee21dc3f5808b5a78a3b1fab83500c05907a"
"gitHead": "d2cff77924d989aad5ab601cf08433a4e683ac6d"
}

@@ -9,7 +9,9 @@ export function decamelize(str, sep = ' ') {

// See: https://caniuse.com/?search=Unicode%20property%20escape
/([a-z\d])([A-Z])|(\S)(?:\s+)(\S)/g,
(all, lower, upper, beforeSpace, afterSpace) =>
upper
/(^\s+)|(\s+$)|([a-z\d])([A-Z])|(?<=\S)\s+(?=\S)/g,
(all, leading, trailing, lower, upper) =>
lower
? `${lower}${sep}${upper}`
: `${beforeSpace}${sep}${afterSpace}`
: leading || trailing
? ''
: sep
)

@@ -16,0 +18,0 @@ .toLowerCase()

@@ -35,2 +35,22 @@ import { decamelize, hyphenate, underscore } from './decamelize.js'

)
it('should hyphenate single space between words', () => {
expect(hyphenate('Foo Bar')).toBe('foo-bar')
})
it('should hyphenate multiple spaces', () => {
expect(hyphenate('Foo Bar')).toBe('foo-bar')
})
it('should trim leading whitespace', () => {
expect(hyphenate(' Foo Bar')).toBe('foo-bar')
})
it('should trim trailing whitespace', () => {
expect(hyphenate('Foo Bar ')).toBe('foo-bar')
})
it('should hyphenate special characters correctly', () => {
expect(hyphenate('Foo & Bar')).toBe('foo-&-bar')
})
})

@@ -48,2 +68,18 @@

)
it('should underscore multiple spaces', () => {
expect(underscore('Foo Bar')).toBe('foo_bar')
})
it('should trim leading whitespace', () => {
expect(underscore(' Foo Bar')).toBe('foo_bar')
})
it('should trim trailing whitespace', () => {
expect(underscore('Foo Bar ')).toBe('foo_bar')
})
it('should underscore special characters correctly', () => {
expect(underscore('Foo & Bar')).toBe('foo_&_bar')
})
})

@@ -6,12 +6,13 @@ export function labelize(str) {

? str.replace(
/([-_ ]|^)(\w)|([a-z])(?=[A-Z0-9])|(\d)([a-zA-Z])/g,
function (all, hyphen, hyphenated, camel, decimal, decimalNext) {
return hyphenated
? `${hyphen ? ' ' : ''}${hyphenated.toUpperCase()}`
: camel
? `${camel} `
: `${decimal} ${decimalNext.toUpperCase()}`
}
/[-_](?=\W)|([-_ ]|^)(\w)|([a-z])(?=[A-Z0-9])|(\d)([a-zA-Z])/g,
(all, hyphen, hyphenated, camel, decimal, decimalNext) =>
all === '-' || all === '_'
? ' '
: hyphenated
? `${hyphen ? ' ' : ''}${hyphenated.toUpperCase()}`
: camel
? `${camel} `
: `${decimal} ${decimalNext.toUpperCase()}`
)
: ''
}

@@ -6,2 +6,4 @@ import { labelize } from './labelize.js'

expect(labelize('some-hyphenated-text')).toBe('Some Hyphenated Text')
expect(labelize('one-&-two', true)).toBe('One & Two')
expect(labelize('one-2-three', true)).toBe('One 2 Three')
})

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