Convert kebab-case to camelCase with JavaScript

You can also try regex. camelize = s => s.replace(/-./g, x=>x[1].toUpperCase()) const camelize = s => s.replace(/-./g, x=>x[1].toUpperCase()) const words = [“stack-overflow”,”camel-case”,”alllowercase”,”allcapitalletters”,”custom-xml-parser”,”api-finder”,”json-response-data”,”person20-address”,”user-api20-endpoint”]; console.log(words.map(camelize)); Looks only for hyphen followed by any character, and capitalises it and replaces the hyphen+character with the capitalised character.

Converting a string with spaces into camel case

Looking at your code, you can achieve it with only two replace calls: function camelize(str) { return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) { return index === 0 ? word.toLowerCase() : word.toUpperCase(); }).replace(/\s+/g, ”); } // all output “equipmentClassName” console.log(camelize(“EquipmentClass name”)); console.log(camelize(“Equipment className”)); console.log(camelize(“equipment class name”)); console.log(camelize(“Equipment Class Name”)); Edit: Or in with a single replace call, capturing … Read more

Converting from camelcase to _ in emacs

Use the string-inflection package, available on MELPA, or at https://github.com/akicho8/string-inflection. Useful keyboard shortcuts, copied from https://www.emacswiki.org/emacs/CamelCase : ;; Cycle between snake case, camel case, etc. (require ‘string-inflection) (global-set-key (kbd “C-c i”) ‘string-inflection-cycle) (global-set-key (kbd “C-c C”) ‘string-inflection-camelcase) ;; Force to CamelCase (global-set-key (kbd “C-c L”) ‘string-inflection-lower-camelcase) ;; Force to lowerCamelCase (global-set-key (kbd “C-c J”) ‘string-inflection-java-style-cycle) … Read more

Is using camelCase in CSS ids or classes ok or not?

There is one technical limitation if you use camelCase identifiers in your CSS – the |= selector specifier: <form class=”registration”></form> <form class=”search-movies”></form> <form class=”search-actress”></form> To match only search forms, you can write: [class|=”search”] { font-size: 150% } You cannot do this with camelCase class names.

Force CamelCase on ASP.NET WebAPI Per Controller

Thanks to @KiranChalla I was able to achieve this easier than I thought. Here is the pretty simple class I created: using System; using System.Linq; using System.Web.Http.Controllers; using System.Net.Http.Formatting; using Newtonsoft.Json.Serialization; public class CamelCaseControllerConfigAttribute : Attribute, IControllerConfiguration { public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) { var formatter = controllerSettings.Formatters.OfType<JsonMediaTypeFormatter>().Single(); controllerSettings.Formatters.Remove(formatter); formatter = new JsonMediaTypeFormatter { … Read more

Acronyms in Camel Back

We use the camel case convention like Java and .NET do. Not for reasons of code generators, but for readability. Consider the case of combining two acronyms in one name, for example a class that converts XML into HTML. XMLHTMLConverter or XmlHtmlConverter Which one do you prefer?

MVC JsonResult camelCase serialization [duplicate]

If you want to return a json string from your action which adheres to camelcase notation what you have to do is to create a JsonSerializerSettings instance and pass it as the second parameter of JsonConvert.SerializeObject(a,b) method. public string GetSerializedCourseVms() { var courses = new[] { new CourseVm{Number = “CREA101”, Name = “Care of Magical … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)