@ditojs/utils
Advanced tools
+2
-2
| { | ||
| "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 @@ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
161835
0.75%6047
0.53%