Giter Site home page Giter Site logo

namecase's Introduction

NameCase

A Javascript library for fixing the capitalization of people's names.

It is heavily based on the Perl Lingua-EN-NameCase module.

It's always best to let the user capitalize their own name as there are too many variations to programmatically catch them all. However, when working with legacy databases, sometimes such a module is needed.

Usage

NameCase provides two functions:

NameCase.checkName() which returns true if the name is in all UPPERCASE or lowercase.

NameCase(string or array, { individualFields : boolean }) returns a properly capitalized name.

The option individualFields defaults to false which works best when the person's names are combined into a single field. If individualFields is set to true, it means you're passing in given and surnames separately. The only difference between these two options is with individualFields set to false, the first character is always capitalized.

Namecase can also be executed from the command line via namecase, which accepts data from stdin and outputs the formatted names to stdout.

Examples

Browser

<script source="namecase.js"></script>

<script>

  var name = "GEORGE WASHINGTON";

  if (NameCase.checkName(name)) {
    document.write(
      NameCase(name)
    );
  } else {
    document.write(name);
  }

</script>

Node

var nc = require('namecase');

String.prototype.toNameCase = function () {
  var name = this.toString();

  if (nc.checkName(name)) {
    return nc(name, { individualFields : true } );
  }
}

console.log("WILLIAM".toNameCase());
console.log("MCKINLEY".toNameCase());

Command line

Install with npm install -g namecase.

namecase < input.txt > ouput.txt

Meteor Integration

NameCase also includes Meteor integration. The NameCase function is available on the Client and Server and comes with a Template helper entitled NameCase.

<template name="templateName">
  {{ NameCase "abe lincoln" optionalNamecaseOptionsHelper }}
</template>
Template.templateName.helpers({
  optionalNamecaseOptionsHelper : function () {
    return { individualFields : true };
  }
});

Build Status

namecase's People

Contributors

emgee3 avatar

Stargazers

Jan Killian avatar  avatar Gary Gurlaskie avatar Vahe Hovhannisyan avatar Yasin ATEŞ avatar Julien Le Coupanec avatar Travis Houlette avatar Joshua Byrd avatar Penn Su avatar Chris Blanchard avatar  avatar James Moberg avatar Roland Fogarasy avatar Jonathon Hill avatar Andrés Bravo avatar Brandon Cheng avatar  avatar Adrian Carriger avatar  avatar Miguel Duarte avatar Gaspard d'Hautefeuille avatar Dominic avatar Adrien Guillo avatar

Watchers

James Cloos avatar  avatar

namecase's Issues

Some edge cases

Hi thank you for the great library.

I have discovered some names, that the conversion produces unexpected results.

Here are my test cases:

[
"Yuri's",
"van den Thillart",
"Ruiz y Picasso,"
"Dato e Iradier",
"Mas i Gavarró",
"Fred XLIX",
"Yusof bin Ishak"
]

The names are taken from Ruby variant of the library: https://github.com/tenderlove/namecase/blob/master/test/test_namecase.rb

Here are the results:

  1) Capitalize name
       should convert "YURI'S" to "Yuri's":

      AssertionError: expected 'Yuri\'S' to equal 'Yuri\'s'
      + expected - actual

      -Yuri'S
      +Yuri's
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

  2) Capitalize name
       should convert "VAN DEN THILLART" to "van den Thillart":

      AssertionError: expected 'van Den Thillart' to equal 'van den Thillart'
      + expected - actual

      -van Den Thillart
      +van den Thillart
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

  3) Capitalize name
       should convert "RUIZ Y PICASSO" to "Ruiz y Picasso":

      AssertionError: expected 'Ruiz yPicasso' to equal 'Ruiz y Picasso'
      + expected - actual

      -Ruiz yPicasso
      +Ruiz y Picasso
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

  4) Capitalize name
       should convert "DATO E IRADIER" to "Dato e Iradier":

      AssertionError: expected 'Dato E Iradier' to equal 'Dato e Iradier'
      + expected - actual

      -Dato E Iradier
      +Dato e Iradier
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

  5) Capitalize name
       should convert "MAS I GAVARRÓ" to "Mas i Gavarró":

      AssertionError: expected 'Mas I Gavarró' to equal 'Mas i Gavarró'
      + expected - actual

      -Mas I Gavarró
      +Mas i Gavarró
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

  6) Capitalize name
       should convert "FRED XLIX" to "Fred XLIX":

      AssertionError: expected 'Fred Xlix' to equal 'Fred XLIX'
      + expected - actual

      -Fred Xlix
      +Fred XLIX
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

  7) Capitalize name
       should convert "YUSOF BIN ISHAK" to "Yusof bin Ishak":

      AssertionError: expected 'Yusof Bin Ishak' to equal 'Yusof bin Ishak'
      + expected - actual

      -Yusof Bin Ishak
      +Yusof bin Ishak
      
      at Context.it (app/utils/capitalize-name.spec.js:73:29)

An edge case

Hi thank you for the awesome library.

I have discovered a weird case that produces an unexpected result.

This is the name:

DAVID LA ROSE

This is the result:

David la Rose

The module should handle LA as “La” instead of “la”, shouldn't it? I think an speaking french contributor could be really helpful to clarify this, thanks.

Best Regards!!!

image

Name causes undefined

I was playing with the library. It works amazingly well for how simple it is. However, when I used the name João it returned undefined.

var nc = require('namecase')

String.prototype.toNameCase = function () {
  var name = this.toString()

  if (nc.checkName(name)) {
    return nc(name, { individualFields : true } )
  }
}

console.log("João".toNameCase())
// returns undefined

Common Abbreviations

I'm planning on using your parser to clean company names, which are littered with LLC, Inc, CO, etc.

Would a PR adding support for these acronyms be welcome? Perhaps it would be included in a different mode?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.