Sha256: c65e693a5709ca067df26d19afb61ea690b4d11b65daa4b5d427315a2ca956db

Contents?: true

Size: 761 Bytes

Versions: 54

Compression:

Stored size: 761 Bytes

Contents

function normaliseString(value, property) {
  const trimmedValue = value ? value.trim() : '';
  let output;
  let outputType = property == null ? void 0 : property.type;
  if (!outputType) {
    if (['true', 'false'].includes(trimmedValue)) {
      outputType = 'boolean';
    }
    if (trimmedValue.length > 0 && isFinite(Number(trimmedValue))) {
      outputType = 'number';
    }
  }
  switch (outputType) {
    case 'boolean':
      output = trimmedValue === 'true';
      break;
    case 'number':
      output = Number(trimmedValue);
      break;
    default:
      output = value;
  }
  return output;
}

/**
 * @typedef {import('./index.mjs').SchemaProperty} SchemaProperty
 */

export { normaliseString };
//# sourceMappingURL=normalise-string.mjs.map

Version data entries

54 entries across 54 versions & 3 rubygems

Version Path
govuk_publishing_components-49.1.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-49.0.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-48.0.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-47.0.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-46.4.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-46.3.1 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-46.3.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-46.2.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-46.1.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-46.0.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.10.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.9.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.8.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.7.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.6.1 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.6.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.5.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.4.1 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.4.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs
govuk_publishing_components-45.3.0 node_modules/govuk-frontend/dist/govuk/common/normalise-string.mjs