Skip to content

Commit

Permalink
Bug #10, cast numbers in JSON to integers parseInt() [iet:8994834]
Browse files Browse the repository at this point in the history
* Plus, add `?gaadwidget=force` and `?lang=zh-cn` parameters/links to test HTML
  • Loading branch information
nfreear committed Feb 24, 2018
1 parent e00837f commit f4c22ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
24 changes: 7 additions & 17 deletions bin/gaad.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @see https://github.com/nfreear/gaad-widget
*/
const NO_LIABILITY =
'License: MIT. The data is provided "as is". I accept no responsibility for the accuracy or otherwise of the data, or any losses arising.';
"License: MIT. The data is provided 'as is'. I accept no responsibility for the accuracy or otherwise of the data, or any losses arising.";

const PKG = require('../package.json');
const ICS_FILE = abspath('../data/gaad.en.ics');
Expand Down Expand Up @@ -38,6 +38,7 @@ var gaadobj = {
url: PKG.repository,
// texts: texts,
locales: PKG[ 'x-locales' ],
count_years: LIMIT_YEARS,
dates: {}
};
var idx;
Expand All @@ -63,13 +64,13 @@ for (idx = 0; idx < LIMIT_YEARS; idx++) {
event.setProperty('DTEND;VALUE=DATE', GAAD_DATE.toString('yyyyMMdd'));

gaadobj.dates[ year ] = {
'{x}': idx + 0,
'{d}': GAAD_DATE.toString('dd'),
'{x}': parseInt(idx),
'{d}': parseInt(GAAD_DATE.toString('dd')),
'{th}': GAAD_DATE.toString('S'),
'{m}': GAAD_DATE.toString('MMMM'),
'{y}': GAAD_DATE.toString('yyyy'),
'{y}': parseInt(GAAD_DATE.toString('yyyy')),
// iso: GAAD_DATE.toISOString(),
ts: GAAD_DATE.getTime() // Milliseconds since epoch.
ts: GAAD_DATE.getTime() / 1000 // Seconds since epoch.
};
}

Expand Down Expand Up @@ -114,21 +115,10 @@ function readLocaleTexts (localedir, locales) {
locale = locales[ idx ];
texts[ locale ] = removeJsonComments(require(localedir + locale));
}

/* fs.readdirSync(localedir).forEach(function (file) {
if (!file.match(/.+\.json$/)) { return texts; }
console.log('Locale: %s', file);
var locale = file.replace('.json', '');
var jsontext = fs.readFileSync(localedir + file, 'utf8');
texts[ locale ] = removeJsonComments(JSON.parse(jsontext));
}); */

return texts;
}

// https://github.com/i18next/i18next/issues/108#__comment
// https://github.com/i18next/i18next/issues/108#__A-comment
function removeJsonComments (locale) {
var texts = {};
var prop;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
"files": [
"index.js",
"dist/",
"data/",
"data/gaad.en.ics",
"data/gaad.json",
"data/locales.json",
"src/",
"style/"
],
Expand Down
7 changes: 6 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ <h1> gaad-widget test </h1>
<div id="id-gaad-widget"></div>


<script data-CDN-src="https://unpkg.com/gaad-widget@3.1.0-beta-beta#._.js"></script>
<p> If the widget is not visible, <a href="?gaadwidget=force">click to add <code>?gaadwidget=force</code></a> to the URL in the address-bar above. </p>

<p> See the widget in <a href="?gaadwidget=force&lang=zh-cn">Chinese, with <code>?lang=zh-cn</code></a> | <a href="?gaadwidget=force">Revert to English</a>. </p>


<script data-CDN-src="https://unpkg.com/gaad-widget@3.2.0#._.js"></script>

<script src="../dist/gaad-widget.js" data-gaad-widget='{ "debug": true, "X-lang": "fr", "X-theme": "black", "X-analytics": false }'></script>

Expand Down

0 comments on commit f4c22ed

Please sign in to comment.