Re: [css3-fonts][cssom] proposal for revised definition of CSSFontFaceRule

>
> > Ok. As long as there will be a mapping between them it's fine for me.
>
> Yeah, the mapping is trivial:
>
> function camelCaseFromDashes(str) {
>         str = str.toLowerCase();
>         var ret = '';
>         for(var i = 0; i < str.length; i++) {
>                 if(str[i] == '-' && i+1 < str.length) {
>                         ret += str[i+1].toUpperCase();
>                         i++;
>                 } else {
>                         ret += str[i];
>                 }
>         }
>         return ret;
> }
>
> function dashesFromCamelCase(str) {
>         var ret = '';
>         for(var i = 0; i < str.length; i++) {
>                 if(str[i].match(/[A-Z]/)) {
>                         ret += '-' + str[i].toLowerCase();
>                 } else {
>                         ret += str[i];
>                 }
>         }
>         return ret;
> }


This can even be reached easier:

function camelCaseFromDashes(str) {
  return str.replace(/-./g, function(m) { return m[1].toUpperCase(); });
}

function dashesFromCamelCase(str) {
  str.replace(/[A-Z]/g, function(m) { return "-"+m[0].toLowerCase(); });
}

Though I was not talking of a JavaScript mapping. I was talking of a
mapping in CSSOM as Glenn mentioned it. Imagine the camelCase notation
differs from the property name notation for some reason.

Sebastian

Received on Friday, 21 September 2012 22:36:04 UTC