@uniai-fe/util-functions 0.2.6 → 0.2.7

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 +1 @@
1
- {"version":3,"sources":["../../src/route/module.ts"],"names":[],"mappings":";AAQO,IAAM,eAAA,GAAkB,CAC7B,MAAA,EACA,WAAA,KACmB;AACnB,EAAA,IAAI,YAAA,GAA+B,IAAA;AACnC,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,IAAI,WAAA,CAAY,UAAA,CAAW,KAAA,CAAM,IAAI,CAAA,EAAG;AACtC,MAAA,IAAI,CAAC,YAAA,IAAgB,KAAA,CAAM,KAAK,MAAA,GAAS,YAAA,CAAa,KAAK,MAAA,EAAQ;AACjE,QAAA,YAAA,GAAe,KAAA;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,YAAA;AACT;AASO,IAAM,aAAA,GAAgB,CAI3B,MAAA,EACA,WAAA,KACmB;AACnB,EAAA,MAAM,GAAA,GAAsB,EAAE,QAAA,EAAU,IAAA,EAAM,OAAO,IAAA,EAAK;AAG1D,EAAA,GAAA,CAAI,QAAA,GAAW,eAAA,CAAyB,MAAA,EAAQ,WAAW,CAAA;AAG3D,EAAA,IAAI,GAAA,CAAI,QAAA,IAAY,GAAA,CAAI,QAAA,CAAS,KAAA,EAAO;AACtC,IAAA,GAAA,CAAI,KAAA,GAAQ,eAAA;AAAA,MACV,IAAI,QAAA,CAAS,KAAA;AAAA,MACb;AAAA,KACF;AAAA,EACF;AAEA,EAAA,OAAO,GAAA;AACT","file":"index.mjs","sourcesContent":["import type { SitemapBase, SitemapMatchBase } from \"./type\";\n\n/**\n * 현재 경로와 가장 근접한 경로 데이터 추출\n * @param {SitemapBase[]} routes 사이트맵 배열 데이터\n * @param {string} currentPath 현재 경로\n * @return {SitemapBase | null} 경로 데이터\n */\nexport const getClosestRoute = <Sitemap extends SitemapBase>(\n routes: Sitemap[],\n currentPath: string,\n): Sitemap | null => {\n let deepestMatch: Sitemap | null = null;\n for (const route of routes) {\n if (currentPath.startsWith(route.path)) {\n if (!deepestMatch || route.path.length > deepestMatch.path.length) {\n deepestMatch = route;\n }\n }\n }\n return deepestMatch;\n};\n\n/**\n * 경로 일치 데이터 추출\n * @util\n * @param {SitemapBase[]} routes 사이트맵 배열 데이터\n * @param {string} currentPath 현재 경로\n * @return {SitemapBase | undefined} 경로 데이터\n */\nexport const getMatchRoute = <\n Sitemap extends SitemapBase,\n SitemapMatched extends SitemapMatchBase,\n>(\n routes: Sitemap[],\n currentPath: string,\n): SitemapMatched => {\n const res: SitemapMatched = { category: null, depth: null } as SitemapMatched;\n\n // 1 depth\n res.category = getClosestRoute<Sitemap>(routes, currentPath);\n\n // 2 depth\n if (res.category && res.category.depth) {\n res.depth = getClosestRoute<Sitemap>(\n res.category.depth as Sitemap[],\n currentPath,\n );\n }\n\n return res;\n};\n"]}
1
+ {"version":3,"sources":["../../src/route/module.ts"],"names":[],"mappings":";AAQO,IAAM,eAAA,GAAkB,CAC7B,MAAA,EACA,WAAA,KACmB;AACnB,EAAA,IAAI,YAAA,GAA+B,IAAA;AACnC,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,IAAI,WAAA,CAAY,UAAA,CAAW,KAAA,CAAM,IAAI,CAAA,EAAG;AAEtC,MAAA,IAAI,CAAC,YAAA,IAAgB,KAAA,CAAM,KAAK,MAAA,GAAS,YAAA,CAAa,KAAK,MAAA,EAAQ;AACjE,QAAA,YAAA,GAAe,KAAA;AAAA,MACjB;AAAA,IACF;AAAA,EACF;AACA,EAAA,OAAO,YAAA;AACT;AASO,IAAM,aAAA,GAAgB,CAI3B,MAAA,EACA,WAAA,KACmB;AACnB,EAAA,MAAM,GAAA,GAAsB,EAAE,QAAA,EAAU,IAAA,EAAM,OAAO,IAAA,EAAK;AAG1D,EAAA,GAAA,CAAI,QAAA,GAAW,eAAA,CAAyB,MAAA,EAAQ,WAAW,CAAA;AAG3D,EAAA,IAAI,GAAA,CAAI,QAAA,IAAY,GAAA,CAAI,QAAA,CAAS,KAAA,EAAO;AACtC,IAAA,GAAA,CAAI,KAAA,GAAQ,eAAA;AAAA,MACV,IAAI,QAAA,CAAS,KAAA;AAAA,MACb;AAAA,KACF;AAAA,EACF;AAEA,EAAA,OAAO,GAAA;AACT;AAQO,IAAM,eAAA,GAAkB,CAAC,QAAA,GAAmB,EAAA,KAAe;AAEhE,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,UAAU,QAAA,EAAU;AAC9D,IAAA,OAAO,OAAO,QAAA,CAAS,QAAA;AAAA,EACzB;AAEA,EAAA,IAAI,OAAO,eAAe,WAAA,EAAa;AACrC,IAAA,MAAM,iBAAkB,UAAA,CACrB,QAAA;AACH,IAAA,IAAI,gBAAgB,QAAA,EAAU;AAC5B,MAAA,OAAO,cAAA,CAAe,QAAA;AAAA,IACxB;AAAA,EACF;AAEA,EAAA,OAAO,QAAA;AACT","file":"index.mjs","sourcesContent":["import type { SitemapBase, SitemapMatchBase } from \"./type\";\n\n/**\n * 현재 경로와 가장 근접한 경로 데이터 추출\n * @param {SitemapBase[]} routes 사이트맵 배열 데이터\n * @param {string} currentPath 현재 경로\n * @return {SitemapBase | null} 경로 데이터\n */\nexport const getClosestRoute = <Sitemap extends SitemapBase>(\n routes: Sitemap[],\n currentPath: string,\n): Sitemap | null => {\n let deepestMatch: Sitemap | null = null; // 가장 긴 prefix를 저장한다.\n for (const route of routes) {\n if (currentPath.startsWith(route.path)) {\n // 기존 match가 없거나 더 긴 path를 찾으면 교체한다.\n if (!deepestMatch || route.path.length > deepestMatch.path.length) {\n deepestMatch = route;\n }\n }\n }\n return deepestMatch;\n};\n\n/**\n * 경로 일치 데이터 추출\n * @util\n * @param {SitemapBase[]} routes 사이트맵 배열 데이터\n * @param {string} currentPath 현재 경로\n * @return {SitemapBase | undefined} 경로 데이터\n */\nexport const getMatchRoute = <\n Sitemap extends SitemapBase,\n SitemapMatched extends SitemapMatchBase,\n>(\n routes: Sitemap[],\n currentPath: string,\n): SitemapMatched => {\n const res: SitemapMatched = { category: null, depth: null } as SitemapMatched; // 반환 형식 초기화\n\n // 1 depth\n res.category = getClosestRoute<Sitemap>(routes, currentPath);\n\n // 2 depth\n if (res.category && res.category.depth) {\n res.depth = getClosestRoute<Sitemap>(\n res.category.depth as Sitemap[],\n currentPath,\n );\n }\n\n return res;\n};\n\n/**\n * 브라우저 환경 여부와 관계없이 안전하게 pathname을 추출한다.\n * @util\n * @param {string} fallback 브라우저가 아닌 환경에서 사용할 기본 경로\n * @return {string} 현재 경로 또는 fallback\n */\nexport const getSafePathname = (fallback: string = \"\"): string => {\n // CSR 환경: window.location.pathname 활용\n if (typeof window !== \"undefined\" && window.location?.pathname) {\n return window.location.pathname;\n }\n // SSR 또는 다른 런타임: globalThis.location을 검사\n if (typeof globalThis !== \"undefined\") {\n const globalLocation = (globalThis as { location?: { pathname?: string } })\n .location;\n if (globalLocation?.pathname) {\n return globalLocation.pathname;\n }\n }\n // 모든 환경에서 값이 없으면 fallback 반환\n return fallback;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniai-fe/util-functions",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "TypeScript Utilities for UNIAI FE Projects",
5
5
  "type": "module",
6
6
  "private": false,