@docaohuynh/ielts-api-utils 1.0.7 → 1.0.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.
package/dist/index.js CHANGED
@@ -500,6 +500,14 @@ var normalizeText = (text) => {
500
500
  var fullNameToUsername = (fullName) => {
501
501
  return import_transliteration.transliterate(fullName).normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]/g, "").trim();
502
502
  };
503
+ // src/utils/strings/empty-line.util.ts
504
+ function removeEmptyLines(str) {
505
+ if (typeof str !== "string") {
506
+ throw new TypeError("Input must be a string");
507
+ }
508
+ return str.split(/\r?\n/).filter((line) => line.trim() !== "").join(`
509
+ `);
510
+ }
503
511
  // src/utils/decode/decode-signed.util.ts
504
512
  function decodeSignedPayload(signedPayload) {
505
513
  const parts = signedPayload.split(".");
@@ -5142,6 +5150,38 @@ async function sendPut(url, body, options = {}) {
5142
5150
  throw error;
5143
5151
  }
5144
5152
  }
5153
+ async function sendDelete(url, options = {}) {
5154
+ const { headers = {}, timeout: timeout3 = 30000 } = options;
5155
+ const controller = new AbortController;
5156
+ const timeoutId = setTimeout(() => controller.abort(), timeout3);
5157
+ try {
5158
+ const response = await fetch(url, {
5159
+ method: "DELETE",
5160
+ headers: {
5161
+ "Content-Type": "application/json",
5162
+ ...headers
5163
+ },
5164
+ signal: controller.signal
5165
+ });
5166
+ clearTimeout(timeoutId);
5167
+ if (!response.ok) {
5168
+ throw new Error(`HTTP error! status: ${response.status} ${response.statusText}`);
5169
+ }
5170
+ const data = await response.json();
5171
+ return {
5172
+ data,
5173
+ status: response.status,
5174
+ statusText: response.statusText,
5175
+ headers: response.headers
5176
+ };
5177
+ } catch (error) {
5178
+ clearTimeout(timeoutId);
5179
+ if (error instanceof Error && error.name === "AbortError") {
5180
+ throw new Error(`Request timeout after ${timeout3}ms`);
5181
+ }
5182
+ throw error;
5183
+ }
5184
+ }
5145
5185
  async function sendGetWithBearer(url, token, options = {}) {
5146
5186
  return sendGet(url, {
5147
5187
  ...options,
@@ -5169,6 +5209,15 @@ async function sendPutWithBearer(url, body, token, options = {}) {
5169
5209
  }
5170
5210
  });
5171
5211
  }
5212
+ async function sendDeleteWithBearer(url, token, options = {}) {
5213
+ return sendDelete(url, {
5214
+ ...options,
5215
+ headers: {
5216
+ ...options.headers,
5217
+ Authorization: `Bearer ${token}`
5218
+ }
5219
+ });
5220
+ }
5172
5221
  // node_modules/escape-string-regexp/index.js
5173
5222
  function escapeStringRegexp(string) {
5174
5223
  if (typeof string !== "string") {
@@ -7229,7 +7278,10 @@ export {
7229
7278
  sendPost,
7230
7279
  sendGetWithBearer,
7231
7280
  sendGet,
7281
+ sendDeleteWithBearer,
7282
+ sendDelete,
7232
7283
  replaceWordInList,
7284
+ removeEmptyLines,
7233
7285
  normalizeText,
7234
7286
  getCurrentDateStr,
7235
7287
  getCurrentDateInUserTimezone,
@@ -3,7 +3,6 @@ export * from './strings';
3
3
  export * from './decode';
4
4
  export * from './language';
5
5
  export * from './list';
6
- export * from './strings';
7
6
  export * from './time';
8
7
  export * from './request';
9
8
  export * from './slug';
@@ -34,6 +34,13 @@ export declare function sendPost<T = any>(url: string, body: any, options?: Requ
34
34
  * @returns Promise with response data
35
35
  */
36
36
  export declare function sendPut<T = any>(url: string, body: any, options?: RequestOptions): Promise<ResponseData<T>>;
37
+ /**
38
+ * Send a DELETE request
39
+ * @param url - The URL to send the request to
40
+ * @param options - Request options including headers and timeout
41
+ * @returns Promise with response data
42
+ */
43
+ export declare function sendDelete<T = any>(url: string, options?: RequestOptions): Promise<ResponseData<T>>;
37
44
  /**
38
45
  * Send a GET request with Bearer token authentication
39
46
  * @param url - The URL to send the request to
@@ -60,3 +67,11 @@ export declare function sendPostWithBearer<T = any>(url: string, body: any, toke
60
67
  * @returns Promise with response data
61
68
  */
62
69
  export declare function sendPutWithBearer<T = any>(url: string, body: any, token: string, options?: RequestOptions): Promise<ResponseData<T>>;
70
+ /**
71
+ * Send a DELETE request with Bearer token authentication
72
+ * @param url - The URL to send the request to
73
+ * @param token - The Bearer token
74
+ * @param options - Request options including headers and timeout
75
+ * @returns Promise with response data
76
+ */
77
+ export declare function sendDeleteWithBearer<T = any>(url: string, token: string, options?: RequestOptions): Promise<ResponseData<T>>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Removes empty lines from a string.
3
+ * An empty line is considered to be a line that contains only whitespace characters or is completely empty.
4
+ *
5
+ * @param str - The input string to remove empty lines from
6
+ * @returns A new string with empty lines removed
7
+ */
8
+ export declare function removeEmptyLines(str: string): string;
@@ -1,2 +1,3 @@
1
1
  export * from './split.util';
2
2
  export * from './normalize.util';
3
+ export * from './empty-line.util';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docaohuynh/ielts-api-utils",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Utilities for IELTS API",
5
5
  "module": "index.ts",
6
6
  "main": "dist/index.js",