Source: storage/shared.js

import { Storage } from '@google-cloud/storage';
import { removeTrailingSlash } from 'cpb-common';

export const StorageInstance = new Storage();

/**
 * @method module:cpb-storage.getShopifyStoreIdFromDir
 * @description
 * ### returns the numerical value from the directory name
 * @param {*} dir
 * @param {string?} [delimiter='/']
 * @returns {*|undefined}
 */
export function getShopifyStoreIdFromDir({ dir, prefix = '/' } = {}) {
  const storeId = removeTrailingSlash(dir);
  // allowing implicit cast comparison (type coercion)
  if (prefix !== '/' || !isFinite(storeId) || !storeId.length) {
    return undefined;
  }

  return +storeId;
}