@dub/utils 0.0.2 → 0.0.4

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # `@dub/utils`
2
+
3
+ `@dub/utils` is a library of utility functions that are used across Dub.co's web applications.
4
+
5
+ ## Installation
6
+
7
+ To install the package, run:
8
+
9
+ ```bash
10
+ pnpm i @dub/utils
11
+ ```
@@ -0,0 +1 @@
1
+ var o=Object.defineProperty,p=Object.defineProperties;var q=Object.getOwnPropertyDescriptors;var f=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,l=Object.prototype.propertyIsEnumerable;var j=(a,c,b)=>c in a?o(a,c,{enumerable:!0,configurable:!0,writable:!0,value:b}):a[c]=b,r=(a,c)=>{for(var b in c||(c={}))k.call(c,b)&&j(a,b,c[b]);if(f)for(var b of f(c))l.call(c,b)&&j(a,b,c[b]);return a},s=(a,c)=>p(a,q(c));var t=(a,c)=>{var b={};for(var d in a)k.call(a,d)&&c.indexOf(d)<0&&(b[d]=a[d]);if(a!=null&&f)for(var d of f(a))c.indexOf(d)<0&&l.call(a,d)&&(b[d]=a[d]);return b};var u=(a,c,b)=>new Promise((d,i)=>{var m=e=>{try{g(b.next(e))}catch(h){i(h)}},n=e=>{try{g(b.throw(e))}catch(h){i(h)}},g=e=>e.done?d(e.value):Promise.resolve(e.value).then(m,n);g((b=b.apply(a,c)).next())});export{r as a,s as b,t as c,u as d};
@@ -0,0 +1,3 @@
1
+ declare const ccTLDs: Set<string>;
2
+
3
+ export { ccTLDs as default };
@@ -1 +1 @@
1
- import{a}from"../chunk-MODISIUH.mjs";export{a as default};
1
+ import{a}from"../chunk-MODISIUH.mjs";import"../chunk-GK743T7Z.mjs";export{a as default};
@@ -0,0 +1,5 @@
1
+ declare const COUNTRIES: {
2
+ [key: string]: string;
3
+ };
4
+
5
+ export { COUNTRIES as default };
@@ -1 +1 @@
1
- import{a}from"../chunk-3P54C65P.mjs";export{a as default};
1
+ import{a}from"../chunk-3P54C65P.mjs";import"../chunk-GK743T7Z.mjs";export{a as default};
@@ -0,0 +1,139 @@
1
+ export { default as ccTLDs } from './cctlds.mjs';
2
+ export { default as COUNTRIES } from './countries.mjs';
3
+
4
+ declare const LOCALHOST_GEO_DATA: {
5
+ city: string;
6
+ region: string;
7
+ country: string;
8
+ latitude: string;
9
+ longitude: string;
10
+ };
11
+ declare const LOCALHOST_IP = "63.141.57.109";
12
+ declare const FRAMER_MOTION_LIST_ITEM_VARIANTS: {
13
+ hidden: {
14
+ scale: number;
15
+ opacity: number;
16
+ };
17
+ show: {
18
+ scale: number;
19
+ opacity: number;
20
+ transition: {
21
+ type: string;
22
+ };
23
+ };
24
+ };
25
+ declare const STAGGER_CHILD_VARIANTS: {
26
+ hidden: {
27
+ opacity: number;
28
+ y: number;
29
+ };
30
+ show: {
31
+ opacity: number;
32
+ y: number;
33
+ transition: {
34
+ duration: number;
35
+ type: string;
36
+ };
37
+ };
38
+ };
39
+ declare const SWIPE_REVEAL_ANIMATION_SETTINGS: {
40
+ initial: {
41
+ height: number;
42
+ };
43
+ animate: {
44
+ height: string;
45
+ };
46
+ exit: {
47
+ height: number;
48
+ };
49
+ transition: {
50
+ duration: number;
51
+ ease: string;
52
+ };
53
+ };
54
+ declare const FADE_IN_ANIMATION_SETTINGS: {
55
+ initial: {
56
+ opacity: number;
57
+ };
58
+ animate: {
59
+ opacity: number;
60
+ };
61
+ exit: {
62
+ opacity: number;
63
+ };
64
+ transition: {
65
+ duration: number;
66
+ };
67
+ };
68
+ declare const PAGINATION_LIMIT = 100;
69
+ declare const HOME_DOMAIN = "https://dub.co";
70
+ declare const APP_HOSTNAMES: Set<string>;
71
+ declare const APP_DOMAIN: string;
72
+ declare const APP_DOMAIN_WITH_NGROK: string | undefined;
73
+ declare const API_HOSTNAMES: Set<string>;
74
+ declare const API_DOMAIN: string;
75
+ declare const ADMIN_HOSTNAMES: Set<string>;
76
+ declare const DEFAULT_REDIRECTS: {
77
+ home: string;
78
+ dub: string;
79
+ signin: string;
80
+ login: string;
81
+ register: string;
82
+ signup: string;
83
+ app: string;
84
+ dashboard: string;
85
+ links: string;
86
+ settings: string;
87
+ welcome: string;
88
+ discord: string;
89
+ tags: string;
90
+ };
91
+ declare const DUB_HEADERS: {
92
+ headers: {
93
+ "x-powered-by": string;
94
+ };
95
+ };
96
+ declare const FAVICON_FOLDER = "/_static/favicons";
97
+ declare const GOOGLE_FAVICON_URL = "https://www.google.com/s2/favicons?sz=64&domain_url=";
98
+ declare const DUB_LOGO = "https://d2vwwcvoksz7ty.cloudfront.net/logo.png";
99
+ declare const DUB_THUMBNAIL = "https://d2vwwcvoksz7ty.cloudfront.net/thumbnail.png";
100
+ declare const SHOW_BACKGROUND_SEGMENTS: string[];
101
+ declare const ALL_TOOLS: {
102
+ name: string;
103
+ slug: string;
104
+ }[];
105
+
106
+ declare const SECOND_LEVEL_DOMAINS: Set<string>;
107
+ declare const SPECIAL_APEX_DOMAINS: Set<string>;
108
+ declare const DEFAULT_LINK_PROPS: {
109
+ key: string;
110
+ url: string;
111
+ domain: string;
112
+ archived: boolean;
113
+ expiresAt: null;
114
+ password: null;
115
+ title: null;
116
+ description: null;
117
+ image: null;
118
+ rewrite: boolean;
119
+ ios: null;
120
+ android: null;
121
+ clicks: number;
122
+ userId: string;
123
+ proxy: boolean;
124
+ };
125
+ declare const DUB_PROJECT_ID = "cl7pj5kq4006835rbjlt2ofka";
126
+ declare const SAML_PROVIDERS: {
127
+ name: string;
128
+ logo: string;
129
+ saml: string;
130
+ samlModalCopy: string;
131
+ scim: string;
132
+ scimModalCopy: {
133
+ url: string;
134
+ token: string;
135
+ };
136
+ wip: boolean;
137
+ }[];
138
+
139
+ export { ADMIN_HOSTNAMES, ALL_TOOLS, 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 };
@@ -1 +1 @@
1
- import{A as C,a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j,i as k,j as l,k as m,l as n,m as o,n as p,o as q,p as r,q as s,r as t,s as u,t as v,u as w,v as x,w as y,x as z,y as A,z as B}from"../chunk-6ES23EVP.mjs";import{a}from"../chunk-MODISIUH.mjs";import{a as b}from"../chunk-3P54C65P.mjs";export{p as ADMIN_HOSTNAMES,x as ALL_TOOLS,o as API_DOMAIN,n as API_HOSTNAMES,l as APP_DOMAIN,m as APP_DOMAIN_WITH_NGROK,k as APP_HOSTNAMES,b as COUNTRIES,A as DEFAULT_LINK_PROPS,q as DEFAULT_REDIRECTS,r as DUB_HEADERS,u as DUB_LOGO,B as DUB_PROJECT_ID,v as DUB_THUMBNAIL,h as FADE_IN_ANIMATION_SETTINGS,s as FAVICON_FOLDER,e as FRAMER_MOTION_LIST_ITEM_VARIANTS,t as GOOGLE_FAVICON_URL,j as HOME_DOMAIN,c as LOCALHOST_GEO_DATA,d as LOCALHOST_IP,i as PAGINATION_LIMIT,C as SAML_PROVIDERS,y as SECOND_LEVEL_DOMAINS,w as SHOW_BACKGROUND_SEGMENTS,z as SPECIAL_APEX_DOMAINS,f as STAGGER_CHILD_VARIANTS,g as SWIPE_REVEAL_ANIMATION_SETTINGS,a as ccTLDs};
1
+ import{A as C,a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j,i as k,j as l,k as m,l as n,m as o,n as p,o as q,p as r,q as s,r as t,s as u,t as v,u as w,v as x,w as y,x as z,y as A,z as B}from"../chunk-6ES23EVP.mjs";import{a}from"../chunk-MODISIUH.mjs";import{a as b}from"../chunk-3P54C65P.mjs";import"../chunk-GK743T7Z.mjs";export{p as ADMIN_HOSTNAMES,x as ALL_TOOLS,o as API_DOMAIN,n as API_HOSTNAMES,l as APP_DOMAIN,m as APP_DOMAIN_WITH_NGROK,k as APP_HOSTNAMES,b as COUNTRIES,A as DEFAULT_LINK_PROPS,q as DEFAULT_REDIRECTS,r as DUB_HEADERS,u as DUB_LOGO,B as DUB_PROJECT_ID,v as DUB_THUMBNAIL,h as FADE_IN_ANIMATION_SETTINGS,s as FAVICON_FOLDER,e as FRAMER_MOTION_LIST_ITEM_VARIANTS,t as GOOGLE_FAVICON_URL,j as HOME_DOMAIN,c as LOCALHOST_GEO_DATA,d as LOCALHOST_IP,i as PAGINATION_LIMIT,C as SAML_PROVIDERS,y as SECOND_LEVEL_DOMAINS,w as SHOW_BACKGROUND_SEGMENTS,z as SPECIAL_APEX_DOMAINS,f as STAGGER_CHILD_VARIANTS,g as SWIPE_REVEAL_ANIMATION_SETTINGS,a as ccTLDs};
@@ -0,0 +1,75 @@
1
+ import { ClassValue } from 'clsx';
2
+ import { Metadata } from 'next';
3
+ import { NextRouter } from 'next/router';
4
+ export { ADMIN_HOSTNAMES, ALL_TOOLS, 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 } from './constants/index.mjs';
5
+ export { default as ccTLDs } from './constants/cctlds.mjs';
6
+ export { default as COUNTRIES } from './constants/countries.mjs';
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 CHANGED
@@ -1 +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-6ES23EVP.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,z as ALL_TOOLS,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,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};
1
+ import{A as Y,a as L,b as v,c as M,d as O,e as _,f as $,g as T,h as p,i as A,j as E,k as F,l as N,m as C,n as q,o as I,p as K,q as P,r as z,s as H,t as Z,u as j,v as W,w as m,x as f,y as B,z as J}from"./chunk-6ES23EVP.mjs";import{a as l}from"./chunk-MODISIUH.mjs";import{a as k}from"./chunk-3P54C65P.mjs";import{a as i,b as u,c as g,d as c}from"./chunk-GK743T7Z.mjs";import y from"@sindresorhus/slugify";import{clsx as d}from"clsx";import x from"ms";import{customAlphabet as D}from"nanoid";import{twMerge as w}from"tailwind-merge";function re(...e){return w(d(e))}function ne({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 i({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(p),themeColor:"#FFF"},n&&{robots:{index:!1,follow:!1}})}var oe=D("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7);function se(e,t){return c(this,null,function*(){let r=yield fetch(e,t);if(!r.ok){let o=yield r.text(),n=new Error(o);throw n.status=r.status,n}return r.json()})}function ae(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 ie(e){return!e||typeof e!="string"?e:e.charAt(0).toUpperCase()+e.slice(1)}var ce=(e,t)=>e.reduce((r,o,n)=>{let s=Math.floor(n/t);return r[s]||(r[s]=[]),r[s].push(o),r},[]);function le({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 ue=(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}):`${x(r)}${t?" ago":""}`},ge=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(":")},pe=e=>new Date(`${e}T00:00:00Z`).toLocaleDateString("en-US",{day:"numeric",month:"long",year:"numeric",timeZone:"UTC"}),me=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,a=o===0?11:o-1;return{firstDay:new Date(s,a,e),lastDay:new Date(n,o,e-1)}}},b=()=>{let e=new Date;return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()},fe=e=>{let t=b();return e>t?t:e},he=e=>{let t=y(e,{separator:""});if(t.length<3)return"";if(l.has(t.slice(-2)))return`${t.slice(0,-2)}.${t.slice(-2)}`;let r=t.replace(/[aeiou]/g,"");return r.length>=3&&l.has(r.slice(-2))?`${r.slice(0,-2)}.${r.slice(-2)}`:`${[t,r].reduce((n,s)=>n.length<s.length?n:s)}.to`},ye=new RegExp(/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/),de=new RegExp(/^[0-9A-Za-z\u0080-\uFFFF\/\-]*$/u),xe=new RegExp(/^[a-zA-Z0-9\-]+$/),De=(e,t)=>e===t?null:e.slice(0,e.length-t.length-1),we=e=>{let t;try{t=new URL(e.replace(/^[a-zA-Z]+:\/\//,"https://")).hostname}catch(o){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?m.has(r[r.length-2])&&l.has(r[r.length-1])||f.has(r.slice(-2).join("."))?r.slice(-3).join("."):r.slice(-2).join("."):t},h=e=>{try{return new URL(e),!0}catch(t){return!1}},be=e=>{if(h(e))return e;try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).toString()}catch(t){return null}},Se=e=>{if(h(e))return new URL(e).hostname.replace(/^www\./,"");try{if(e.includes(".")&&!e.includes(" "))return new URL(`https://${e}`).hostname.replace(/^www\./,"")}catch(t){return null}},Re=(e,t)=>{let r=new URLSearchParams(i(i({},e.query),t)).toString();return`${r?"?":""}${r}`},Ue=({router:e,param:t,value:r})=>{t!=="page"&&delete e.query.page;let o;r.length>0?o=u(i({},e.query),{[t]:r}):(delete e.query[t],o=i({},e.query));let a=o,{slug:n}=a,s=g(a,["slug"]);e.replace({pathname:`/${e.query.slug||"links"}`,query:s})},ke=(e,t)=>!e||e.length<=t?e:`${e.slice(0,t-3)}...`,Le=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(t){return{}}},ve=(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(r){return""}},S=[{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"}],Me=e=>{try{let t=new URL(e);return S.forEach(r=>t.searchParams.delete(r.key)),t.toString()}catch(t){return e}};function Oe(e){return c(this,null,function*(){let r=new TextEncoder().encode(e),o=yield crypto.subtle.digest("MD5",r);return Array.from(new Uint8Array(o)).map(a=>a.toString(16).padStart(2,"0")).join("")})}var R={cron:process.env.DUB_SLACK_HOOK_CRON,links:process.env.DUB_SLACK_HOOK_LINKS},_e=o=>c(void 0,[o],function*({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 n=R[t];if(n)try{return yield fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({blocks:[{type:"section",text:{type:"mrkdwn",text:`${r?"<@U0404G6J3NJ> ":""}${e}`}}]})})}catch(s){console.log(`Failed to log to Dub Slack. Error: ${s}`)}}),U=(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)||!U(e[n],t[n]))return!1;return!0};export{q as ADMIN_HOSTNAMES,W as ALL_TOOLS,C as API_DOMAIN,N as API_HOSTNAMES,E as APP_DOMAIN,F as APP_DOMAIN_WITH_NGROK,A as APP_HOSTNAMES,k as COUNTRIES,B as DEFAULT_LINK_PROPS,I as DEFAULT_REDIRECTS,K as DUB_HEADERS,H as DUB_LOGO,J as DUB_PROJECT_ID,Z as DUB_THUMBNAIL,$ as FADE_IN_ANIMATION_SETTINGS,P as FAVICON_FOLDER,M as FRAMER_MOTION_LIST_ITEM_VARIANTS,z as GOOGLE_FAVICON_URL,p as HOME_DOMAIN,L as LOCALHOST_GEO_DATA,v as LOCALHOST_IP,T as PAGINATION_LIMIT,Y as SAML_PROVIDERS,m as SECOND_LEVEL_DOMAINS,j as SHOW_BACKGROUND_SEGMENTS,f as SPECIAL_APEX_DOMAINS,O as STAGGER_CHILD_VARIANTS,_ as SWIPE_REVEAL_ANIMATION_SETTINGS,ie as capitalize,l as ccTLDs,ce as chunk,re as cn,ne as constructMetadata,ve as constructURLFromUTMParams,U as deepEqual,se as fetcher,pe as formatDate,he as generateDomainFromName,Oe as generateMD5Hash,fe as getAdjustedBillingCycleStart,we as getApexDomain,ge as getDateTimeLocal,Se as getDomainWithoutWWW,me as getFirstAndLastDay,b as getLastDayOfMonth,Le as getParamsFromURL,Re as getQueryString,De as getSubdomain,be as getUrlFromString,Me as getUrlWithoutUTMParams,h as isValidUrl,le as linkConstructor,_e as log,ae as nFormatter,oe as nanoid,S as paramsMetadata,Ue as setQueryString,ue as timeAgo,ke as truncate,ye as validDomainRegex,de as validKeyRegex,xe as validSlugRegex};
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@dub/utils",
3
3
  "description": "Utility functions and constants for Dub.co",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
+ "sideEffects": false,
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
5
8
  "types": "./dist/index.d.ts",
6
- "exports": {
7
- ".": "./dist"
8
- },
9
+ "files": [
10
+ "dist/**"
11
+ ],
9
12
  "scripts": {
10
13
  "build": "tsup",
11
14
  "lint": "eslint src/",
@@ -13,17 +16,17 @@
13
16
  "check-types": "tsc --noEmit"
14
17
  },
15
18
  "peerDependencies": {
16
- "react": "^18.2.0",
17
- "next": "13.5.4"
19
+ "next": "13.5.4",
20
+ "react": "^18.2.0"
18
21
  },
19
22
  "devDependencies": {
20
23
  "@types/ms": "^0.7.31",
21
24
  "@types/node": "18.11.9",
22
25
  "@types/react": "^18.2.5",
23
- "react": "^18.2.0",
24
26
  "next": "13.5.4",
27
+ "react": "^18.2.0",
25
28
  "tsconfig": "workspace:*",
26
- "tsup": "^6.1.3",
29
+ "tsup": "^7.2.0",
27
30
  "typescript": "^5.1.6"
28
31
  },
29
32
  "dependencies": {
@@ -1,24 +0,0 @@
1
-
2
- > @dub/utils@0.0.2 build /Users/steventey/Desktop/dub/packages/utils
3
- > tsup
4
-
5
- CLI Building entry: src/index.ts, src/constants/cctlds.ts, src/constants/countries.ts, src/constants/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.1.3
8
- CLI Using tsup config: /Users/steventey/Desktop/dub/packages/utils/tsup.config.ts
9
- CLI Target: node14
10
- ESM Build start
11
- ESM ⚡️ Build success in 6ms
12
- ESM dist/constants/countries.mjs 59.00 B
13
- ESM dist/constants/cctlds.mjs 59.00 B
14
- ESM dist/index.mjs 7.47 KB
15
- ESM dist/chunk-MODISIUH.mjs 1.37 KB
16
- ESM dist/constants/index.mjs 951.00 B
17
- ESM dist/chunk-3P54C65P.mjs 3.96 KB
18
- ESM dist/chunk-6ES23EVP.mjs 3.10 KB
19
- DTS Build start
20
- DTS ⚡️ Build success in 849ms
21
- DTS dist/index.d.ts 4.02 KB
22
- DTS dist/constants/index.d.ts 3.58 KB
23
- DTS dist/constants/cctlds.d.ts 66.00 B
24
- DTS dist/constants/countries.d.ts 91.00 B
@@ -1,276 +0,0 @@
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;