Convert hyphens to camel case (camelCase)

后端 未结 13 1876
梦谈多话
梦谈多话 2020-12-04 08:02

With regex (i assume) or some other method, how can i convert things like:

marker-image or my-example-setting to markerImage o

13条回答
  •  无人及你
    2020-12-04 08:22

    Here is my implementation (just to make hands dirty)

    /**
     * kebab-case to UpperCamelCase
     * @param {String} string
     * @return {String}
     */
    function toUpperCamelCase(string) {
      return string
        .toLowerCase()
        .split('-')
        .map(it => it.charAt(0).toUpperCase() + it.substr(1))
        .join('');
    }
    

提交回复
热议问题