generaltranslation 2.0.17 → 2.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Standardizes a given language code.
3
+ */
4
+ declare function _standardizeLanguageCode(code: string): string;
1
5
  /**
2
6
  * Check if a given language-country-script code is valid.
3
7
  * @param {string} code - The language-country-script code to validate.
@@ -37,4 +41,4 @@ declare const _getLanguageCode: (languages: string | string[]) => string | strin
37
41
  */
38
42
  declare function _isSameLanguage(...codes: string[]): boolean;
39
43
  declare function _isSameLanguage(codes: string[]): boolean;
40
- export { _isValidLanguageCode, _getLanguageObject, _getLanguageName, _getLanguageCode, _isSameLanguage };
44
+ export { _isValidLanguageCode, _standardizeLanguageCode, _getLanguageObject, _getLanguageName, _getLanguageCode, _isSameLanguage };
@@ -6,6 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports._getLanguageCode = exports._getLanguageName = void 0;
8
8
  exports._isValidLanguageCode = _isValidLanguageCode;
9
+ exports._standardizeLanguageCode = _standardizeLanguageCode;
9
10
  exports._getLanguageObject = _getLanguageObject;
10
11
  exports._isSameLanguage = _isSameLanguage;
11
12
  // Import modules for mapping ISO 639 codes to language names and vice versa
@@ -32,6 +33,21 @@ const CodeToRegion = CodeToRegion_json_1.default;
32
33
  const Predefined_json_1 = __importDefault(require("./predefined/Predefined.json"));
33
34
  const Predefined = Predefined_json_1.default;
34
35
  // ----- VALIDITY CHECKS ----- //
36
+ /**
37
+ * Standardizes a given language code.
38
+ */
39
+ function _standardizeLanguageCode(code) {
40
+ if (!code || typeof code !== 'string')
41
+ return '';
42
+ try {
43
+ const locale = new Intl.Locale(code);
44
+ const { language, script, region } = locale;
45
+ return `${language}${script ? '-' + script : ''}${region ? '-' + region : ''}`;
46
+ }
47
+ catch (error) {
48
+ return '';
49
+ }
50
+ }
35
51
  /**
36
52
  * Check if a given language-country-script code is valid.
37
53
  * @param {string} code - The language-country-script code to validate.
@@ -46,7 +62,7 @@ function _isValidLanguageCode(code) {
46
62
  const locale = new Intl.Locale(code);
47
63
  const { language, script, region } = locale;
48
64
  const constructedCode = `${language}${script ? '-' + script : ''}${region ? '-' + region : ''}`;
49
- return constructedCode === code;
65
+ return constructedCode.toLowerCase() === code.toLowerCase();
50
66
  }
51
67
  catch (error) {
52
68
  return false;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { _isValidLanguageCode, _getLanguageObject, _isSameLanguage } from './codes/codes';
1
+ import { _isValidLanguageCode, _standardizeLanguageCode, _getLanguageObject, _isSameLanguage } from './codes/codes';
2
2
  import _getLanguageDirection from './codes/getLanguageDirection';
3
3
  /**
4
4
  * Type representing the constructor parameters for the GT class.
@@ -83,6 +83,7 @@ declare class GT {
83
83
  export default GT;
84
84
  export declare const getLanguageDirection: typeof _getLanguageDirection;
85
85
  export declare const isValidLanguageCode: typeof _isValidLanguageCode;
86
+ export declare const standardizeLanguageCode: typeof _standardizeLanguageCode;
86
87
  export declare const getLanguageObject: typeof _getLanguageObject;
87
88
  export declare const getLanguageCode: (languages: string | string[]) => string | string[];
88
89
  export declare const getLanguageName: (codes: string | string[]) => string | string[];
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.isSameLanguage = exports.getLanguageName = exports.getLanguageCode = exports.getLanguageObject = exports.isValidLanguageCode = exports.getLanguageDirection = void 0;
17
+ exports.isSameLanguage = exports.getLanguageName = exports.getLanguageCode = exports.getLanguageObject = exports.standardizeLanguageCode = exports.isValidLanguageCode = exports.getLanguageDirection = void 0;
18
18
  // ----- IMPORTS ----- //
19
19
  const codes_1 = require("./codes/codes");
20
20
  const getLanguageDirection_1 = __importDefault(require("./codes/getLanguageDirection"));
@@ -108,6 +108,7 @@ exports.default = GT;
108
108
  // Export the functions
109
109
  exports.getLanguageDirection = getLanguageDirection_1.default;
110
110
  exports.isValidLanguageCode = codes_1._isValidLanguageCode;
111
+ exports.standardizeLanguageCode = codes_1._standardizeLanguageCode;
111
112
  exports.getLanguageObject = codes_1._getLanguageObject;
112
113
  exports.getLanguageCode = codes_1._getLanguageCode;
113
114
  exports.getLanguageName = codes_1._getLanguageName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generaltranslation",
3
- "version": "2.0.17",
3
+ "version": "2.0.19",
4
4
  "description": "A language toolkit for AI developers",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {