66
77'use strict' ;
88
9- const slack = require ( './slack' ) ;
9+ import slack from './slack.js' ;
1010
11- const fs = require ( 'fs' ) ,
12- crypto = require ( 'crypto' ) ,
13- handlebars = require ( 'handlebars' ) ;
11+ import fs from 'fs' ;
12+ import crypto from 'crypto' ;
13+ import handlebars from 'handlebars' ;
1414
1515const templates = { } ;
1616
@@ -33,7 +33,7 @@ const ONE_DAY = 60 * 60 * 24, // eslint-disable-line no-magic-numbers
3333 * @param {array } commands The commands to look for.
3434 * @return {string|Boolean } Either the first command found, or false if no commands were found.
3535 */
36- const extractCommand = ( message , commands ) => {
36+ export const extractCommand = ( message , commands ) => {
3737
3838 let firstLocation = Number . MAX_SAFE_INTEGER ,
3939 firstCommand ;
@@ -60,7 +60,7 @@ const extractCommand = ( message, commands ) => {
6060 * 'operation' being done on it - expressed as a valid mathematical operation
6161 * (i.e. + or -).
6262 */
63- const extractPlusMinusEventData = ( text ) => {
63+ export const extractPlusMinusEventData = ( text ) => {
6464 const data = text . match ( / @ ( [ A - Z a - z 0 - 9 ] + ?) > ? \s * ( - { 2 } \+ { 2 } | \+ { 2 } - { 2 } | \+ { 2 } | - { 2 } | — { 1 } ) / ) ;
6565
6666 if ( ! data ) {
@@ -97,7 +97,7 @@ const extractPlusMinusEventData = ( text ) => {
9797 * could not be found.
9898 * @see ::isUser
9999 */
100- const extractUserID = ( text ) => {
100+ export const extractUserID = ( text ) => {
101101 const match = text . match ( / U [ A - Z 0 - 9 ] { 8 } / ) ;
102102 return match ? match [ 0 ] : '' ;
103103} ;
@@ -108,7 +108,7 @@ const extractUserID = ( text ) => {
108108 * @param {string } ts A timestamp to hash into the token.
109109 * @returns {string } A token, that can be re-checked later using the same timestamp.
110110 */
111- const getTimeBasedToken = ( ts ) => {
111+ export const getTimeBasedToken = ( ts ) => {
112112
113113 if ( ! ts ) {
114114 throw Error ( 'Timestamp not provided when getting time-based token.' ) ;
@@ -125,7 +125,7 @@ const getTimeBasedToken = ( ts ) => {
125125 *
126126 * @returns {integer } The current Unix timestamp.
127127 */
128- const getTimestamp = ( ) => {
128+ export const getTimestamp = ( ) => {
129129 return Math . floor ( Date . now ( ) / MILLISECONDS_TO_SECONDS ) ;
130130} ;
131131
@@ -135,7 +135,7 @@ const getTimestamp = () => {
135135 * @param {integer } number The number in question.
136136 * @returns {Boolean } Whether or not the number is a plural.
137137 */
138- const isPlural = ( number ) => {
138+ export const isPlural = ( number ) => {
139139 return 1 !== Math . abs ( number ) ;
140140} ;
141141
@@ -147,7 +147,7 @@ const isPlural = ( number ) => {
147147 * @param {integer } ts The timestamp the token was supplied with.
148148 * @returns {boolean } Whether or not the token is valid.
149149 */
150- const isTimeBasedTokenStillValid = ( token , ts ) => {
150+ export const isTimeBasedTokenStillValid = ( token , ts ) => {
151151 const now = getTimestamp ( ) ;
152152
153153 // Don't support tokens too far from the past.
@@ -176,7 +176,7 @@ const isTimeBasedTokenStillValid = ( token, ts ) => {
176176 * @returns {Boolean } Whether or not the string is a Slack user ID.
177177 * @see ::extractUserID()
178178 */
179- const isUser = ( item ) => {
179+ export const isUser = ( item ) => {
180180 return item . match ( / U [ A - Z 0 - 9 ] { 8 } / ) ? true : false ;
181181} ;
182182
@@ -188,7 +188,7 @@ const isUser = ( item ) => {
188188 * @return {string } The item linked with Slack mrkdwn
189189 * @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
190190 */
191- const maybeLinkItem = ( item ) => {
191+ export const maybeLinkItem = ( item ) => {
192192 return isUser ( item ) ? '<@' + item + '>' : item ;
193193} ;
194194
@@ -200,7 +200,7 @@ const maybeLinkItem = ( item ) => {
200200 * @return {int } item
201201 * The id.
202202 */
203- const returnAsId = ( item ) => {
203+ export const returnAsId = ( item ) => {
204204 return item ;
205205} ;
206206
@@ -222,7 +222,7 @@ const returnAsId = ( item ) => {
222222 * @returns {string } HTML ready to be rendered in the browser.
223223 * @see https://handlebarsjs.com/
224224 */
225- const render = async ( templatePath , context = { } , request = { } ) => {
225+ export const render = async ( templatePath , context = { } , request = { } ) => {
226226
227227 // Retrieve the header and footer HTML, if we don't already have it in memory.
228228 if ( ! templates . header ) templates . header = fs . readFileSync ( 'src/html/header.html' , 'utf8' ) ;
@@ -249,7 +249,7 @@ const render = async( templatePath, context = {}, request = {}) => {
249249
250250} ; // Render.
251251
252- module . exports = {
252+ export default {
253253 extractCommand,
254254 extractPlusMinusEventData,
255255 extractUserID,
0 commit comments