dff-util 1.1.7 → 1.1.9

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,4 @@
1
+ import { LangCountryType } from "./const-type";
1
2
  export declare const AppRandomString: (length: number, charset: string) => string;
2
3
  export declare const AppUniqueCode: () => string;
3
4
  export declare const AppCodeByType: (name: string, type?: null) => string;
@@ -5,4 +6,6 @@ export declare const AppCode: (name: string) => string | null;
5
6
  export declare const AppDaysBack: (date: Date, backValue: number, isDays?: boolean) => Date;
6
7
  export declare const AppAddDays: (date: Date, addDays: number, isDays?: boolean) => Date;
7
8
  export declare const AppUUID4: () => string;
8
- export declare const LangData: (data: string, source: string, target: string) => Promise<any>;
9
+ export declare const LangText: (data: string, source: string, target: string) => Promise<any>;
10
+ export declare const CurrencyConvert: (from: string, to: string) => Promise<number>;
11
+ export declare const LangCountryCode: (lang: string) => LangCountryType;
package/dist/main/util.js CHANGED
@@ -9,9 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LangData = exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppCode = exports.AppCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
12
+ exports.LangCountryCode = exports.CurrencyConvert = exports.LangText = exports.AppUUID4 = exports.AppAddDays = exports.AppDaysBack = exports.AppCode = exports.AppCodeByType = exports.AppUniqueCode = exports.AppRandomString = void 0;
13
13
  const randomstring_1 = require("randomstring");
14
- const regexr_1 = require("./regexr");
14
+ const reg_exr_1 = require("./reg-exr");
15
+ const countries_1 = require("./countries");
16
+ const languages_1 = require("./languages");
15
17
  const AppRandomString = (length, charset) => {
16
18
  return (0, randomstring_1.generate)({ length: length, charset: charset });
17
19
  };
@@ -35,7 +37,7 @@ const AppCodeByType = (name, type = null) => {
35
37
  else {
36
38
  str = name + "_" + (0, exports.AppUniqueCode)();
37
39
  }
38
- str = str.replace(regexr_1.RegExp.NON_ALPHA_NUMERIC, "_");
40
+ str = str.replace(reg_exr_1.RegExp.NON_ALPHA_NUMERIC, "_");
39
41
  str = str.replace(/\s/g, "_");
40
42
  str = str.substr(0, 128);
41
43
  return str.toUpperCase();
@@ -46,7 +48,7 @@ const AppCode = (name) => {
46
48
  return null;
47
49
  let str = "";
48
50
  str = name.trim();
49
- str = str.replace(regexr_1.RegExp.NON_ALPHA_NUMERIC, "_");
51
+ str = str.replace(reg_exr_1.RegExp.NON_ALPHA_NUMERIC, "_");
50
52
  str = str.replace(/\s/g, "_");
51
53
  return str.toUpperCase();
52
54
  };
@@ -83,7 +85,7 @@ const AppUUID4 = () => {
83
85
  });
84
86
  };
85
87
  exports.AppUUID4 = AppUUID4;
86
- const LangData = (data, source, target) => __awaiter(void 0, void 0, void 0, function* () {
88
+ const LangText = (data, source, target) => __awaiter(void 0, void 0, void 0, function* () {
87
89
  if (!data || !source || !target) {
88
90
  throw new Error("Invalid input: data, source, or target is missing");
89
91
  }
@@ -106,4 +108,44 @@ const LangData = (data, source, target) => __awaiter(void 0, void 0, void 0, fun
106
108
  }
107
109
  return json.translation || "";
108
110
  });
109
- exports.LangData = LangData;
111
+ exports.LangText = LangText;
112
+ const CurrencyConvert = (from, to) => __awaiter(void 0, void 0, void 0, function* () {
113
+ if (!from || !to) {
114
+ throw new Error("Invalid input: from or to is missing");
115
+ }
116
+ if (from === to) {
117
+ return 1;
118
+ }
119
+ try {
120
+ const url = `https://api.frankfurter.app/latest?from=${from}&to=${to}`;
121
+ const res = yield fetch(url, {
122
+ method: "GET",
123
+ });
124
+ if (!res.ok) {
125
+ throw new Error(`Currency conversion failed: ${res.status} ${res.statusText}`);
126
+ }
127
+ const json = yield res.json();
128
+ return json.rates[to];
129
+ }
130
+ catch (error) {
131
+ throw new Error(`Currency conversion failed: ${error}`);
132
+ }
133
+ });
134
+ exports.CurrencyConvert = CurrencyConvert;
135
+ const LangCountryCode = (lang) => {
136
+ const countryCode = lang.split("-")[1];
137
+ const country = countries_1.countries.find((c) => c.code === countryCode) || {};
138
+ const language = languages_1.languages.find((l) => l.lang === lang) || {};
139
+ return {
140
+ lang: lang,
141
+ country: countryCode,
142
+ name: language.name,
143
+ locale: language.locale,
144
+ currencyCode: country.currencyCode,
145
+ currency: country.currency,
146
+ telCode: country.telCode,
147
+ flag: country.flag,
148
+ dir: language.dir,
149
+ };
150
+ };
151
+ exports.LangCountryCode = LangCountryCode;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- // bun run src/tests/lang.ts
2
+ // bun run src/tests/util.ts
3
3
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
4
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
5
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,19 +11,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  const util_1 = require("../main/util");
14
+ const CallLangCountry = () => {
15
+ const lang = "en-US";
16
+ const country = (0, util_1.LangCountryCode)(lang);
17
+ console.log("LangCountryCode:: ", country);
18
+ };
19
+ const CallLangText = () => __awaiter(void 0, void 0, void 0, function* () {
20
+ const resp = yield (0, util_2.LangText)("Hello, how are you?", "en-US", "te-IN");
21
+ console.log("Resp Kannada:: ", resp);
22
+ });
23
+ const CallCurrencyConvert = () => __awaiter(void 0, void 0, void 0, function* () {
24
+ const resp = yield (0, util_1.CurrencyConvert)("INR", "USD");
25
+ console.log("Resp Currency:: ", resp);
26
+ });
27
+ const util_2 = require("../main/util");
14
28
  const run = () => __awaiter(void 0, void 0, void 0, function* () {
15
- try {
16
- const resp = yield (0, util_1.LangData)("Hello, how are you?", "en-US", "ka-IN");
17
- console.log("Resp Kannada:: ", resp);
18
- const resp1 = yield (0, util_1.LangData)("Hello, how are you?", "en-US", "ar-SA");
19
- console.log("Resp Arabic:: ", resp1);
20
- const resp2 = yield (0, util_1.LangData)("Hello, how are you?", "en-US", "te-IN");
21
- console.log("Resp Telugu:: ", resp2);
22
- const resp3 = yield (0, util_1.LangData)("Hello, how are you?", "en-US", "ta-IN");
23
- console.log("Resp Tamil:: ", resp3);
24
- }
25
- catch (error) {
26
- console.log(error);
27
- }
29
+ yield CallLangCountry();
30
+ yield CallLangText();
31
+ yield CallCurrencyConvert();
28
32
  });
29
33
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dff-util",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
File without changes
File without changes
File without changes