mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Update camelize() and hyphenate() to simpler versions.
This commit is contained in:
parent
f871430018
commit
e6c59672ac
1 changed files with 2 additions and 6 deletions
|
@ -221,7 +221,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
* Camelizes the passed hyphenated string: caps-lock -> capsLock
|
* Camelizes the passed hyphenated string: caps-lock -> capsLock
|
||||||
*/
|
*/
|
||||||
camelize: function(str) {
|
camelize: function(str) {
|
||||||
return str.replace(/-(\w)/g, function(all, chr) {
|
return str.replace(/-(.)/g, function(all, chr) {
|
||||||
return chr.toUpperCase();
|
return chr.toUpperCase();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -230,11 +230,7 @@ this.Base = Base.inject(/** @lends Base# */{
|
||||||
* Converst camelized strings to hyphenated ones: CapsLock -> caps-lock
|
* Converst camelized strings to hyphenated ones: CapsLock -> caps-lock
|
||||||
*/
|
*/
|
||||||
hyphenate: function(str) {
|
hyphenate: function(str) {
|
||||||
return str.replace(/[a-z][A-Z0-9]|[0-9][a-zA-Z]|[A-Z]{2}[a-z]/g,
|
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
||||||
function(match) {
|
|
||||||
return match.charAt(0) + '-' + match.substring(1);
|
|
||||||
}
|
|
||||||
).toLowerCase();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue