@xpoudy/free-tools 0.0.0-stage → 1.1.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/LICENSE +21 -0
- package/README.md +30 -2
- package/assets/calculators.js +175 -0
- package/assets/common.js +176 -0
- package/assets/copy.js +140 -0
- package/assets/dns.js +280 -0
- package/assets/lists.js +187 -0
- package/assets/mail.js +302 -0
- package/assets/message.js +47 -0
- package/assets/mirror-index.css +6 -0
- package/assets/reports.js +179 -0
- package/assets/toolbox-auth.js +229 -0
- package/assets/toolbox-campaign.js +154 -0
- package/assets/toolbox-compose.js +212 -0
- package/assets/toolbox-data.js +53 -0
- package/assets/toolbox-disposable-license.txt +24 -0
- package/assets/toolbox-disposable.js +1 -0
- package/assets/toolbox-domain.js +199 -0
- package/assets/toolbox-files.js +250 -0
- package/assets/toolbox-leads.js +133 -0
- package/assets/toolbox-measure.js +153 -0
- package/assets/toolbox-pdf-license.txt +177 -0
- package/assets/toolbox-pdf-worker.js +21 -0
- package/assets/toolbox-pdf.js +21 -0
- package/assets/toolbox-ui.js +285 -0
- package/assets/toolbox-vendor-data.js +6 -0
- package/assets/toolbox-vendor-licenses.txt +75 -0
- package/assets/toolbox-vendor-qr.js +8 -0
- package/assets/toolbox.css +14 -0
- package/assets/tools.css +112 -0
- package/assets/ui.js +257 -0
- package/catalog.json +11 -0
- package/favicon-32x32.png +0 -0
- package/index.html +1 -0
- package/index.js +3 -0
- package/package.json +19 -3
- package/tools/cold-email-volume-calculator/index.html +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xpoudy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @xpoudy/free-tools (v1.1.0)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Standalone MIT-licensed JavaScript, CSS, and HTML source bundle for Xpoudy email deliverability, DNS diagnostics, outreach calculators, and CSV list tools.
|
|
4
|
+
|
|
5
|
+
Try every utility directly in your browser at **[xpoudy.com/tools/](https://xpoudy.com/tools/)**.
|
|
6
|
+
|
|
7
|
+
## Installation & Node.js Usage
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @xpoudy/free-tools
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
const { catalog, webDir, getTool } = require('@xpoudy/free-tools');
|
|
15
|
+
console.log('Bundled tools:', catalog.length, 'Web root:', webDir);
|
|
16
|
+
console.log(getTool('cold-email-volume-calculator'));
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Spotlight: Cold Email Volume Calculator
|
|
20
|
+
|
|
21
|
+
See how many messages your prospect list and follow-ups could create. Compare the average daily workload with the mailbox capacity you enter. **[Open Cold Email Volume Calculator on Xpoudy](https://xpoudy.com/tools/cold-email-volume-calculator/)**
|
|
22
|
+
|
|
23
|
+
- **ES Module & Action:** `assets/calculators.js` (`volume`)
|
|
24
|
+
- **Form Controls:** Unique prospects · Steps including the first email · Stop rate after each step (%) · Sending days in the period · Connected mailboxes · Your daily limit per mailbox
|
|
25
|
+
- **Sample Calculation:** 1,000 prospects and three steps, with 20% stopping after each step, produce an estimated 2,440 messages.
|
|
26
|
+
|
|
27
|
+
## Complete Module Directory (1 / 100)
|
|
28
|
+
|
|
29
|
+
- [Cold Email Volume Calculator](https://xpoudy.com/tools/cold-email-volume-calculator/) — See how many messages your prospect list and follow-ups could create.
|
|
30
|
+
|
|
31
|
+
Licensed under MIT. Full `LICENSE`, `assets/`, and `tools/` files are included in the npm tarball.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {InputError,readNumber as n,showNumber as number,showInteger as whole,
|
|
2
|
+
showPercent as percent,showMoney as money,ratio,csvDownload,modelResult as result} from './common.js';
|
|
3
|
+
|
|
4
|
+
const int={integer:true};
|
|
5
|
+
const maxCount=10_000_000;
|
|
6
|
+
const maxCash=1_000_000_000;
|
|
7
|
+
function probability(input,key) { return n(input,key,0,100)/100; }
|
|
8
|
+
function accounts(input,key,min=0) { return n(input,key,min,maxCount,int); }
|
|
9
|
+
|
|
10
|
+
export function volume(input) {
|
|
11
|
+
const prospects=accounts(input,'prospects',1);
|
|
12
|
+
const steps=n(input,'sequence_steps',1,20,int);
|
|
13
|
+
const stop=probability(input,'stop_rate');
|
|
14
|
+
const days=n(input,'sending_days',1,366,int);
|
|
15
|
+
const mailboxes=accounts(input,'mailboxes',1);
|
|
16
|
+
const capacity=n(input,'daily_mailbox_limit',1,100_000,int);
|
|
17
|
+
const forecast=Array.from({length:steps},(_,i)=>prospects*((1-stop)**i));
|
|
18
|
+
const total=forecast.reduce((a,b)=>a+b,0);
|
|
19
|
+
const average=total/days;
|
|
20
|
+
const dailyCapacity=mailboxes*capacity;
|
|
21
|
+
return result([
|
|
22
|
+
['Estimated messages',whole(total)],['Estimated follow-ups',whole(total-prospects)],
|
|
23
|
+
['Average per send day',number(average)],['Average per mailbox per day',number(average/mailboxes)],
|
|
24
|
+
['Mailboxes for average load',whole(Math.ceil(average/capacity))],
|
|
25
|
+
['Average capacity used',percent(average/dailyCapacity)]
|
|
26
|
+
],{table:{columns:['Sequence step','Estimated sends'],rows:forecast.map((count,i)=>[i===0?'First email':'Follow-up '+i,number(count)])},
|
|
27
|
+
notes:['The model removes the same share of remaining prospects after each step. It spreads the estimated total across the sending days you entered.',
|
|
28
|
+
average>dailyCapacity ? 'The estimated average exceeds your stated capacity. Reduce the workload or allow more sending days.' :
|
|
29
|
+
'The estimated average fits your stated capacity. Follow-ups can still create busier days. Your entry is a planning limit.']});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function cost(input) {
|
|
33
|
+
const leads=accounts(input,'monthly_prospects');
|
|
34
|
+
const count=accounts(input,'mailboxes');
|
|
35
|
+
const domainCount=accounts(input,'domains');
|
|
36
|
+
const amount=key=>n(input,key,0,maxCash);
|
|
37
|
+
const m=input.currency;
|
|
38
|
+
const costs=[
|
|
39
|
+
['Domains, monthly equivalent',domainCount*amount('annual_cost_per_domain')/12],
|
|
40
|
+
['Mailbox hosting',count*amount('monthly_cost_per_mailbox')],
|
|
41
|
+
['Sending and warmup software',amount('software_per_month')],
|
|
42
|
+
['Lead data and verification',amount('data_per_month')+amount('verification_per_month')],
|
|
43
|
+
['Labor',amount('hours_per_month')*amount('hourly_rate')],
|
|
44
|
+
];
|
|
45
|
+
const monthly=costs.reduce((total,row)=>total+row[1],0), setup=amount('one_time_setup');
|
|
46
|
+
return result([
|
|
47
|
+
['Monthly cost',money(monthly,m)],['First-year cost',money(monthly*12+setup,m)],
|
|
48
|
+
['One-time setup',money(setup,m)],['Monthly cost per prospect',money(ratio(monthly,leads),m)]
|
|
49
|
+
],{table:{columns:['Cost item','Monthly cost'],rows:costs.map(([k,v])=>[k,money(v,m)])},
|
|
50
|
+
notes:['Domain renewals are spread across 12 months. First-year cost adds the one-time setup to 12 modeled months. Enter amounts in one currency.']});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function roi(input) {
|
|
54
|
+
const spend=n(input,'campaign_spend',0,maxCash);
|
|
55
|
+
const margin=n(input,'gross_profit_per_sale',0.01,maxCash);
|
|
56
|
+
const close=probability(input,'qualified_close_rate');
|
|
57
|
+
const meetings=accounts(input,'qualified_meetings');
|
|
58
|
+
const won=meetings*close;
|
|
59
|
+
const profit=won*margin-spend;
|
|
60
|
+
const breakEvenSales=Math.ceil(spend/margin);
|
|
61
|
+
const breakEvenMeetings=close>0 ? Math.ceil(spend/(margin*close)) : (spend===0 ? 0:null);
|
|
62
|
+
return result([
|
|
63
|
+
['Modeled won deals',number(won)],['Estimated profit after campaign cost',money(profit,input.currency)],
|
|
64
|
+
['Break-even sales',whole(breakEvenSales)],['Break-even qualified meetings',whole(breakEvenMeetings)],
|
|
65
|
+
['Modeled return on spend',percent(ratio(profit,spend))]
|
|
66
|
+
],{notes:[close===0 ? 'Break-even meetings are undefined at a 0% close rate when spend is positive.' :
|
|
67
|
+
'Break-even meetings use expected profit per qualified meeting. Real outcomes are discrete and can vary.',
|
|
68
|
+
'Use gross profit per won deal after direct fulfillment costs. Zero campaign spend has no defined return-on-spend ratio.']});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function replyRate(input) {
|
|
72
|
+
const contacts=accounts(input,'contacted_prospects');
|
|
73
|
+
const human=accounts(input,'human_replies');
|
|
74
|
+
const positive=accounts(input,'positive_replies');
|
|
75
|
+
const qualified=accounts(input,'qualified_replies');
|
|
76
|
+
const held=accounts(input,'meetings_held');
|
|
77
|
+
if (human>contacts || positive>human || qualified>positive || held>qualified) {
|
|
78
|
+
throw new InputError('Enter counts in this order, from largest to smallest: contacted, human replies, positive replies, qualified replies, and held meetings.');
|
|
79
|
+
}
|
|
80
|
+
const rows=[
|
|
81
|
+
['Human reply rate',human,contacts],['Positive reply rate',positive,contacts],['Qualified reply rate',qualified,contacts],
|
|
82
|
+
['Held meeting rate',held,contacts],['Positive share of human replies',positive,human],
|
|
83
|
+
];
|
|
84
|
+
return result(rows.slice(0,4).map(([label,count,denom])=>[label,percent(ratio(count,denom))]),{
|
|
85
|
+
table:{columns:['Measure','Unique people','Denominator','Rate'],
|
|
86
|
+
rows:rows.map(([label,count,denom])=>[label,whole(count),whole(denom),percent(ratio(count,denom))])},
|
|
87
|
+
notes:['Count each person once per measure. Exclude automatic replies from human replies. This model treats held meetings as a subset of qualified replies.']});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function normalCDF(x) {
|
|
91
|
+
const t=1/(1+0.2316419*Math.abs(x));
|
|
92
|
+
const density=Math.exp(-x*x/2)/Math.sqrt(2*Math.PI);
|
|
93
|
+
const tail=density*t*(0.319381530+t*(-0.356563782+t*(1.781477937+t*(-1.821255978+t*1.330274429))));
|
|
94
|
+
return x>=0 ? 1-tail : tail;
|
|
95
|
+
}
|
|
96
|
+
function zFor(p) {
|
|
97
|
+
let left=-10,right=10;
|
|
98
|
+
for(let i=0;i<70;i++){
|
|
99
|
+
const mid=(left+right)/2;
|
|
100
|
+
if(normalCDF(mid)<p) left=mid;
|
|
101
|
+
else right=mid;
|
|
102
|
+
}
|
|
103
|
+
return (left+right)/2;
|
|
104
|
+
}
|
|
105
|
+
function wilson(success,count,z) {
|
|
106
|
+
const p=success/count, scale=1+z*z/count;
|
|
107
|
+
const center=(p+z*z/(2*count))/scale;
|
|
108
|
+
const radius=z*Math.sqrt((p*(1-p)+z*z/(4*count))/count)/scale;
|
|
109
|
+
return [Math.max(0,center-radius),Math.min(1,center+radius)];
|
|
110
|
+
}
|
|
111
|
+
function abPlan(input) {
|
|
112
|
+
const p1=n(input,'baseline_rate',0.001,99.999)/100;
|
|
113
|
+
const uplift=n(input,'lift_percentage_points',0.001,99.999)/100;
|
|
114
|
+
const p2=p1+uplift;
|
|
115
|
+
if (p2>=1) throw new InputError('Baseline plus lift must stay below 100%.');
|
|
116
|
+
const confidence=n(input,'confidence',80,99.9)/100;
|
|
117
|
+
const power=n(input,'power',50,99.9)/100;
|
|
118
|
+
const alpha=zFor((1+confidence)/2), beta=zFor(power), pooled=(p1+p2)/2;
|
|
119
|
+
const top=alpha*Math.sqrt(2*pooled*(1-pooled))+beta*Math.sqrt(p1*(1-p1)+p2*(1-p2));
|
|
120
|
+
const size=Math.ceil((top/uplift)**2);
|
|
121
|
+
return result([['Recipients per group',whole(size)],['Total recipients',whole(size*2)],
|
|
122
|
+
['Baseline rate',percent(p1)],['Rate to detect',percent(p2)]],{
|
|
123
|
+
notes:['This is an approximate, two-sided test with equal-sized groups and independent observations. Plan using unique prospects who can receive the measured outcome.',
|
|
124
|
+
'A lift of 2 percentage points means 5% becomes 7%. When assigning companies as groups, this person-level estimate may be too small.']});
|
|
125
|
+
}
|
|
126
|
+
function abAnalyze(input) {
|
|
127
|
+
const a=accounts(input,'a_recipients',1), b=accounts(input,'b_recipients',1);
|
|
128
|
+
const successA=accounts(input,'a_outcomes'), successB=accounts(input,'b_outcomes');
|
|
129
|
+
if (successA>a || successB>b) throw new InputError('Outcomes cannot exceed recipients in either group.');
|
|
130
|
+
const conf=n(input,'confidence',80,99.9)/100, z=zFor((1+conf)/2), p=successA/a, q=successB/b;
|
|
131
|
+
const delta=q-p;
|
|
132
|
+
const [al,au]=wilson(successA,a,z), [bl,bu]=wilson(successB,b,z);
|
|
133
|
+
const low=delta-Math.hypot(q-bl,au-p), high=delta+Math.hypot(bu-q,p-al);
|
|
134
|
+
const pooled=(successA+successB)/(a+b);
|
|
135
|
+
const adequate=[a*pooled,a*(1-pooled),b*pooled,b*(1-pooled)].every(x=>x>=5);
|
|
136
|
+
const stdev=Math.sqrt(pooled*(1-pooled)*(1/a+1/b));
|
|
137
|
+
const pValue=adequate ? 2*(1-normalCDF(Math.abs(delta/stdev))) : null;
|
|
138
|
+
return result([
|
|
139
|
+
['Version A rate',percent(p)],['Version B rate',percent(q)],['B minus A',number(delta*100)+' pp'],
|
|
140
|
+
[percent(conf)+' interval for B − A',number(low*100)+' to '+number(high*100)+' pp'],
|
|
141
|
+
['Two-sided p-value',pValue===null?'Too few outcomes':(pValue<0.0001?'<0.0001':pValue.toFixed(4))]
|
|
142
|
+
],{notes:[adequate ? 'The p-value uses a two-proportion normal approximation. The difference interval uses Wilson score intervals.' :
|
|
143
|
+
'The expected cell counts are too small for a normal-approximation p-value. Use the interval and keep the raw counts.',
|
|
144
|
+
'Use the same outcome definition and response window. Group assignments, repeated looks, or testing several variants can change what these results mean.']});
|
|
145
|
+
}
|
|
146
|
+
export function abTest(input) {
|
|
147
|
+
if (input.mode==='plan') return abPlan(input);
|
|
148
|
+
if (input.mode==='results') return abAnalyze(input);
|
|
149
|
+
throw new InputError('Choose whether to plan a test or analyze results.');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function readiness(input) {
|
|
153
|
+
const checks=[
|
|
154
|
+
['authentication','SPF, DKIM and DMARC checked on a received message'],
|
|
155
|
+
['identity','From name and Reply-To identify the sender clearly'],
|
|
156
|
+
['reply','A test reply reached the right person'],
|
|
157
|
+
['opt_out','An opt-out stopped the next scheduled step'],
|
|
158
|
+
['placement','A controlled send was reviewed in relevant providers'],
|
|
159
|
+
['provider','The account owner reviewed provider rules and limits'],
|
|
160
|
+
['list','The first group was screened for fit and exclusions'],
|
|
161
|
+
['owner','Someone can pause sending and investigate failures'],
|
|
162
|
+
];
|
|
163
|
+
const rows=checks.map(([key,label])=>{
|
|
164
|
+
const state=String(input[key]??'pending');
|
|
165
|
+
if (!['pass','fail','pending'].includes(state)) throw new InputError('Choose a state for each readiness check.');
|
|
166
|
+
return [label,{pass:'Checked',fail:'Needs fixing',pending:'Pending'}[state]];
|
|
167
|
+
});
|
|
168
|
+
const blockers=rows.filter(row=>row[1]==='Needs fixing').length;
|
|
169
|
+
const pending=rows.filter(row=>row[1]==='Pending').length;
|
|
170
|
+
return result([['Checks complete',whole(rows.length-blockers-pending)+' of '+rows.length],
|
|
171
|
+
['Needs fixing',whole(blockers)],['Awaiting evidence',whole(pending)]],{
|
|
172
|
+
table:{columns:['Check','Status'],rows},
|
|
173
|
+
downloads:[csvDownload('mailbox-readiness.csv',['Check','Status'],rows)],
|
|
174
|
+
notes:['This checklist records the evidence you entered. Completing it does not predict inbox placement or substitute for provider requirements.']});
|
|
175
|
+
}
|
package/assets/common.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
export class InputError extends Error {}
|
|
2
|
+
|
|
3
|
+
export const MAX_FILE_SIZE = 4 * 1024 * 1024;
|
|
4
|
+
export const MAX_ROWS = 25000;
|
|
5
|
+
const MAX_COLUMNS = 200;
|
|
6
|
+
const numberDisplay = new Intl.NumberFormat('en-US', {maximumFractionDigits:2});
|
|
7
|
+
const integerDisplay = new Intl.NumberFormat('en-US', {maximumFractionDigits:0});
|
|
8
|
+
const currencies = new Set(['USD','EUR','GBP','MYR','INR','CAD','AUD']);
|
|
9
|
+
|
|
10
|
+
export const showNumber = value => Number.isFinite(value) ? numberDisplay.format(value) : '—';
|
|
11
|
+
export const showInteger = value => Number.isFinite(value) ? integerDisplay.format(value) : '—';
|
|
12
|
+
export const showPercent = value => Number.isFinite(value) ? showNumber(value*100)+'%' : '—';
|
|
13
|
+
export const showMoney = (value,currency='USD') => Number.isFinite(value)
|
|
14
|
+
? new Intl.NumberFormat('en-US',{style:'currency',currency:currencies.has(currency) ? currency : 'USD'}).format(value) : '—';
|
|
15
|
+
export const ratio = (numerator,denominator) => denominator ? numerator/denominator : null;
|
|
16
|
+
|
|
17
|
+
export function readNumber(values,key,min,max,options={}) {
|
|
18
|
+
const {integer=false,optional=false} = options;
|
|
19
|
+
const raw = values[key];
|
|
20
|
+
if ((raw===undefined || raw===null || String(raw).trim()==='') && optional) return null;
|
|
21
|
+
const label = key.replaceAll('_',' ');
|
|
22
|
+
if (raw===undefined || raw===null || String(raw).trim()==='') throw new InputError('Enter '+label+'.');
|
|
23
|
+
if (!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(String(raw).trim())) {
|
|
24
|
+
throw new InputError('Enter a number for '+label+'.');
|
|
25
|
+
}
|
|
26
|
+
const n = Number(raw);
|
|
27
|
+
if (!Number.isFinite(n) || n < min || n > max || (integer && !Number.isInteger(n))) {
|
|
28
|
+
throw new InputError('Enter '+(integer?'a whole number':'a number')+' from '+min+' to '+max+' for '+label+'.');
|
|
29
|
+
}
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function requiredText(value,label,limit=MAX_FILE_SIZE) {
|
|
34
|
+
if (typeof value!=='string' || !value.trim()) throw new InputError('Enter '+label+'.');
|
|
35
|
+
if (value.length>limit) throw new InputError(label+' is too large. Reduce the size and try again.');
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function delimiterFor(text) {
|
|
40
|
+
text=text.replace(/^(?:[ \t]*\r?\n)+/,"");
|
|
41
|
+
const separators = [',','\t',';'];
|
|
42
|
+
const counts = [0,0,0];
|
|
43
|
+
let quote = false;
|
|
44
|
+
for (let i=0; i<text.length; i++) {
|
|
45
|
+
const c=text[i];
|
|
46
|
+
if (c==='"') {
|
|
47
|
+
if (quote && text[i+1]==='"') i++;
|
|
48
|
+
else quote=!quote;
|
|
49
|
+
} else if (!quote) {
|
|
50
|
+
if (c==='\n'||c==='\r') break;
|
|
51
|
+
const position=separators.indexOf(c);
|
|
52
|
+
if (position>=0) counts[position]++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return separators[counts.indexOf(Math.max(...counts))];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function parseCSV(input,{delimiter,loose=false}={}) {
|
|
59
|
+
let text=requiredText(input,'a CSV or TSV file').replace(/^\uFEFF/,'');
|
|
60
|
+
if (text.includes('\0')) throw new InputError('This file contains binary data. Export it as UTF-8 CSV or TSV.');
|
|
61
|
+
const sep=delimiter || delimiterFor(text);
|
|
62
|
+
if (![',','\t',';'].includes(sep)) throw new InputError('Choose comma, tab, or semicolon as the delimiter.');
|
|
63
|
+
const records=[];
|
|
64
|
+
let values=[], value='', inQuotes=false, closed=false;
|
|
65
|
+
let line=1, startLine=1;
|
|
66
|
+
|
|
67
|
+
function pushValue() {
|
|
68
|
+
values.push(value);
|
|
69
|
+
if (values.length>MAX_COLUMNS) throw new InputError('Keep files to '+MAX_COLUMNS+' columns or fewer.');
|
|
70
|
+
value='';
|
|
71
|
+
closed=false;
|
|
72
|
+
}
|
|
73
|
+
function pushRecord() {
|
|
74
|
+
pushValue();
|
|
75
|
+
if (values.some(cell=>cell.trim()!=='')) records.push({line:startLine,cells:values});
|
|
76
|
+
if (records.length>MAX_ROWS+1) throw new InputError('Keep files to '+showInteger(MAX_ROWS)+' data rows or fewer.');
|
|
77
|
+
values=[];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (let i=0; i<text.length; i++) {
|
|
81
|
+
const c=text[i];
|
|
82
|
+
if (inQuotes) {
|
|
83
|
+
if (c==='"') {
|
|
84
|
+
if (text[i+1]==='"') { value+='"'; i++; }
|
|
85
|
+
else {inQuotes=false; closed=true;}
|
|
86
|
+
} else if (c==='\r'||c==='\n') {
|
|
87
|
+
if (c==='\r' && text[i+1]==='\n') i++;
|
|
88
|
+
value+='\n';
|
|
89
|
+
line++;
|
|
90
|
+
} else value+=c;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (c===sep) pushValue();
|
|
94
|
+
else if (c==='\r'||c==='\n') {
|
|
95
|
+
if (c==='\r'&&text[i+1]==='\n') i++;
|
|
96
|
+
pushRecord();
|
|
97
|
+
startLine=++line;
|
|
98
|
+
} else if (c==='"' && !value && !closed) inQuotes=true;
|
|
99
|
+
else if (closed || c==='"') throw new InputError('Unexpected quote or text after a closing quote on line '+line+'.');
|
|
100
|
+
else value+=c;
|
|
101
|
+
}
|
|
102
|
+
if (inQuotes) throw new InputError('A quoted cell starting on or after line '+startLine+' is missing its closing quote.');
|
|
103
|
+
if (values.length || value || closed) pushRecord();
|
|
104
|
+
if (!records.length) throw new InputError('The file is empty. Include a header row.');
|
|
105
|
+
|
|
106
|
+
const columns=records.shift().cells.map(cell=>cell.trim());
|
|
107
|
+
if (columns.some(name=>!name)) throw new InputError('Give every column a name in the header row.');
|
|
108
|
+
if (new Set(columns.map(name=>name.toLowerCase())).size!==columns.length) {
|
|
109
|
+
throw new InputError('The header row contains duplicate column names. Rename them first.');
|
|
110
|
+
}
|
|
111
|
+
const widthIssues=records.filter(row=>row.cells.length!==columns.length);
|
|
112
|
+
if (widthIssues.length && !loose) {
|
|
113
|
+
const row=widthIssues[0];
|
|
114
|
+
throw new InputError('Line '+row.line+' has '+row.cells.length+' cells. The header has '+columns.length+'. Use preflight to see row errors.');
|
|
115
|
+
}
|
|
116
|
+
return {columns,records,widthIssues,delimiter:sep};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function columnIndex(columns,name,optional=false) {
|
|
120
|
+
const key=String(name??'').trim().toLowerCase();
|
|
121
|
+
if (!key && optional) return -1;
|
|
122
|
+
if (!key) throw new InputError('Enter a column name.');
|
|
123
|
+
const i=columns.findIndex(c=>c.toLowerCase()===key);
|
|
124
|
+
if (i<0) throw new InputError('Column "'+String(name).slice(0,100)+'" was not found. Available columns include '+columns.slice(0,8).join(', ')+'.');
|
|
125
|
+
return i;
|
|
126
|
+
}
|
|
127
|
+
export function keyFor(value,matchCase=false) {
|
|
128
|
+
const key=String(value??'').trim();
|
|
129
|
+
return matchCase ? key : key.toLowerCase();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function csvCell(input) {
|
|
133
|
+
let value=String(input??'');
|
|
134
|
+
const inspected=value.replace(/^[\s\u00a0\uFEFF]+/u,'');
|
|
135
|
+
const numeric=/^-\d+(?:\.\d+)?$/.test(inspected);
|
|
136
|
+
if (!numeric && /^[=+@\-\t\r\n]/.test(inspected||value)) value="'"+value;
|
|
137
|
+
return /[",\r\n]/.test(value) ? '"'+value.replaceAll('"','""')+'"' : value;
|
|
138
|
+
}
|
|
139
|
+
export function toCSV(columns,rows) {
|
|
140
|
+
return [columns,...rows].map(row=>row.map(csvCell).join(',')).join('\r\n')+'\r\n';
|
|
141
|
+
}
|
|
142
|
+
export const csvDownload=(name,columns,rows)=>({name,type:'text/csv;charset=utf-8',text:toCSV(columns,rows)});
|
|
143
|
+
|
|
144
|
+
export function asciiDomain(input) {
|
|
145
|
+
const domain=String(input??'').trim();
|
|
146
|
+
if (!domain || /[\s/@:#?\\%<>\[\]+]/u.test(domain) || domain.endsWith('.') || !domain.includes('.')) return null;
|
|
147
|
+
let ascii;
|
|
148
|
+
try { ascii=new URL('https://'+domain).hostname.toLowerCase(); } catch { return null; }
|
|
149
|
+
if (/^\d+(?:\.\d+)+$/.test(ascii) || ascii.length>253) return null;
|
|
150
|
+
const labels=ascii.split('.');
|
|
151
|
+
if (!labels.every(label=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label))) return null;
|
|
152
|
+
return ascii;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function emailFormat(input) {
|
|
156
|
+
const raw=String(input??'').trim();
|
|
157
|
+
const lastAt=raw.lastIndexOf('@');
|
|
158
|
+
if (!raw || lastAt<1 || lastAt===raw.length-1) return {status:'Invalid',note:'Include an address name and domain separated by @.'};
|
|
159
|
+
if (raw.length>254 || lastAt>64) return {status:'Invalid',note:'The address or address name is longer than the supported limit.'};
|
|
160
|
+
const local=raw.slice(0,lastAt), host=raw.slice(lastAt+1);
|
|
161
|
+
if (local.startsWith('"') || /[^\x00-\x7f]/u.test(local) || host.startsWith('[')) {
|
|
162
|
+
return {status:'Review',note:'Quoted, internationalized address names and domain literals need a mail-system-specific check.'};
|
|
163
|
+
}
|
|
164
|
+
if (!/^[a-z0-9!#$%&'*+/=?^_\x60{|}~\-]+(?:\.[a-z0-9!#$%&'*+/=?^_\x60{|}~\-]+)*$/i.test(local)) {
|
|
165
|
+
return {status:'Invalid',note:'Check the address name for spaces, invalid characters, or consecutive dots.'};
|
|
166
|
+
}
|
|
167
|
+
if (!host.includes('.') && /^[a-z0-9-]+$/i.test(host)) return {status:'Review',note:'The domain has no public suffix.'};
|
|
168
|
+
const domain=asciiDomain(host);
|
|
169
|
+
if (!domain || local.length+domain.length+1>254) return {status:'Invalid',note:'Check the domain format or length.'};
|
|
170
|
+
return {status:'Format looks valid',note:'Syntax only.',domain,key:local.toLowerCase()+'@'+domain};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function textList(value) {
|
|
174
|
+
return String(value??'').split(/[\r\n,;]+/).map(item=>item.trim()).filter(Boolean);
|
|
175
|
+
}
|
|
176
|
+
export function modelResult(metrics=[],rest={}) { return {metrics,...rest}; }
|
package/assets/copy.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import {InputError,parseCSV,requiredText,readNumber,showInteger as whole,
|
|
2
|
+
csvDownload,modelResult as result} from './common.js';
|
|
3
|
+
|
|
4
|
+
export function mergePreview(input) {
|
|
5
|
+
const template=requiredText(input.template,'an email template',12_000);
|
|
6
|
+
const file=parseCSV(input.csv);
|
|
7
|
+
const limit=readNumber(input,'preview_rows',1,25,{integer:true});
|
|
8
|
+
if(!file.records.length) throw new InputError('The CSV has a header but no sample contacts.');
|
|
9
|
+
const pattern=/\{\{([^{}]*)\}\}/g;
|
|
10
|
+
const literals=template.replace(pattern,'');
|
|
11
|
+
if(/\{\{|\}\}/.test(literals)) throw new InputError('A merge field has mismatched braces. Use {{column}} or {{column|fallback}}.');
|
|
12
|
+
const tokens=[...template.matchAll(pattern)].map(m=>{
|
|
13
|
+
const [key,...rest]=m[1].split('|');
|
|
14
|
+
const name=key.trim();
|
|
15
|
+
if(!name) throw new InputError('A merge field is missing its column name.');
|
|
16
|
+
const fallback=rest.join('|').trim();
|
|
17
|
+
return {name,fallback,index:file.columns.findIndex(c=>c.toLowerCase()===name.toLowerCase())};
|
|
18
|
+
});
|
|
19
|
+
if(tokens.length>200) throw new InputError('Use 200 merge fields or fewer per template.');
|
|
20
|
+
const missingHeaders=[...new Set(tokens.filter(t=>t.index<0).map(t=>t.name))];
|
|
21
|
+
const issueRows=[], preview=[];
|
|
22
|
+
let fallbackCount=0;
|
|
23
|
+
for(const [p,row] of file.records.entries()){
|
|
24
|
+
const misses=new Set();
|
|
25
|
+
let used=0;
|
|
26
|
+
const renderValue=token=>{
|
|
27
|
+
const value=row.cells[token.index]?.trim();
|
|
28
|
+
if(value) return value;
|
|
29
|
+
if(token.fallback){used++;return token.fallback;}
|
|
30
|
+
misses.add(token.name);
|
|
31
|
+
return '[missing '+token.name+']';
|
|
32
|
+
};
|
|
33
|
+
if(p<limit){
|
|
34
|
+
let i=0;
|
|
35
|
+
let remaining=24_000-literals.length;
|
|
36
|
+
let clipped=false;
|
|
37
|
+
const message=template.replace(pattern,()=>{
|
|
38
|
+
const chunk=renderValue(tokens[i++]);
|
|
39
|
+
const visible=chunk.slice(0,remaining);
|
|
40
|
+
remaining-=visible.length;
|
|
41
|
+
if(visible.length<chunk.length) clipped=true;
|
|
42
|
+
return visible;
|
|
43
|
+
});
|
|
44
|
+
preview.push(['CSV line '+row.line,message+(clipped?'\n[Preview limited to 24,000 characters]':'')]);
|
|
45
|
+
}else for(const token of tokens) renderValue(token);
|
|
46
|
+
if(misses.size) issueRows.push([row.line,[...misses].join(', ')]);
|
|
47
|
+
fallbackCount+=used;
|
|
48
|
+
}
|
|
49
|
+
const columns=['Source line','Unfilled fields'];
|
|
50
|
+
return result([['Rows checked',whole(file.records.length)],['Rows with missing values',whole(issueRows.length)],
|
|
51
|
+
['Fallbacks used',whole(fallbackCount)],['Unknown column names',whole(missingHeaders.length)]],{
|
|
52
|
+
blocks:preview, table:{columns,rows:issueRows.slice(0,40),total:issueRows.length},
|
|
53
|
+
downloads:issueRows.length?[csvDownload('merge-field-issues.csv',columns,issueRows)]:[],
|
|
54
|
+
notes:[missingHeaders.length?'Columns not found: '+missingHeaders.join(', ')+'.':'All named fields match a column.',
|
|
55
|
+
tokens.length?'Fields are matched case-insensitively. Compare the final preview with your sending platform.':'This template has no merge fields.']});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function copyReview(input) {
|
|
59
|
+
const body=requiredText(input.message,'your draft email',25_000).trim();
|
|
60
|
+
const subject=String(input.subject??'').trim();
|
|
61
|
+
const word=/(?:\p{L}|\p{N})+(?:[’'-](?:\p{L}|\p{N})+)*/gu;
|
|
62
|
+
const words=body.match(word)||[];
|
|
63
|
+
const sentences=body.split(/(?<=[.!?])\s+|\n{2,}/).map(part=>part.trim()).filter(Boolean);
|
|
64
|
+
const long=sentences.map(s=>[s,(s.match(word)||[]).length]).filter(([,size])=>size>25);
|
|
65
|
+
const links=body.match(/(?:https?:\/\/|www\.)[^\s<>()]+/gi)||[];
|
|
66
|
+
const placeholders=[...new Set((body+' '+subject).match(/\{\{[^{}]+\}\}|\[(?:your|insert|first|name|company|role)[^\]]*\]/gi)||[])];
|
|
67
|
+
const asks=sentences.filter(s=>/\?|(?:^|\n)\s*(?:let me know|please|book |schedule |reply |could you|would you|can you)\b/i.test(s));
|
|
68
|
+
const paragraphs=body.split(/\n\s*\n/).filter(Boolean);
|
|
69
|
+
const checks=[];
|
|
70
|
+
if(!subject) checks.push(['Subject','Add a short, descriptive subject.']);
|
|
71
|
+
else if(subject.length>65) checks.push(['Subject',subject.length+' characters. Check how it reads on mobile.']);
|
|
72
|
+
if(/^(?:re|fwd):/i.test(subject)) checks.push(['Subject','Use Re or Fwd only for a real reply or forward.']);
|
|
73
|
+
if(words.length>120) checks.push(['Length','Consider moving this week’s less important details to a later message.']);
|
|
74
|
+
if(asks.length>1) checks.push(['Request','Several sentences look like requests. Check whether one next step would be clearer.']);
|
|
75
|
+
if(placeholders.length) checks.push(['Merge fields','Preview or replace '+placeholders.slice(0,12).join(', ')+'.']);
|
|
76
|
+
if(links.length>1) checks.push(['Links','Review whether each link serves the reader’s next step. Keep any required opt-out.']);
|
|
77
|
+
for(const [s,size] of long.slice(0,12)) checks.push(['Long sentence',size+' words — '+(s.length>350?s.slice(0,347)+'…':s)]);
|
|
78
|
+
return result([['Words',whole(words.length)],['Paragraphs',whole(paragraphs.length)],['Links found',whole(links.length)],
|
|
79
|
+
['Possible requests',whole(asks.length)]],{
|
|
80
|
+
table:{columns:['Check','What to review'],rows:checks},
|
|
81
|
+
notes:[checks.length?'Treat these suggestions as prompts for a human review.':'No issues were detected by these simple copy rules.',
|
|
82
|
+
'Word and request counts are estimates. This tool assesses the draft text, rather than predicting inbox placement or replies.']});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parseSpin(text) {
|
|
86
|
+
let p=0;
|
|
87
|
+
function invalid(message){throw new InputError(message+' Near character '+(p+1)+'.');}
|
|
88
|
+
function sequence(depth) {
|
|
89
|
+
if(depth>32) invalid('The format nests more than 32 groups.');
|
|
90
|
+
const nodes=[];
|
|
91
|
+
let literal='';
|
|
92
|
+
const flush=()=>{if(literal){nodes.push({text:literal,count:1n});literal='';}};
|
|
93
|
+
while(p<text.length){
|
|
94
|
+
const ch=text[p];
|
|
95
|
+
if(ch==='\\' && '{}|\\'.includes(text[p+1]??'\0')){literal+=text[p+1];p+=2;continue;}
|
|
96
|
+
if(ch==='{' ){
|
|
97
|
+
flush();p++;
|
|
98
|
+
const branches=[sequence(depth+1)];
|
|
99
|
+
while(text[p]==='|'){p++;branches.push(sequence(depth+1));}
|
|
100
|
+
if(text[p]!=='}') invalid('An opening brace has no matching closing brace');
|
|
101
|
+
if(branches.length<2) invalid('Add a pipe between at least two choices, or escape literal braces');
|
|
102
|
+
p++;
|
|
103
|
+
nodes.push({branches,count:branches.reduce((sum,branch)=>sum+branch.count,0n)});
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if(ch==='|'||ch==='}'){
|
|
107
|
+
if(depth===0) invalid('Escape a literal pipe or close an opened group');
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
literal+=ch;p++;
|
|
111
|
+
}
|
|
112
|
+
flush();
|
|
113
|
+
return {nodes,count:nodes.reduce((total,node)=>total*node.count,1n)};
|
|
114
|
+
}
|
|
115
|
+
return sequence(0);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function spinText(tree,index) {
|
|
119
|
+
let output='';
|
|
120
|
+
for(const node of tree.nodes){
|
|
121
|
+
let pick=index%node.count;
|
|
122
|
+
index/=node.count;
|
|
123
|
+
if(node.text!==undefined){output+=node.text;continue;}
|
|
124
|
+
for(const branch of node.branches){
|
|
125
|
+
if(pick<branch.count){output+=spinText(branch,pick);break;}
|
|
126
|
+
pick-=branch.count;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return output;
|
|
130
|
+
}
|
|
131
|
+
export function spintax(input) {
|
|
132
|
+
const text=requiredText(input.spintax,'a template',15_000);
|
|
133
|
+
const count=readNumber(input,'preview_count',1,30,{integer:true});
|
|
134
|
+
const tree=parseSpin(text);
|
|
135
|
+
const preview=tree.count<BigInt(count)?Number(tree.count):count;
|
|
136
|
+
const blocks=Array.from({length:preview},(_,i)=>['Variant '+(i+1),spinText(tree,BigInt(i)*tree.count/BigInt(preview))]);
|
|
137
|
+
return result([['Possible paths',tree.count.toLocaleString('en-US')],['Previews',whole(blocks.length)]],{
|
|
138
|
+
blocks, notes:['Counts are exact for this syntax. Repeated alternatives can produce identical messages.',
|
|
139
|
+
'Preview choices are spread across the template’s variation paths. Verify the syntax in your sending platform before using it.']});
|
|
140
|
+
}
|