Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G g1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 68
    • Issues 68
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • cto
  • g1
  • Issues
  • #100

Closed
Open
Created Oct 03, 2018 by Bhanu K@bhanu.k🤺Maintainer

Utilities request

Formatting, methods and string operations

String formatting

JavaScript natively doesn't support camel case conversion and handwriting format conversion

example: MatErNal MortalIty Rate should be

Camel case

Maternal Mortality Rate. We use a custom implementation for this:

function toCamelCase(str) {
  var final_str = str.replace(/\w\S*/g, function (txt) {
    return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  })
  return final_str
}

Handwriting format

Maternal mortality rate

This is a common utility in multiple BMGF projects (Gender, NHRR, UP TSU). I'm assuming other projects might be using this as well.

function slug(text) {
  return text.toString().toLowerCase()
    .replace(/\s+/g, '-')           // Replace spaces with -
    .replace(/[^\w\\-]+/g, '')      // Remove all non-word chars
    .replace(/\\-\\-+/g, '-')       // Replace multiple - with single -
    .replace(/^-+/, '')             // Trim - from start of text
    .replace(/-+$/, '');            // Trim - from end of text
}

Slugify

Slufiy is useful to remove any special characters from a phrase. Jammu & Kashmir becomes jammu_kashmir, Andaman and nicobar islands becomes andaman_and_nicobar_islands

credit: with comments from @karmanya.aggarwal @naveen.manukonda

Edited Oct 03, 2018 by Bhanu K
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking