@tidepool/viz
Version:
Tidepool data visualization for diabetes device data.
685 lines (288 loc) • 20.9 kB
HTML
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>utilities · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.2">
<link rel="stylesheet" href="../../gitbook/style.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="apidocs/" />
<link rel="prev" href="../../docs/deps/Webpack.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../../">
<a href="../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../docs/StartHere.html">
<a href="../../docs/StartHere.html">
@tidepool/viz developer guide
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="../../docs/Background.html">
<a href="../../docs/Background.html">
background
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="../../docs/FeatureOverview.html">
<a href="../../docs/FeatureOverview.html">
overview of features
</a>
</li>
<li class="chapter " data-level="1.2.3" data-path="../../docs/Architecture.html">
<a href="../../docs/Architecture.html">
planned architecture
</a>
</li>
<li class="chapter " data-level="1.2.4" data-path="../../docs/DirectoryStructure.html">
<a href="../../docs/DirectoryStructure.html">
app & directory structure
</a>
</li>
<li class="chapter " data-level="1.2.5" data-path="../../docs/CodeStyle.html">
<a href="../../docs/CodeStyle.html">
code style
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="../../docs/views/">
<a href="../../docs/views/">
per-view documentation
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="../components/settings/">
<a href="../components/settings/">
Device Settings view
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="../../docs/views/Trends.html">
<a href="../../docs/views/Trends.html">
Trends view
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="../../docs/Storybook.html">
<a href="../../docs/Storybook.html">
use of React Storybook
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../docs/deps/">
<a href="../../docs/deps/">
usage of dependencies
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../../docs/deps/D3.html">
<a href="../../docs/deps/D3.html">
D3
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../../docs/deps/GSAP.html">
<a href="../../docs/deps/GSAP.html">
GSAP
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../../docs/deps/Moment.html">
<a href="../../docs/deps/Moment.html">
Moment
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="../../docs/deps/React.html">
<a href="../../docs/deps/React.html">
React
</a>
</li>
<li class="chapter " data-level="1.5.5" data-path="../../docs/deps/ReactMotion.html">
<a href="../../docs/deps/ReactMotion.html">
React Motion
</a>
</li>
<li class="chapter " data-level="1.5.6" data-path="../../docs/deps/Redux.html">
<a href="../../docs/deps/Redux.html">
Redux
</a>
</li>
<li class="chapter " data-level="1.5.7" data-path="../../docs/deps/Webpack.html">
<a href="../../docs/deps/Webpack.html">
webpack
</a>
</li>
</ul>
</li>
<li class="chapter active" data-level="1.6" data-path="./">
<a href="./">
utilities
</a>
<ul class="articles">
<li class="chapter " data-level="1.6.1" data-path="apidocs/">
<a href="apidocs/">
API docs for utilities
</a>
<ul class="articles">
<li class="chapter " data-level="1.6.1.1" data-path="apidocs/basal.html">
<a href="apidocs/basal.html">
basal
</a>
</li>
<li class="chapter " data-level="1.6.1.2" data-path="apidocs/bloodglucose.html">
<a href="apidocs/bloodglucose.html">
blood glucose
</a>
</li>
<li class="chapter " data-level="1.6.1.3" data-path="apidocs/bolus.html">
<a href="apidocs/bolus.html">
bolus
</a>
</li>
<li class="chapter " data-level="1.6.1.4" data-path="apidocs/datetime.html">
<a href="apidocs/datetime.html">
datetime
</a>
</li>
<li class="chapter " data-level="1.6.1.5" data-path="apidocs/format.html">
<a href="apidocs/format.html">
format
</a>
</li>
<li class="chapter " data-level="1.6.1.6" data-path="apidocs/misc.html">
<a href="apidocs/misc.html">
misc
</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="chapter " data-level="1.7" data-path="../../docs/misc/">
<a href="../../docs/misc/">
misc
</a>
<ul class="articles">
<li class="chapter " data-level="1.7.1" data-path="../../docs/misc/CommonProps.html">
<a href="../../docs/misc/CommonProps.html">
Common props
</a>
</li>
<li class="chapter " data-level="1.7.2" data-path="../../docs/misc/Docs.html">
<a href="../../docs/misc/Docs.html">
Docs setup & publishing
</a>
</li>
<li class="chapter " data-level="1.7.3" data-path="../../docs/misc/TimeRenderingModes.html">
<a href="../../docs/misc/TimeRenderingModes.html">
Time-rendering modes
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../.." >utilities</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h2 id="javascript-utilities">JavaScript utilities</h2>
<p>This directory contains pure JavaScript utilities for data munging, datetime manipulation, and data display formatting. This document describes our coding standards for these utilities.</p>
<h3 id="auto-generating-api-docs">auto-generating API docs</h3>
<p>We enforce the use of <a href="http://usejsdoc.org/" title="@use JSDoc" target="_blank">JSDoc</a> comments within the <code>src/utils/</code> directory with the <code>require-jsdoc</code> ESLint rule. To generate or update the Markdown file of auto-generated API documentation using <a href="https://github.com/jsdoc2md/jsdoc-to-markdown" title="GitHub: jsdoc2md" target="_blank">jsdoc2md</a>, run the following:</p>
<pre><code class="lang-bash">npm run apidocs src/utils/utilsfile.js > src/utils/apidocs/utilsfile.md
</code></pre>
<p>For example:</p>
<pre><code class="lang-bash">npm run apidocs src/utils/datetime.js > src/utils/apidocs/datetime.md
</code></pre>
<h3 id="use-of-es6-import-and-export">use of ES6 <code>import</code> and <code>export</code></h3>
<ul>
<li><code>export</code> each function individually:<pre><code class="lang-JavaScript"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getTimezoneFromTimePrefs</span>(<span class="hljs-params"></span>) </span>{
...
}
</code></pre>
</li>
<li>unless you need to use a lot of the utilities from a module, it's also nice to import just what you need with de-structuring: <code>import { getTimezoneFromTimePrefs } from './datetime';</code></li>
<li>do <strong>not</strong> use the <code>export default</code></li>
</ul>
<h3 id="use-of-the-moment-api-for-datetime-manipulation">use of the <code>moment</code> API for datetime manipulation</h3>
<p>We use <a href="http://momentjs.com/timezone/" target="_blank"><code>moment-timezone</code></a> when we need to do datetime manipulation involving an arbitrary timezone since neither JavaScript <code>Date</code> or D3 provide this functionality. We also try to <em>only</em> use <code>moment</code> where necessary, preferring JavaScript <code>Date</code> or D3 where one or the other is sufficient.</p>
<p>We are trying to move towards a standard in this repository of dealing with datetimes as hammertimes (milliseconds since January 1, 1970) as much as possible, rather than as ISO 8601-formatted Zulu timestamps in String format, as we've done in the past.</p>
<p>When you need to apply an arbitrary timezone to format a datetime for display, the initial construction of the moment object should look like this:</p>
<pre><code class="lang-JavaScript"><span class="hljs-keyword">const</span> d = moment.utc(hammertime);
</code></pre>
<p>See <a href="http://momentjs.com/docs/#/parsing/utc/" target="_blank">moment's documentation on 'UTC' mode</a> for further details.</p>
<p>In particular, try to avoid <code>moment(hammertime).utc()</code>, as this will first create a representation of the hammertime in the browser's timezone/locale, then convert it back to offset-less UTC, an unnecessary step.</p>
<p>Also be <strong>sure</strong> to avoid <code>moment().utc(hammertime)</code> as this creates a new "moment" object representing the time of execution, then ignores the <code>hammertime</code> parameter to the <code>utc()</code> method!</p>
<p>We are also enforcing use of <code>moment.utc()</code> and disallowing <code>moment().utc()</code> with the help of <a href="https://github.com/wunderflats/eslint-plugin-moment-utc" target="_blank">an ESLint plugin</a>.</p>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../../docs/deps/Webpack.html" class="navigation navigation-prev " aria-label="Previous page: webpack">
<i class="fa fa-angle-left"></i>
</a>
<a href="apidocs/" class="navigation navigation-next " aria-label="Next page: API docs for utilities">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"utilities","level":"1.6","depth":1,"next":{"title":"API docs for utilities","level":"1.6.1","depth":2,"path":"src/utils/apidocs/README.md","ref":"src/utils/apidocs/README.md","articles":[{"title":"basal","level":"1.6.1.1","depth":3,"path":"src/utils/apidocs/basal.md","ref":"src/utils/apidocs/basal.md","articles":[]},{"title":"blood glucose","level":"1.6.1.2","depth":3,"path":"src/utils/apidocs/bloodglucose.md","ref":"src/utils/apidocs/bloodglucose.md","articles":[]},{"title":"bolus","level":"1.6.1.3","depth":3,"path":"src/utils/apidocs/bolus.md","ref":"src/utils/apidocs/bolus.md","articles":[]},{"title":"datetime","level":"1.6.1.4","depth":3,"path":"src/utils/apidocs/datetime.md","ref":"src/utils/apidocs/datetime.md","articles":[]},{"title":"format","level":"1.6.1.5","depth":3,"path":"src/utils/apidocs/format.md","ref":"src/utils/apidocs/format.md","articles":[]},{"title":"misc","level":"1.6.1.6","depth":3,"path":"src/utils/apidocs/misc.md","ref":"src/utils/apidocs/misc.md","articles":[]}]},"previous":{"title":"webpack","level":"1.5.7","depth":2,"path":"docs/deps/Webpack.md","ref":"docs/deps/Webpack.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"src/utils/README.md","mtime":"2017-05-23T17:51:07.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-05-31T15:26:30.892Z"},"basePath":"../..","book":{"language":""}});
});
</script>
</div>
<script src="../../gitbook/gitbook.js"></script>
<script src="../../gitbook/theme.js"></script>
<script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>