"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.buildFieldsFromOpenIDTemplate = void 0;
exports.formatDate = formatDate;
exports.getHostNameFromUrl = getHostNameFromUrl;
exports.sanitizeString = sanitizeString;
var _legacy = require("@hyperledger/aries-oca/build/legacy");
/**
 * Converts a camelCase string to a sentence format (first letter capitalized, rest in lower case).
 * i.e. sanitizeString("helloWorld")  // returns: 'Hello world'
 */
function sanitizeString(str) {
  const result = str.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replaceAll('_', ' ');
  let words = result.split(' ');
  words = words.map((word, index) => {
    if (index === 0 || word.toUpperCase() === word) {
      return word.charAt(0).toUpperCase() + word.slice(1);
    }
    return word.charAt(0).toLowerCase() + word.slice(1);
  });
  return words.join(' ');
}
function getHostNameFromUrl(url) {
  //TODO: Find more elegant way to extract host name
  // const urlRegex = /^(.*:)\/\/([A-Za-z0-9-.]+)(:[0-9]+)?(.*)$/
  // const parts = urlRegex.exec(url)
  // return parts ? parts[2] : undefined
  return url.split("https://")[1];
}
const buildFieldsFromOpenIDTemplate = data => {
  const fields = [];
  for (const key of Object.keys(data)) {
    // omit id and type
    if (key === 'id' || key === 'type') continue;
    let pushedVal = null;
    if (typeof data[key] === 'string' || typeof data[key] === 'number') {
      pushedVal = data[key];
    }
    fields.push(new _legacy.Attribute({
      name: key,
      value: pushedVal
    }));
  }
  return fields;
};
exports.buildFieldsFromOpenIDTemplate = buildFieldsFromOpenIDTemplate;
function formatDate(input) {
  const date = input instanceof Date ? input : new Date(input);
  return date.toLocaleString('en-US', {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    hour12: true
  });
}
//# sourceMappingURL=utils.js.map