All files utils.js

60.71% Statements 17/28
0% Branches 0/4
20% Functions 2/10
60.71% Lines 17/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 631x   1x         1x                     1x   1x       1x       1x           1x   1x       1x       1x         1x   1x 3x     1x 2x     1x      
const utils = exports;
 
const documentTypes = {
  image: 'image',
  googleDoc: 'googleDoc',
};
 
utils.getDocumentType = (/** @type {string} */ mimeType) => {
  if (mimeType.startsWith('image/')) {
    return documentTypes.image;
  }
  if (mimeType === 'application/vnd.google-apps.document') {
    return documentTypes.googleDoc;
  }
};
 
// URL utils
// Google Document
const googleDocumentUrlRegex = /^https:\/\/docs\.google\.com\/document(\/u\/\d)?\/d\//;
 
utils.isGoogleDocument = (/** @type {string} */ url) => {
  return googleDocumentUrlRegex.test(url);
};
 
utils.getDocumentIdByUrl = (/** @type {string} */ url) => {
  return url.replace(googleDocumentUrlRegex, '').replace(/\/pub\??.*/, '');
};
 
utils.getDocumentUrlById = (/** @type {string} */ documentId) => {
  return `https://docs.google.com/document/d/${documentId}`;
};
 
// Google Drive Folder
const googleDriveFolderUrlRegex =
  /^https:\/\/drive\.google\.com\/drive(\/u\/\d)?\/folders\//;
 
utils.isGoogleDriveFolder = (/** @type {string} */ url) => {
  return googleDriveFolderUrlRegex.test(url);
};
 
utils.getFolderIdByUrl = (/** @type {string} */ url) => {
  return url.replace(googleDriveFolderUrlRegex, '');
};
 
utils.getFolderUrlById = (/** @type {string} */ folderId) => {
  return `https://drive.google.com/drive/folders/${folderId}`;
};
 
// Google Sheet
const googleSheetUrlRegex = /^https:\/\/docs\.google\.com\/spreadsheets(\/u\/\d)?\/d\//;
 
utils.isGoogleSheet = (/** @type {string} */ url) => {
  return googleSheetUrlRegex.test(url);
};
 
utils.getSheetIdByUrl = (/** @type {string} */ url) => {
  return url.replace(googleSheetUrlRegex, '').replace(/\/pub\??.*/, '');
};
 
utils.getSheetUrlById = (/** @type {string} */ sheetId) => {
  return `https://docs.google.com/spreadsheets/d/${sheetId}`;
};