Skip to content

Commit

Permalink
Remove Map polyfill. Fixes #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 15, 2015
1 parent 8d2e5bc commit 2493e4a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
43 changes: 22 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,35 @@ import ptBr from "./src/locale/pt-BR.js";
import ruRu from "./src/locale/ru-RU.js";
import zhCn from "./src/locale/zh-CN.js";

var localeDefinitions = (new Map)
.set("ca-ES", caEs)
.set("de-DE", deDe)
.set("en-CA", enCa)
.set("en-GB", enGb)
.set("en-US", enUs)
.set("es-ES", esEs)
.set("fi-FI", fiFi)
.set("fr-CA", frCa)
.set("fr-FR", frFr)
.set("he-IL", heIl)
.set("it-IT", itIt)
.set("ja-JP", jaJp)
.set("mk-MK", mkMk)
.set("nl-NL", nlNl)
.set("pl-PL", plPl)
.set("pt-BR", ptBr)
.set("ru-RU", ruRu)
.set("zh-CN", zhCn);
var localeDefinitions = {
"ca-ES": caEs,
"de-DE": deDe,
"en-CA": enCa,
"en-GB": enGb,
"en-US": enUs,
"es-ES": esEs,
"fi-FI": fiFi,
"fr-CA": frCa,
"fr-FR": frFr,
"he-IL": heIl,
"it-IT": itIt,
"ja-JP": jaJp,
"mk-MK": mkMk,
"nl-NL": nlNl,
"pl-PL": plPl,
"pt-BR": ptBr,
"ru-RU": ruRu,
"zh-CN": zhCn
};

var defaultLocale = locale(enUs);
export var format = defaultLocale.format;
export var utcFormat = defaultLocale.utcFormat;

export function localeFormat(definition) {
if (typeof definition === "string") {
definition = localeDefinitions.get(definition);
if (!definition) return null;
if (!localeDefinitions.hasOwnProperty(definition)) return null;
definition = localeDefinitions[definition];
}
return locale(definition);
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-time-format",
"version": "0.1.1",
"version": "0.1.2",
"description": "A JavaScript time formatter and parser inspired by strftime and strptime.",
"keywords": [
"d3",
Expand All @@ -22,7 +22,7 @@
"url": "https://github.com/d3/d3-time-format.git"
},
"scripts": {
"pretest": "mkdir -p build && d3-bundler --polyfill-map --format=umd --name=timeFormat -- index.js > build/timeFormat.js",
"pretest": "mkdir -p build && d3-bundler --format=umd --name=timeFormat -- index.js > build/timeFormat.js",
"test": "TZ=America/Los_Angeles faucet `find test -name '*-test.js'`",
"prepublish": "npm run test && uglifyjs build/timeFormat.js -c -m -o build/timeFormat.min.js && rm -f build/timeFormat.zip && zip -j build/timeFormat.zip -- LICENSE README.md build/timeFormat.js build/timeFormat.min.js"
},
Expand Down
14 changes: 7 additions & 7 deletions src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,22 @@ export default function(locale) {

function parseShortWeekday(d, string, i) {
var n = shortWeekdayRe.exec(string.slice(i));
return n ? (d.w = shortWeekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}

function parseWeekday(d, string, i) {
var n = weekdayRe.exec(string.slice(i));
return n ? (d.w = weekdayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}

function parseShortMonth(d, string, i) {
var n = shortMonthRe.exec(string.slice(i));
return n ? (d.m = shortMonthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}

function parseMonth(d, string, i) {
var n = monthRe.exec(string.slice(i));
return n ? (d.m = monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}

function parseLocaleDateTime(d, string, i) {
Expand All @@ -245,7 +245,7 @@ export default function(locale) {
}

function parsePeriod(d, string, i) {
var n = periodLookup.get(string.slice(i, i += 2).toLowerCase());
var n = periodLookup[string.slice(i, i += 2).toLowerCase()];
return n == null ? -1 : (d.p = n, i);
}

Expand Down Expand Up @@ -326,8 +326,8 @@ function formatRe(names) {
}

function formatLookup(names) {
var map = new Map, i = -1, n = names.length;
while (++i < n) map.set(names[i].toLowerCase(), i);
var map = {}, i = -1, n = names.length;
while (++i < n) map[names[i].toLowerCase()] = i;
return map;
}

Expand Down

0 comments on commit 2493e4a

Please sign in to comment.