@hichchi/utils 0.0.4 → 0.0.6

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/index.cjs.js CHANGED
@@ -107,69 +107,6 @@ function isValidRedirectUrl(url, allowedDomains) {
107
107
  return false;
108
108
  }
109
109
  }
110
- /**
111
- * Extract a subdomain from an origin URL
112
- *
113
- * This utility function parses an origin URL and extracts the subdomain portion.
114
- * It works by splitting the origin string using a regular expression that matches
115
- * protocol prefixes (http://, https://), dots, and the provided domain name.
116
- *
117
- * The function handles special cases:
118
- * - If the origin hostname has no domain name (single-label host) or is an IP address, it returns the provided fallback value
119
- * - If no subdomain is found or the origin is undefined, it returns undefined
120
- *
121
- * This is particularly useful for multi-tenant applications where different
122
- * subdomains represent different tenants or environments.
123
- *
124
- * @param {string} origin - The origin URL to extract the subdomain from
125
- * (e.g., "https://admin.example.com")
126
- * @param {string} [splitDomain] - The main domain to use as a reference for extraction
127
- * (e.g., "example.com")
128
- * @param {string} [ifLocalhost] - Fallback value to return when the origin hostname
129
- * has no domain name or is an IP address (e.g., "local" or "development")
130
- * @returns {string|undefined} The extracted subdomain if found, the ifLocalhost value
131
- * for single-label/IP hostnames, or undefined if no subdomain exists
132
- * or origin is undefined
133
- *
134
- * @example
135
- * ```TypeScript
136
- * extractSubdomain("example.com", "admin.example.com", "local")
137
- * // Returns "admin"
138
- * ```
139
- *
140
- * @example
141
- * ```TypeScript
142
- * extractSubdomain("example.com", "localhost:3000", "local")
143
- * // Returns "local"
144
- * ```
145
- *
146
- * @example
147
- * ```TypeScript
148
- * extractSubdomain("example.com", "example.com", "local")
149
- * // Returns undefined (no subdomain)
150
- * ```
151
- */
152
- function extractSubdomain(origin, splitDomain, ifLocalhost) {
153
- if (!splitDomain) return undefined;
154
- try {
155
- const url = new URL(origin.startsWith("http") ? origin : `http://${origin}`);
156
- const hostname = url.hostname;
157
- const isIpv4 = /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/.test(hostname);
158
- const isIpv6 = hostname.includes(":");
159
- if (!hostname.includes(".") || isIpv4 || isIpv6) {
160
- return ifLocalhost;
161
- }
162
- if (hostname.endsWith(splitDomain)) {
163
- const subdomainPart = hostname.slice(0, hostname.length - splitDomain.length);
164
- // Remove trailing dot if present
165
- const subdomain = subdomainPart.replace(/\.$/, "");
166
- return subdomain || undefined;
167
- }
168
- return undefined;
169
- } catch {
170
- return undefined;
171
- }
172
- }
173
110
 
174
111
  /* eslint-disable @typescript-eslint/no-explicit-any */
175
112
  // noinspection JSUnusedGlobalSymbols
@@ -3656,7 +3593,6 @@ exports.deepCopy = deepCopy;
3656
3593
  exports.dottedPathObjectToNested = dottedPathObjectToNested;
3657
3594
  exports.escapeRegExp = escapeRegExp;
3658
3595
  exports.extractEmails = extractEmails;
3659
- exports.extractSubdomain = extractSubdomain;
3660
3596
  exports.extractUrls = extractUrls;
3661
3597
  exports.filterByObject = filterByObject;
3662
3598
  exports.format = format;
package/index.esm.js CHANGED
@@ -105,69 +105,6 @@ function isValidRedirectUrl(url, allowedDomains) {
105
105
  return false;
106
106
  }
107
107
  }
108
- /**
109
- * Extract a subdomain from an origin URL
110
- *
111
- * This utility function parses an origin URL and extracts the subdomain portion.
112
- * It works by splitting the origin string using a regular expression that matches
113
- * protocol prefixes (http://, https://), dots, and the provided domain name.
114
- *
115
- * The function handles special cases:
116
- * - If the origin hostname has no domain name (single-label host) or is an IP address, it returns the provided fallback value
117
- * - If no subdomain is found or the origin is undefined, it returns undefined
118
- *
119
- * This is particularly useful for multi-tenant applications where different
120
- * subdomains represent different tenants or environments.
121
- *
122
- * @param {string} origin - The origin URL to extract the subdomain from
123
- * (e.g., "https://admin.example.com")
124
- * @param {string} [splitDomain] - The main domain to use as a reference for extraction
125
- * (e.g., "example.com")
126
- * @param {string} [ifLocalhost] - Fallback value to return when the origin hostname
127
- * has no domain name or is an IP address (e.g., "local" or "development")
128
- * @returns {string|undefined} The extracted subdomain if found, the ifLocalhost value
129
- * for single-label/IP hostnames, or undefined if no subdomain exists
130
- * or origin is undefined
131
- *
132
- * @example
133
- * ```TypeScript
134
- * extractSubdomain("example.com", "admin.example.com", "local")
135
- * // Returns "admin"
136
- * ```
137
- *
138
- * @example
139
- * ```TypeScript
140
- * extractSubdomain("example.com", "localhost:3000", "local")
141
- * // Returns "local"
142
- * ```
143
- *
144
- * @example
145
- * ```TypeScript
146
- * extractSubdomain("example.com", "example.com", "local")
147
- * // Returns undefined (no subdomain)
148
- * ```
149
- */
150
- function extractSubdomain(origin, splitDomain, ifLocalhost) {
151
- if (!splitDomain) return undefined;
152
- try {
153
- const url = new URL(origin.startsWith("http") ? origin : `http://${origin}`);
154
- const hostname = url.hostname;
155
- const isIpv4 = /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/.test(hostname);
156
- const isIpv6 = hostname.includes(":");
157
- if (!hostname.includes(".") || isIpv4 || isIpv6) {
158
- return ifLocalhost;
159
- }
160
- if (hostname.endsWith(splitDomain)) {
161
- const subdomainPart = hostname.slice(0, hostname.length - splitDomain.length);
162
- // Remove trailing dot if present
163
- const subdomain = subdomainPart.replace(/\.$/, "");
164
- return subdomain || undefined;
165
- }
166
- return undefined;
167
- } catch {
168
- return undefined;
169
- }
170
- }
171
108
 
172
109
  /* eslint-disable @typescript-eslint/no-explicit-any */
173
110
  // noinspection JSUnusedGlobalSymbols
@@ -3635,4 +3572,4 @@ function applyTemplates(str, prefixes) {
3635
3572
  return result;
3636
3573
  }
3637
3574
 
3638
- export { CHARACTERS_TO_REMOVE, CONTEXT_MULTIPLIER, DEFAULT_BREAK_CHAR, DEFAULT_CONTEXT_LENGTH, DEFAULT_ELLIPSIS, DEFAULT_LINE_LENGTH, EnglishInflectionRules, HEX_PADDING_CHAR, HEX_PADDING_LENGTH, HEX_RADIX, TemplateTag, applyTemplate, applyTemplates, breakToWords, countOccurrences, createExcerpt, deepCopy, dottedPathObjectToNested, escapeRegExp, extractEmails, extractSubdomain, extractUrls, filterByObject, format, getEnumValues, getFileExt, getFileSize, getMapKey, getMapKeys, getValueByPath, groupBy, hasOwnAll, hashString, htmlToText, isAlphanumeric, isArray, isObject, isObjectWith, isValidRedirectUrl, maskString, mimeTypes, normalizeString, objectToDottedPathValueObject, omit, padString, plural, prune, randomString, removeWhitespace, reverse, searchMapValues, singular, slugify, stringSimilarity, toCamelCase, toFirstCase, toFirstCaseBreak, toKebabCase, toLowerCase, toLowerCaseBreak, toNumber, toPascalCase, toProperTitleCase, toSentenceCase, toSnakeCase, toTitleCase, toUpperCase, toUpperCaseBreak, toVariableName, truncate, wordWrap };
3575
+ export { CHARACTERS_TO_REMOVE, CONTEXT_MULTIPLIER, DEFAULT_BREAK_CHAR, DEFAULT_CONTEXT_LENGTH, DEFAULT_ELLIPSIS, DEFAULT_LINE_LENGTH, EnglishInflectionRules, HEX_PADDING_CHAR, HEX_PADDING_LENGTH, HEX_RADIX, TemplateTag, applyTemplate, applyTemplates, breakToWords, countOccurrences, createExcerpt, deepCopy, dottedPathObjectToNested, escapeRegExp, extractEmails, extractUrls, filterByObject, format, getEnumValues, getFileExt, getFileSize, getMapKey, getMapKeys, getValueByPath, groupBy, hasOwnAll, hashString, htmlToText, isAlphanumeric, isArray, isObject, isObjectWith, isValidRedirectUrl, maskString, mimeTypes, normalizeString, objectToDottedPathValueObject, omit, padString, plural, prune, randomString, removeWhitespace, reverse, searchMapValues, singular, slugify, stringSimilarity, toCamelCase, toFirstCase, toFirstCaseBreak, toKebabCase, toLowerCase, toLowerCaseBreak, toNumber, toPascalCase, toProperTitleCase, toSentenceCase, toSnakeCase, toTitleCase, toUpperCase, toUpperCaseBreak, toVariableName, truncate, wordWrap };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hichchi/utils",
3
3
  "description": "A comprehensive utility library with essential helper functions for JavaScript/TypeScript applications",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -97,46 +97,3 @@
97
97
  * @throws {never} This function catches all URL parsing errors and returns false instead of throwing
98
98
  */
99
99
  export declare function isValidRedirectUrl(url: string, allowedDomains: string[]): boolean;
100
- /**
101
- * Extract a subdomain from an origin URL
102
- *
103
- * This utility function parses an origin URL and extracts the subdomain portion.
104
- * It works by splitting the origin string using a regular expression that matches
105
- * protocol prefixes (http://, https://), dots, and the provided domain name.
106
- *
107
- * The function handles special cases:
108
- * - If the origin hostname has no domain name (single-label host) or is an IP address, it returns the provided fallback value
109
- * - If no subdomain is found or the origin is undefined, it returns undefined
110
- *
111
- * This is particularly useful for multi-tenant applications where different
112
- * subdomains represent different tenants or environments.
113
- *
114
- * @param {string} origin - The origin URL to extract the subdomain from
115
- * (e.g., "https://admin.example.com")
116
- * @param {string} [splitDomain] - The main domain to use as a reference for extraction
117
- * (e.g., "example.com")
118
- * @param {string} [ifLocalhost] - Fallback value to return when the origin hostname
119
- * has no domain name or is an IP address (e.g., "local" or "development")
120
- * @returns {string|undefined} The extracted subdomain if found, the ifLocalhost value
121
- * for single-label/IP hostnames, or undefined if no subdomain exists
122
- * or origin is undefined
123
- *
124
- * @example
125
- * ```TypeScript
126
- * extractSubdomain("example.com", "admin.example.com", "local")
127
- * // Returns "admin"
128
- * ```
129
- *
130
- * @example
131
- * ```TypeScript
132
- * extractSubdomain("example.com", "localhost:3000", "local")
133
- * // Returns "local"
134
- * ```
135
- *
136
- * @example
137
- * ```TypeScript
138
- * extractSubdomain("example.com", "example.com", "local")
139
- * // Returns undefined (no subdomain)
140
- * ```
141
- */
142
- export declare function extractSubdomain(origin: string, splitDomain?: string, ifLocalhost?: string): string | undefined;