UNPKG

1.05 kBJavaScriptView Raw
1'use strict';
2
3exports.padComponent = function (component) {
4 return component <= 9 ? '0' + component : '' + component;
5};
6
7// Converts a date to a string in YYYYMMDD format
8//
9// - @param {Date} theDate
10// - @return {String} The formatted date
11exports.toYYYYMMDD = function (theDate) {
12 var month = this.padComponent(theDate.getMonth() + 1);
13
14 return theDate.getUTCFullYear() +
15 month +
16 this.padComponent(theDate.getDate()) +
17 '';
18};
19
20// Capitalises the first character of a string
21//
22// - @param {String} str The string to capitalise
23// - @return {String} The capitalised string
24exports.capitalize = function (str) {
25 return str.charAt(0).toUpperCase() + str.slice(1);
26};
27//
28// Determines the path for a given action on a resource
29//
30// - @param {String} prefix
31// - @param {String} resource
32// - @param {String} action
33exports.formatPath = function formatPath(prefix, resource, action) {
34 var requestPath = '/' + (prefix ? prefix + '/' : '') + resource;
35
36 if (action !== '') {
37 requestPath += '/' + action;
38 }
39
40 return requestPath;
41};