Skip to content

Commit

Permalink
removes dependency on d3plus-common locale
Browse files Browse the repository at this point in the history
  • Loading branch information
davelandry committed Nov 16, 2017
1 parent a01fe47 commit 046fee8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
124 changes: 64 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"d3-array": "^1.2.0",
"d3-selection": "^1.1.0",
"d3-transition": "^1.1.0",
"d3plus-common": "^0.6.22"
"d3plus-common": "^0.6.24"
},
"scripts": {
"build": "d3plus-build",
Expand Down
19 changes: 6 additions & 13 deletions src/titleCase.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import {locale} from "d3plus-common";

import {suffixChars, default as textSplit} from "./textSplit";

const lowercase = ["a", "an", "and", "as", "at", "but", "by", "for", "from", "if", "in", "into", "near", "nor", "of", "on", "onto", "or", "per", "that", "the", "to", "with", "via", "vs", "vs."];
const uppercase = ["CEO", "CFO", "CNC", "COO", "CPU", "GDP", "HVAC", "ID", "IT", "R&D", "TV", "UI"];

/**
@function titleCase
@desc Capitalizes the first letter of each word in a phrase/sentence.
@param {String} str The string to apply the title case logic.
@param {Object} [opts] Optional parameters to apply.
@param {String} [opts.lng] The locale to use when looking up all lowercase or uppecase words.
*/
export default function(str, opts) {
export default function(str) {

if (str === void 0) return "";

opts = Object.assign({
lng: "en-US"
}, opts);

const {lng} = opts;

const smalls = locale.t("array.lowercase", {lng, returnObjects: true}).map(s => s.toLowerCase());
const smalls = lowercase.map(s => s.toLowerCase());

let bigs = locale.t("array.uppercase", {lng, returnObjects: true});
let bigs = uppercase.slice();
bigs = bigs.concat(bigs.map(b => `${b}s`));
const biglow = bigs.map(b => b.toLowerCase());

Expand Down
1 change: 0 additions & 1 deletion test/titleCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export default zora()

assert.equal(titleCase("this/that"), "This/That", "Non-space Break");
assert.equal(titleCase("this and that"), "This and That", "Lowercase Word");
assert.equal(titleCase("esto y aquello", {lng: "es-ES"}), "Esto y Aquello", "Parameter: lng");

});

0 comments on commit 046fee8

Please sign in to comment.