@dub/utils 0.0.0
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/.turbo/turbo-build.log +24 -0
- package/dist/chunk-2U2IYZHN.mjs +1 -0
- package/dist/chunk-35O76FBU.mjs +2 -0
- package/dist/chunk-3P54C65P.mjs +1 -0
- package/dist/chunk-64C57Q4W.mjs +2 -0
- package/dist/chunk-64KMNIJU.mjs +2 -0
- package/dist/chunk-6MWSVUBA.mjs +1 -0
- package/dist/chunk-6YUAHP47.mjs +1 -0
- package/dist/chunk-D7V6QEC3.mjs +2 -0
- package/dist/chunk-G2EXSXOB.mjs +1 -0
- package/dist/chunk-GIGD5PB3.mjs +1 -0
- package/dist/chunk-H4LU5LOY.mjs +2 -0
- package/dist/chunk-H53DALDZ.mjs +1 -0
- package/dist/chunk-LEHV3NWH.mjs +2 -0
- package/dist/chunk-LXDQ4KMN.mjs +0 -0
- package/dist/chunk-M5FLGH3T.mjs +1 -0
- package/dist/chunk-MODISIUH.mjs +1 -0
- package/dist/chunk-MQNZDHLT.mjs +2 -0
- package/dist/chunk-OH6TH3J6.mjs +1 -0
- package/dist/chunk-ONIHRKH7.mjs +1 -0
- package/dist/chunk-TN4P6NPQ.mjs +1 -0
- package/dist/chunk-U4XQUV65.mjs +1 -0
- package/dist/chunk-UE5AMEFG.mjs +2 -0
- package/dist/chunk-UYE4FVX2.mjs +2 -0
- package/dist/chunk-V4HIRCCV.mjs +1 -0
- package/dist/chunk-W5IYXLXA.mjs +1 -0
- package/dist/chunk-XACKIZEQ.mjs +2 -0
- package/dist/chunk-Y2N4Y4WZ.mjs +1 -0
- package/dist/chunk-ZGU5QGQR.mjs +1 -0
- package/dist/constants/cctlds.d.ts +3 -0
- package/dist/constants/cctlds.mjs +1 -0
- package/dist/constants/content.d.ts +70 -0
- package/dist/constants/content.mjs +1 -0
- package/dist/constants/countries.d.ts +5 -0
- package/dist/constants/countries.mjs +1 -0
- package/dist/constants/index.d.ts +136 -0
- package/dist/constants/index.mjs +1 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.mjs +2 -0
- package/dist/hooks/use-current-anchor.d.ts +3 -0
- package/dist/hooks/use-current-anchor.mjs +2 -0
- package/dist/hooks/use-intersection-observer.d.ts +8 -0
- package/dist/hooks/use-intersection-observer.mjs +2 -0
- package/dist/hooks/use-local-storage.d.ts +3 -0
- package/dist/hooks/use-local-storage.mjs +2 -0
- package/dist/hooks/use-media-query.d.ts +10 -0
- package/dist/hooks/use-media-query.mjs +2 -0
- package/dist/hooks/use-scroll.d.ts +3 -0
- package/dist/hooks/use-scroll.mjs +2 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.mjs +1 -0
- package/dist/utils.d.ts +72 -0
- package/dist/utils.mjs +1 -0
- package/package.json +52 -0
- package/src/constants/cctlds.ts +276 -0
- package/src/constants/countries.ts +254 -0
- package/src/constants/index.ts +208 -0
- package/src/index.ts +540 -0
- package/tsconfig.json +5 -0
- package/tsup.config.ts +10 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as useCurrentAnchor } from './use-current-anchor.js';
|
|
2
|
+
export { default as useIntersectionObserver } from './use-intersection-observer.js';
|
|
3
|
+
export { default as useLocalStorage } from './use-local-storage.js';
|
|
4
|
+
export { default as useMediaQuery } from './use-media-query.js';
|
|
5
|
+
export { default as useScroll } from './use-scroll.js';
|
|
6
|
+
import 'react';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
import"../chunk-V4HIRCCV.mjs";import{a as b}from"../chunk-35O76FBU.mjs";import{a as c}from"../chunk-64KMNIJU.mjs";import{a as d}from"../chunk-64C57Q4W.mjs";import{a as e}from"../chunk-LEHV3NWH.mjs";import{a}from"../chunk-UYE4FVX2.mjs";export{a as useCurrentAnchor,b as useIntersectionObserver,c as useLocalStorage,d as useMediaQuery,e as useScroll};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Args extends IntersectionObserverInit {
|
|
4
|
+
freezeOnceVisible?: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare function useIntersectionObserver(elementRef: RefObject<Element>, { threshold, root, rootMargin, freezeOnceVisible, }: Args): IntersectionObserverEntry | undefined;
|
|
7
|
+
|
|
8
|
+
export { useIntersectionObserver as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
import { Metadata } from 'next';
|
|
3
|
+
import { NextRouter } from 'next/router';
|
|
4
|
+
export { ADMIN_HOSTNAMES, API_DOMAIN, API_HOSTNAMES, APP_DOMAIN, APP_DOMAIN_WITH_NGROK, APP_HOSTNAMES, DEFAULT_LINK_PROPS, DEFAULT_REDIRECTS, DUB_HEADERS, DUB_LOGO, DUB_PROJECT_ID, DUB_THUMBNAIL, FADE_IN_ANIMATION_SETTINGS, FAVICON_FOLDER, FRAMER_MOTION_LIST_ITEM_VARIANTS, GOOGLE_FAVICON_URL, HOME_DOMAIN, LOCALHOST_GEO_DATA, LOCALHOST_IP, PAGINATION_LIMIT, SAML_PROVIDERS, SECOND_LEVEL_DOMAINS, SHOW_BACKGROUND_SEGMENTS, SPECIAL_APEX_DOMAINS, STAGGER_CHILD_VARIANTS, SWIPE_REVEAL_ANIMATION_SETTINGS, allTools } from './constants/index.js';
|
|
5
|
+
export { default as ccTLDs } from './constants/cctlds.js';
|
|
6
|
+
export { default as COUNTRIES } from './constants/countries.js';
|
|
7
|
+
|
|
8
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
9
|
+
declare function constructMetadata({ title, description, image, icons, noIndex, }?: {
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
image?: string;
|
|
13
|
+
icons?: string;
|
|
14
|
+
noIndex?: boolean;
|
|
15
|
+
}): Metadata;
|
|
16
|
+
declare const nanoid: (size?: number | undefined) => string;
|
|
17
|
+
declare function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON>;
|
|
18
|
+
declare function nFormatter(num?: number, opts?: {
|
|
19
|
+
digits?: number;
|
|
20
|
+
full?: boolean;
|
|
21
|
+
}): string;
|
|
22
|
+
declare function capitalize(str: string): string;
|
|
23
|
+
declare const chunk: <T>(array: T[], chunk_size: number) => T[][];
|
|
24
|
+
declare function linkConstructor({ key, domain, localhost, pretty, noDomain, }: {
|
|
25
|
+
key: string;
|
|
26
|
+
domain?: string;
|
|
27
|
+
localhost?: boolean;
|
|
28
|
+
pretty?: boolean;
|
|
29
|
+
noDomain?: boolean;
|
|
30
|
+
}): string;
|
|
31
|
+
declare const timeAgo: (timestamp: Date | null, { withAgo, }?: {
|
|
32
|
+
withAgo?: boolean | undefined;
|
|
33
|
+
}) => string;
|
|
34
|
+
declare const getDateTimeLocal: (timestamp?: Date) => string;
|
|
35
|
+
declare const formatDate: (dateString: string) => string;
|
|
36
|
+
declare const getFirstAndLastDay: (day: number) => {
|
|
37
|
+
firstDay: Date;
|
|
38
|
+
lastDay: Date;
|
|
39
|
+
};
|
|
40
|
+
declare const getLastDayOfMonth: () => number;
|
|
41
|
+
declare const getAdjustedBillingCycleStart: (billingCycleStart: number) => number;
|
|
42
|
+
declare const generateDomainFromName: (name: string) => string;
|
|
43
|
+
declare const validDomainRegex: RegExp;
|
|
44
|
+
declare const validKeyRegex: RegExp;
|
|
45
|
+
declare const validSlugRegex: RegExp;
|
|
46
|
+
declare const getSubdomain: (name: string, apexName: string) => string | null;
|
|
47
|
+
declare const getApexDomain: (url: string) => string;
|
|
48
|
+
declare const isValidUrl: (url: string) => boolean;
|
|
49
|
+
declare const getUrlFromString: (str: string) => string | null | undefined;
|
|
50
|
+
declare const getDomainWithoutWWW: (url: string) => string | null | undefined;
|
|
51
|
+
declare const getQueryString: (router: NextRouter, opts?: Record<string, string>) => string;
|
|
52
|
+
declare const setQueryString: ({ router, param, value, }: {
|
|
53
|
+
router: NextRouter;
|
|
54
|
+
param: string;
|
|
55
|
+
value: string;
|
|
56
|
+
}) => void;
|
|
57
|
+
declare const truncate: (str: string | null, length: number) => string | null;
|
|
58
|
+
declare const getParamsFromURL: (url: string) => Record<string, string>;
|
|
59
|
+
declare const constructURLFromUTMParams: (url: string, utmParams: Record<string, string>) => string;
|
|
60
|
+
declare const paramsMetadata: {
|
|
61
|
+
display: string;
|
|
62
|
+
key: string;
|
|
63
|
+
examples: string;
|
|
64
|
+
}[];
|
|
65
|
+
declare const getUrlWithoutUTMParams: (url: string) => string;
|
|
66
|
+
declare function generateMD5Hash(message: string): Promise<string>;
|
|
67
|
+
declare const log: ({ message, type, mention, }: {
|
|
68
|
+
message: string;
|
|
69
|
+
type: "cron" | "links";
|
|
70
|
+
mention?: boolean | undefined;
|
|
71
|
+
}) => Promise<Response | undefined>;
|
|
72
|
+
type DeepEqual = (obj1: Record<string, any>, obj2: Record<string, any>) => boolean;
|
|
73
|
+
declare const deepEqual: DeepEqual;
|
|
74
|
+
|
|
75
|
+
export { capitalize, chunk, cn, constructMetadata, constructURLFromUTMParams, deepEqual, fetcher, formatDate, generateDomainFromName, generateMD5Hash, getAdjustedBillingCycleStart, getApexDomain, getDateTimeLocal, getDomainWithoutWWW, getFirstAndLastDay, getLastDayOfMonth, getParamsFromURL, getQueryString, getSubdomain, getUrlFromString, getUrlWithoutUTMParams, isValidUrl, linkConstructor, log, nFormatter, nanoid, paramsMetadata, setQueryString, timeAgo, truncate, validDomainRegex, validKeyRegex, validSlugRegex };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A as j,a as S,b as R,c as U,d as k,e as L,f as v,g as M,h as c,i as O,j as _,k as $,l as T,m as A,n as E,o as F,p as N,q as C,r as q,s as I,t as K,u as P,v as z,w as l,x as u,y as H,z as Z}from"./chunk-Y2N4Y4WZ.mjs";import{a}from"./chunk-MODISIUH.mjs";import{a as b}from"./chunk-3P54C65P.mjs";import p from"@sindresorhus/slugify";import{clsx as m}from"clsx";import f from"ms";import{customAlphabet as h}from"nanoid";import{twMerge as y}from"tailwind-merge";function G(...e){return y(m(e))}function X({title:e="Dub - Link Management for Modern Marketing Teams",description:t="Dub is an open-source link management tool for modern marketing teams to create, share, and track short links.",image:r="https://dub.co/_static/thumbnail.png",icons:o="/favicon.ico",noIndex:n=!1}={}){return{title:e,description:t,openGraph:{title:e,description:t,images:[{url:r}]},twitter:{card:"summary_large_image",title:e,description:t,images:[r],creator:"@dubdotco"},icons:o,metadataBase:new URL(c),themeColor:"#FFF",...n&&{robots:{index:!1,follow:!1}}}}var ee=h("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7);async function te(e,t){let r=await fetch(e,t);if(!r.ok){let o=await r.text(),n=new Error(o);throw n.status=r.status,n}return r.json()}function re(e,t={digits:1}){if(!e)return"0";if(t.full)return Intl.NumberFormat("en-US").format(e);let r=[{value:1,symbol:""},{value:1e3,symbol:"K"},{value:1e6,symbol:"M"},{value:1e9,symbol:"G"},{value:1e12,symbol:"T"},{value:1e15,symbol:"P"},{value:1e18,symbol:"E"}],o=/\.0+$|(\.[0-9]*[1-9])0+$/;var n=r.slice().reverse().find(function(s){return e>=s.value});return n?(e/n.value).toFixed(t.digits).replace(o,"$1")+n.symbol:"0"}function ne(e){return!e||typeof e!="string"?e:e.charAt(0).toUpperCase()+e.slice(1)}var oe=(e,t)=>e.reduce((r,o,n)=>{let s=Math.floor(n/t);return r[s]||(r[s]=[]),r[s].push(o),r},[]);function se({key:e,domain:t="dub.sh",localhost:r,pretty:o,noDomain:n}){let s=`${r?"http://home.localhost:8888":`https://${t}`}${e!=="_root"?`/${e}`:""}`;return n?`/${e}`:o?s.replace(/^https?:\/\//,""):s}var ae=(e,{withAgo:t}={})=>{if(!e)return"Never";let r=Date.now()-new Date(e).getTime();return r<1e3?"Just now":r>828e5?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:new Date(e).getFullYear()!==new Date().getFullYear()?"numeric":void 0}):`${f(r)}${t?" ago":""}`},ie=e=>{let t=e?new Date(e):new Date;return t.toString()==="Invalid Date"?"":new Date(t.getTime()-t.getTimezoneOffset()*6e4).toISOString().split(":").slice(0,2).join(":")},ce=e=>new Date(`${e}T00:00:00Z`).toLocaleDateString("en-US",{day:"numeric",month:"long",year:"numeric",timeZone:"UTC"}),le=e=>{let t=new Date,r=t.getDate(),o=t.getMonth(),n=t.getFullYear();if(r>=e)return{firstDay:new Date(n,o,e),lastDay:new Date(n,o+1,e-1)};{let s=o===0?n-1:n,i=o===0?11:o-1;return{firstDay:new Date(s,i,e),lastDay:new Date(n,o,e-1)}}},d=()=>{let e=new Date;return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()},ue=e=>{let t=d();return e>t?t:e},ge=e=>{let t=p(e,{separator:""});if(t.length<3)return"";if(a.has(t.slice(-2)))return`${t.slice(0,-2)}.${t.slice(-2)}`;let r=t.replace(/[aeiou]/g,"");return r.length>=3&&a.has(r.slice(-2))?`${r.slice(0,-2)}.${r.slice(-2)}`:`${[t,r].reduce((n,s)=>n.length<s.length?n:s)}.to`},pe=new RegExp(/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/),me=new RegExp(/^[0-9A-Za-z\u0080-\uFFFF\/\-]*$/u),fe=new RegExp(/^[a-zA-Z0-9\-]+$/),he=(e,t)=>e===t?null:e.slice(0,e.length-t.length-1),ye=e=>{let t;try{t=new URL(e.replace(/^[a-zA-Z]+:\/\//,"https://")).hostname}catch{return""}if(t==="youtu.be")return"youtube.com";if(t==="raw.githubusercontent.com")return"github.com";if(t.endsWith(".vercel.app"))return"vercel.app";let r=t.split(".");return r.length>2?l.has(r[r.length-2])&&a.has(r[r.length-1])||u.has(r.slice(-2).join("."))?r.slice(-3).join("."):r.slice(-2).join("."):t},g=e=>{try{return new URL(e),!0}catch{return!1}},de=e=>{if(g(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch{return null}},xe=e=>{if(g(e))return new URL(e).hostname.replace(/^www\./,"");try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).hostname.replace(/^www\./,"")}catch{return null}},De=(e,t)=>{let r=new URLSearchParams({...e.query,...t}).toString();return`${r?"?":""}${r}`},we=({router:e,param:t,value:r})=>{t!=="page"&&delete e.query.page;let o;r.length>0?o={...e.query,[t]:r}:(delete e.query[t],o={...e.query});let{slug:n,...s}=o;e.replace({pathname:`/${e.query.slug||"links"}`,query:s})},be=(e,t)=>!e||e.length<=t?e:`${e.slice(0,t-3)}...`,Se=e=>{if(!e)return{};try{let t=new URL(e).searchParams,r={};for(let[o,n]of t.entries())n&&n!==""&&(r[o]=n);return r}catch{return{}}},Re=(e,t)=>{if(!e)return"";try{let r=new URL(e);for(let[o,n]of Object.entries(t))n===""?r.searchParams.delete(o):r.searchParams.set(o,n);return r.toString()}catch{return""}},x=[{display:"Referral (ref)",key:"ref",examples:"twitter, facebook"},{display:"UTM Source",key:"utm_source",examples:"twitter, facebook"},{display:"UTM Medium",key:"utm_medium",examples:"social, email"},{display:"UTM Campaign",key:"utm_campaign",examples:"summer_sale"},{display:"UTM Term",key:"utm_term",examples:"blue_shoes"},{display:"UTM Content",key:"utm_content",examples:"logolink"}],Ue=e=>{try{let t=new URL(e);return x.forEach(r=>t.searchParams.delete(r.key)),t.toString()}catch{return e}};async function ke(e){let r=new TextEncoder().encode(e),o=await crypto.subtle.digest("MD5",r);return Array.from(new Uint8Array(o)).map(i=>i.toString(16).padStart(2,"0")).join("")}var D={cron:process.env.DUB_SLACK_HOOK_CRON,links:process.env.DUB_SLACK_HOOK_LINKS},Le=async({message:e,type:t,mention:r=!1})=>{(process.env.NODE_ENV==="development"||!process.env.DUB_SLACK_HOOK_CRON||!process.env.DUB_SLACK_HOOK_LINKS)&&console.log(e);let o=D[t];if(!!o)try{return await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({blocks:[{type:"section",text:{type:"mrkdwn",text:`${r?"<@U0404G6J3NJ> ":""}${e}`}}]})})}catch(n){console.log(`Failed to log to Dub Slack. Error: ${n}`)}},w=(e,t)=>{if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;let r=Object.keys(e),o=Object.keys(t);if(r.length!==o.length)return!1;for(let n of r)if(!o.includes(n)||!w(e[n],t[n]))return!1;return!0};export{E as ADMIN_HOSTNAMES,A as API_DOMAIN,T as API_HOSTNAMES,_ as APP_DOMAIN,$ as APP_DOMAIN_WITH_NGROK,O as APP_HOSTNAMES,b as COUNTRIES,H as DEFAULT_LINK_PROPS,F as DEFAULT_REDIRECTS,N as DUB_HEADERS,I as DUB_LOGO,Z as DUB_PROJECT_ID,K as DUB_THUMBNAIL,v as FADE_IN_ANIMATION_SETTINGS,C as FAVICON_FOLDER,U as FRAMER_MOTION_LIST_ITEM_VARIANTS,q as GOOGLE_FAVICON_URL,c as HOME_DOMAIN,S as LOCALHOST_GEO_DATA,R as LOCALHOST_IP,M as PAGINATION_LIMIT,j as SAML_PROVIDERS,l as SECOND_LEVEL_DOMAINS,P as SHOW_BACKGROUND_SEGMENTS,u as SPECIAL_APEX_DOMAINS,k as STAGGER_CHILD_VARIANTS,L as SWIPE_REVEAL_ANIMATION_SETTINGS,z as allTools,ne as capitalize,a as ccTLDs,oe as chunk,G as cn,X as constructMetadata,Re as constructURLFromUTMParams,w as deepEqual,te as fetcher,ce as formatDate,ge as generateDomainFromName,ke as generateMD5Hash,ue as getAdjustedBillingCycleStart,ye as getApexDomain,ie as getDateTimeLocal,xe as getDomainWithoutWWW,le as getFirstAndLastDay,d as getLastDayOfMonth,Se as getParamsFromURL,De as getQueryString,he as getSubdomain,de as getUrlFromString,Ue as getUrlWithoutUTMParams,g as isValidUrl,se as linkConstructor,Le as log,re as nFormatter,ee as nanoid,x as paramsMetadata,we as setQueryString,ae as timeAgo,be as truncate,pe as validDomainRegex,me as validKeyRegex,fe as validSlugRegex};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
import { Metadata } from 'next';
|
|
3
|
+
import { NextRouter } from 'next/router';
|
|
4
|
+
|
|
5
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
6
|
+
declare function constructMetadata({ title, description, image, icons, noIndex, }?: {
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
image?: string;
|
|
10
|
+
icons?: string;
|
|
11
|
+
noIndex?: boolean;
|
|
12
|
+
}): Metadata;
|
|
13
|
+
declare const nanoid: (size?: number | undefined) => string;
|
|
14
|
+
declare function fetcher<JSON = any>(input: RequestInfo, init?: RequestInit): Promise<JSON>;
|
|
15
|
+
declare function nFormatter(num?: number, opts?: {
|
|
16
|
+
digits?: number;
|
|
17
|
+
full?: boolean;
|
|
18
|
+
}): string;
|
|
19
|
+
declare function capitalize(str: string): string;
|
|
20
|
+
declare const chunk: <T>(array: T[], chunk_size: number) => T[][];
|
|
21
|
+
declare function linkConstructor({ key, domain, localhost, pretty, noDomain, }: {
|
|
22
|
+
key: string;
|
|
23
|
+
domain?: string;
|
|
24
|
+
localhost?: boolean;
|
|
25
|
+
pretty?: boolean;
|
|
26
|
+
noDomain?: boolean;
|
|
27
|
+
}): string;
|
|
28
|
+
declare const timeAgo: (timestamp: Date | null, { withAgo, }?: {
|
|
29
|
+
withAgo?: boolean | undefined;
|
|
30
|
+
}) => string;
|
|
31
|
+
declare const getDateTimeLocal: (timestamp?: Date) => string;
|
|
32
|
+
declare const formatDate: (dateString: string) => string;
|
|
33
|
+
declare const getFirstAndLastDay: (day: number) => {
|
|
34
|
+
firstDay: Date;
|
|
35
|
+
lastDay: Date;
|
|
36
|
+
};
|
|
37
|
+
declare const getLastDayOfMonth: () => number;
|
|
38
|
+
declare const getAdjustedBillingCycleStart: (billingCycleStart: number) => number;
|
|
39
|
+
declare const generateDomainFromName: (name: string) => string;
|
|
40
|
+
declare const validDomainRegex: RegExp;
|
|
41
|
+
declare const validKeyRegex: RegExp;
|
|
42
|
+
declare const validSlugRegex: RegExp;
|
|
43
|
+
declare const getSubdomain: (name: string, apexName: string) => string | null;
|
|
44
|
+
declare const getApexDomain: (url: string) => string;
|
|
45
|
+
declare const isValidUrl: (url: string) => boolean;
|
|
46
|
+
declare const getUrlFromString: (str: string) => string | null | undefined;
|
|
47
|
+
declare const getDomainWithoutWWW: (url: string) => string | null | undefined;
|
|
48
|
+
declare const getQueryString: (router: NextRouter, opts?: Record<string, string>) => string;
|
|
49
|
+
declare const setQueryString: ({ router, param, value, }: {
|
|
50
|
+
router: NextRouter;
|
|
51
|
+
param: string;
|
|
52
|
+
value: string;
|
|
53
|
+
}) => void;
|
|
54
|
+
declare const truncate: (str: string | null, length: number) => string | null;
|
|
55
|
+
declare const getParamsFromURL: (url: string) => Record<string, string>;
|
|
56
|
+
declare const constructURLFromUTMParams: (url: string, utmParams: Record<string, string>) => string;
|
|
57
|
+
declare const paramsMetadata: {
|
|
58
|
+
display: string;
|
|
59
|
+
key: string;
|
|
60
|
+
examples: string;
|
|
61
|
+
}[];
|
|
62
|
+
declare const getUrlWithoutUTMParams: (url: string) => string;
|
|
63
|
+
declare function generateMD5Hash(message: string): Promise<string>;
|
|
64
|
+
declare const log: ({ message, type, mention, }: {
|
|
65
|
+
message: string;
|
|
66
|
+
type: "cron" | "links";
|
|
67
|
+
mention?: boolean | undefined;
|
|
68
|
+
}) => Promise<Response | undefined>;
|
|
69
|
+
type DeepEqual = (obj1: Record<string, any>, obj2: Record<string, any>) => boolean;
|
|
70
|
+
declare const deepEqual: DeepEqual;
|
|
71
|
+
|
|
72
|
+
export { capitalize, chunk, cn, constructMetadata, constructURLFromUTMParams, deepEqual, fetcher, formatDate, generateDomainFromName, generateMD5Hash, getAdjustedBillingCycleStart, getApexDomain, getDateTimeLocal, getDomainWithoutWWW, getFirstAndLastDay, getLastDayOfMonth, getParamsFromURL, getQueryString, getSubdomain, getUrlFromString, getUrlWithoutUTMParams, isValidUrl, linkConstructor, log, nFormatter, nanoid, paramsMetadata, setQueryString, timeAgo, truncate, validDomainRegex, validKeyRegex, validSlugRegex };
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{A,B,C,D,E,F,G,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-OH6TH3J6.mjs";import"./chunk-Y2N4Y4WZ.mjs";import"./chunk-MODISIUH.mjs";import"./chunk-3P54C65P.mjs";export{f as capitalize,g as chunk,a as cn,b as constructMetadata,B as constructURLFromUTMParams,G as deepEqual,d as fetcher,k as formatDate,o as generateDomainFromName,E as generateMD5Hash,n as getAdjustedBillingCycleStart,t as getApexDomain,j as getDateTimeLocal,w as getDomainWithoutWWW,l as getFirstAndLastDay,m as getLastDayOfMonth,A as getParamsFromURL,x as getQueryString,s as getSubdomain,v as getUrlFromString,D as getUrlWithoutUTMParams,u as isValidUrl,h as linkConstructor,F as log,e as nFormatter,c as nanoid,C as paramsMetadata,y as setQueryString,i as timeAgo,z as truncate,p as validDomainRegex,q as validKeyRegex,r as validSlugRegex};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dub/utils",
|
|
3
|
+
"description": "Utility functions and constants for Dub.co",
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsup",
|
|
11
|
+
"lint": "eslint src/",
|
|
12
|
+
"dev": "tsup --watch",
|
|
13
|
+
"check-types": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": "^18.2.0",
|
|
17
|
+
"next": "13.5.4"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/ms": "^0.7.31",
|
|
21
|
+
"@types/node": "18.11.9",
|
|
22
|
+
"@types/react": "^18.2.5",
|
|
23
|
+
"react": "^18.2.0",
|
|
24
|
+
"next": "13.5.4",
|
|
25
|
+
"tsconfig": "workspace:*",
|
|
26
|
+
"tsup": "^6.1.3",
|
|
27
|
+
"typescript": "^5.1.6"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@sindresorhus/slugify": "^2.2.1",
|
|
31
|
+
"clsx": "^1.2.1",
|
|
32
|
+
"ms": "^2.1.3",
|
|
33
|
+
"nanoid": "^5.0.1",
|
|
34
|
+
"tailwind-merge": "^1.13.2"
|
|
35
|
+
},
|
|
36
|
+
"author": "Steven Tey <stevensteel97@gmail.com>",
|
|
37
|
+
"homepage": "https://dub.co",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/steven-tey/dub.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/steven-tey/dub/issues"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"dub",
|
|
47
|
+
"dub.co",
|
|
48
|
+
"utils",
|
|
49
|
+
"utility",
|
|
50
|
+
"functions"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
const ccTLDs = new Set([
|
|
2
|
+
"af",
|
|
3
|
+
"ax",
|
|
4
|
+
"al",
|
|
5
|
+
"dz",
|
|
6
|
+
"as",
|
|
7
|
+
"ad",
|
|
8
|
+
"ao",
|
|
9
|
+
"ai",
|
|
10
|
+
"aq",
|
|
11
|
+
"ag",
|
|
12
|
+
"ar",
|
|
13
|
+
"am",
|
|
14
|
+
"aw",
|
|
15
|
+
"ac",
|
|
16
|
+
"au",
|
|
17
|
+
"at",
|
|
18
|
+
"az",
|
|
19
|
+
"bs",
|
|
20
|
+
"bh",
|
|
21
|
+
"bd",
|
|
22
|
+
"bb",
|
|
23
|
+
"eus",
|
|
24
|
+
"by",
|
|
25
|
+
"be",
|
|
26
|
+
"bz",
|
|
27
|
+
"bj",
|
|
28
|
+
"bm",
|
|
29
|
+
"bt",
|
|
30
|
+
"bo",
|
|
31
|
+
"bq",
|
|
32
|
+
"an",
|
|
33
|
+
"nl",
|
|
34
|
+
"ba",
|
|
35
|
+
"bw",
|
|
36
|
+
"bv",
|
|
37
|
+
"br",
|
|
38
|
+
"io",
|
|
39
|
+
"vg",
|
|
40
|
+
"bn",
|
|
41
|
+
"bg",
|
|
42
|
+
"bf",
|
|
43
|
+
"mm",
|
|
44
|
+
"bi",
|
|
45
|
+
"kh",
|
|
46
|
+
"cm",
|
|
47
|
+
"ca",
|
|
48
|
+
"cv",
|
|
49
|
+
"cat",
|
|
50
|
+
"ky",
|
|
51
|
+
"cf",
|
|
52
|
+
"td",
|
|
53
|
+
"cl",
|
|
54
|
+
"cn",
|
|
55
|
+
"cx",
|
|
56
|
+
"cc",
|
|
57
|
+
"co",
|
|
58
|
+
"km",
|
|
59
|
+
"cd",
|
|
60
|
+
"cg",
|
|
61
|
+
"ck",
|
|
62
|
+
"cr",
|
|
63
|
+
"ci",
|
|
64
|
+
"hr",
|
|
65
|
+
"cu",
|
|
66
|
+
"cw",
|
|
67
|
+
"cy",
|
|
68
|
+
"cz",
|
|
69
|
+
"dk",
|
|
70
|
+
"dj",
|
|
71
|
+
"dm",
|
|
72
|
+
"do",
|
|
73
|
+
"tl",
|
|
74
|
+
"tp",
|
|
75
|
+
"ec",
|
|
76
|
+
"eg",
|
|
77
|
+
"sv",
|
|
78
|
+
"gq",
|
|
79
|
+
"er",
|
|
80
|
+
"ee",
|
|
81
|
+
"et",
|
|
82
|
+
"eu",
|
|
83
|
+
"fk",
|
|
84
|
+
"fo",
|
|
85
|
+
"fm",
|
|
86
|
+
"fj",
|
|
87
|
+
"fi",
|
|
88
|
+
"fr",
|
|
89
|
+
"gf",
|
|
90
|
+
"pf",
|
|
91
|
+
"tf",
|
|
92
|
+
"ga",
|
|
93
|
+
"gal",
|
|
94
|
+
"gm",
|
|
95
|
+
"ps",
|
|
96
|
+
"ge",
|
|
97
|
+
"de",
|
|
98
|
+
"gh",
|
|
99
|
+
"gi",
|
|
100
|
+
"gr",
|
|
101
|
+
"gl",
|
|
102
|
+
"gd",
|
|
103
|
+
"gp",
|
|
104
|
+
"gu",
|
|
105
|
+
"gt",
|
|
106
|
+
"gg",
|
|
107
|
+
"gn",
|
|
108
|
+
"gw",
|
|
109
|
+
"gy",
|
|
110
|
+
"ht",
|
|
111
|
+
"hm",
|
|
112
|
+
"hn",
|
|
113
|
+
"hk",
|
|
114
|
+
"hu",
|
|
115
|
+
"is",
|
|
116
|
+
"in",
|
|
117
|
+
"id",
|
|
118
|
+
"ir",
|
|
119
|
+
"iq",
|
|
120
|
+
"ie",
|
|
121
|
+
"im",
|
|
122
|
+
"il",
|
|
123
|
+
"it",
|
|
124
|
+
"jm",
|
|
125
|
+
"jp",
|
|
126
|
+
"je",
|
|
127
|
+
"jo",
|
|
128
|
+
"kz",
|
|
129
|
+
"ke",
|
|
130
|
+
"ki",
|
|
131
|
+
"kw",
|
|
132
|
+
"kg",
|
|
133
|
+
"la",
|
|
134
|
+
"lv",
|
|
135
|
+
"lb",
|
|
136
|
+
"ls",
|
|
137
|
+
"lr",
|
|
138
|
+
"ly",
|
|
139
|
+
"li",
|
|
140
|
+
"lt",
|
|
141
|
+
"lu",
|
|
142
|
+
"mo",
|
|
143
|
+
"mk",
|
|
144
|
+
"mg",
|
|
145
|
+
"mw",
|
|
146
|
+
"my",
|
|
147
|
+
"mv",
|
|
148
|
+
"ml",
|
|
149
|
+
"mt",
|
|
150
|
+
"mh",
|
|
151
|
+
"mq",
|
|
152
|
+
"mr",
|
|
153
|
+
"mu",
|
|
154
|
+
"yt",
|
|
155
|
+
"mx",
|
|
156
|
+
"md",
|
|
157
|
+
"mc",
|
|
158
|
+
"mn",
|
|
159
|
+
"me",
|
|
160
|
+
"ms",
|
|
161
|
+
"ma",
|
|
162
|
+
"mz",
|
|
163
|
+
"mm",
|
|
164
|
+
"na",
|
|
165
|
+
"nr",
|
|
166
|
+
"np",
|
|
167
|
+
"nl",
|
|
168
|
+
"nc",
|
|
169
|
+
"nz",
|
|
170
|
+
"ni",
|
|
171
|
+
"ne",
|
|
172
|
+
"ng",
|
|
173
|
+
"nu",
|
|
174
|
+
"nf",
|
|
175
|
+
"nc",
|
|
176
|
+
"tr",
|
|
177
|
+
"kp",
|
|
178
|
+
"mp",
|
|
179
|
+
"no",
|
|
180
|
+
"om",
|
|
181
|
+
"pk",
|
|
182
|
+
"pw",
|
|
183
|
+
"ps",
|
|
184
|
+
"pa",
|
|
185
|
+
"pg",
|
|
186
|
+
"py",
|
|
187
|
+
"pe",
|
|
188
|
+
"ph",
|
|
189
|
+
"pn",
|
|
190
|
+
"pl",
|
|
191
|
+
"pt",
|
|
192
|
+
"pr",
|
|
193
|
+
"qa",
|
|
194
|
+
"ro",
|
|
195
|
+
"ru",
|
|
196
|
+
"rw",
|
|
197
|
+
"re",
|
|
198
|
+
"bq",
|
|
199
|
+
"an",
|
|
200
|
+
"bl",
|
|
201
|
+
"gp",
|
|
202
|
+
"fr",
|
|
203
|
+
"sh",
|
|
204
|
+
"kn",
|
|
205
|
+
"lc",
|
|
206
|
+
"mf",
|
|
207
|
+
"gp",
|
|
208
|
+
"fr",
|
|
209
|
+
"pm",
|
|
210
|
+
"vc",
|
|
211
|
+
"ws",
|
|
212
|
+
"sm",
|
|
213
|
+
"st",
|
|
214
|
+
"sa",
|
|
215
|
+
"sn",
|
|
216
|
+
"rs",
|
|
217
|
+
"sc",
|
|
218
|
+
"sl",
|
|
219
|
+
"sg",
|
|
220
|
+
"bq",
|
|
221
|
+
"an",
|
|
222
|
+
"nl",
|
|
223
|
+
"sx",
|
|
224
|
+
"an",
|
|
225
|
+
"sk",
|
|
226
|
+
"si",
|
|
227
|
+
"sb",
|
|
228
|
+
"so",
|
|
229
|
+
"so",
|
|
230
|
+
"za",
|
|
231
|
+
"gs",
|
|
232
|
+
"kr",
|
|
233
|
+
"ss",
|
|
234
|
+
"es",
|
|
235
|
+
"lk",
|
|
236
|
+
"sd",
|
|
237
|
+
"sr",
|
|
238
|
+
"sj",
|
|
239
|
+
"sz",
|
|
240
|
+
"se",
|
|
241
|
+
"ch",
|
|
242
|
+
"sy",
|
|
243
|
+
"tw",
|
|
244
|
+
"tj",
|
|
245
|
+
"tz",
|
|
246
|
+
"th",
|
|
247
|
+
"tg",
|
|
248
|
+
"tk",
|
|
249
|
+
"to",
|
|
250
|
+
"tt",
|
|
251
|
+
"tn",
|
|
252
|
+
"tr",
|
|
253
|
+
"tm",
|
|
254
|
+
"tc",
|
|
255
|
+
"tv",
|
|
256
|
+
"ug",
|
|
257
|
+
"ua",
|
|
258
|
+
"ae",
|
|
259
|
+
"uk",
|
|
260
|
+
"us",
|
|
261
|
+
"vi",
|
|
262
|
+
"uy",
|
|
263
|
+
"uz",
|
|
264
|
+
"vu",
|
|
265
|
+
"va",
|
|
266
|
+
"ve",
|
|
267
|
+
"vn",
|
|
268
|
+
"wf",
|
|
269
|
+
"eh",
|
|
270
|
+
"ma",
|
|
271
|
+
"ye",
|
|
272
|
+
"zm",
|
|
273
|
+
"zw",
|
|
274
|
+
]);
|
|
275
|
+
|
|
276
|
+
export default ccTLDs;
|