-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #438 from capricorn86/task/405-assigned-keys-to-ht…
…mlelementdataset-are-ignored Task/405 assigned keys to htmlelementdataset are ignored
- Loading branch information
Showing
4 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/happy-dom/src/nodes/html-element/DatasetUtility.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Dataset utility. | ||
*/ | ||
export default class DatasetUtility { | ||
/** | ||
* Transforms a kebab cased string to camel case. | ||
* | ||
* @param text Text string. | ||
* @returns Camel cased string. | ||
*/ | ||
public static kebabToCamelCase(text: string): string { | ||
const parts = text.split('-'); | ||
for (let i = 0, max = parts.length; i < max; i++) { | ||
parts[i] = i > 0 ? parts[i].charAt(0).toUpperCase() + parts[i].slice(1) : parts[i]; | ||
} | ||
return parts.join(''); | ||
} | ||
|
||
/** | ||
* Transforms a camel cased string to kebab case. | ||
* | ||
* @param text Text string. | ||
* @returns Kebab cased string. | ||
*/ | ||
public static camelCaseToKebab(text: string): string { | ||
return text.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters