@kcutils/gatsby-plugin-intl
Version:
gatsby plugin with support react-intl
70 lines • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Locale = void 0;
var error_1 = require("../constants/error");
var Locale = /** @class */ (function () {
function Locale(locale) {
this.seperator = "-";
this.name = locale.replace(/_/g, this.seperator);
var arr = this.name.split(this.seperator);
if (arr.length < 1) {
throw error_1.InvalidInputError("Locale", locale);
}
this.lang = arr[0];
if (arr.length >= 2) {
this.coun = arr[1];
}
if (arr.length >= 3) {
this.ex = arr[2];
}
}
Object.defineProperty(Locale.prototype, "fullName", {
get: function () {
return this.name;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Locale.prototype, "language", {
get: function () {
return this.lang;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Locale.prototype, "country", {
get: function () {
return this.coun;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Locale.prototype, "extra", {
get: function () {
return this.ex;
},
enumerable: false,
configurable: true
});
/**
* check only locale language key (case insensitive)
*
* @param other
*/
Locale.prototype.equals = function (other) {
return this.language.toLowerCase() === other.language.toLowerCase();
};
/**
* check locale language key and country (case insensitive)
* @param other
*/
Locale.prototype.deepEquals = function (other) {
var _a, _b;
var language = this.language.toLowerCase() === other.language.toLowerCase();
var country = ((_a = this.country) !== null && _a !== void 0 ? _a : "").toLowerCase() === ((_b = other.country) !== null && _b !== void 0 ? _b : "").toLowerCase();
return language && country;
};
return Locale;
}());
exports.Locale = Locale;
//# sourceMappingURL=Locale.js.map