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

On Thu, Sep 20, 2012 at 3:30 AM, Sebastian Zartner
<sebastianzartner@gmail.com> wrote:
>>> Yes, enumeration is the use-case. And of course enumerating the
>>> descriptors you should be able to just get either their camelCased names or
>>> their property name representation. Though the descriptors should be
>>> accessible through both notations. Or there should be a mapping between both
>>> notations.
>>
>> The current thinking is to do the latter only (define mapping between
>> notations in spec prose), and not provide enumeration or access via the
>> non-mapped (hyphenated) notation, but only via the mapped, camel-case
>> notation.
>
> 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;
}

~TJ

Received on Friday, 21 September 2012 20:53:10 UTC