define([], function () {
    'use strict';

    function normalize(postcode) {
        if (!postcode) {
            return '';
        }
        return String(postcode)
            .toUpperCase()
            .replace(/\s+/g, '')
            .replace(/[^A-Z0-9]/g, '');
    }

    return {
        normalize: normalize,

        isExcluded: function (postcode, config) {
            var normalized = normalize(postcode);
            if (!normalized || !config || !config.enabled) {
                return false;
            }

            if (Array.isArray(config.exact) && config.exact.indexOf(normalized) !== -1) {
                return true;
            }

            if (Array.isArray(config.areas)) {
                for (var i = 0; i < config.areas.length; i++) {
                    if (config.areas[i] && normalized.indexOf(config.areas[i]) === 0) {
                        return true;
                    }
                }
            }

            return false;
        }
    };
});
