[{"data":1,"prerenderedAt":1327,"buildId":1328},["ShallowReactive",2],{"docs:\u002Freference\u002Fapi":3},{"page":4,"section":16,"document":17,"credits":10,"prev":1324,"next":10},{"id":5,"path":6,"file":7,"title":8,"sourceTitle":8,"description":9,"tagline":9,"eyebrow":10,"credits":10,"keywords":11,"icon":12,"layout":13,"sidebar":14,"toc":14,"kind":10,"group":10,"navigation":14,"order":15},"api","\u002Freference\u002Fapi","reference\u002Fapi.md","JavaScript API","scan, check, measure, defineSource and the report types, for programs that use whatfrees as a library.",null,[],"i-lucide-code","article",true,3,"reference",{"nodes":18,"toc":1315},[19,23,124,130,136,227,243,415,428,432,500,539,543,607,617,680,726,738,744,752,968,1051,1076,1106,1144,1151,1157,1182,1188,1223],[20,21,22],"p",{},"whatfrees is an ES module for Node.js 22.20 or later on Linux or macOS. It has four entries.",[24,25,26,39],"table",{},[27,28,29],"thead",{},[30,31,32,36],"tr",{},[33,34,35],"th",{},"Import",[33,37,38],{},"Exports",[40,41,42,64,80,108],"tbody",{},[30,43,44,51],{},[45,46,47],"td",{},[48,49,50],"code",{},"whatfrees",[45,52,53,56,57,56,60,63],{},[48,54,55],{},"scan",", ",[48,58,59],{},"check",[48,61,62],{},"ScanOptions"," and every report type",[30,65,66,71],{},[45,67,68],{},[48,69,70],{},"whatfrees\u002Fmeasure",[45,72,73,56,76,79],{},[48,74,75],{},"measure",[48,77,78],{},"diskUsage"," and their types",[30,81,82,87],{},[45,83,84],{},[48,85,86],{},"whatfrees\u002Fsources",[45,88,89,56,92,56,95,56,98,56,101,56,104,107],{},[48,90,91],{},"sources",[48,93,94],{},"defineSource",[48,96,97],{},"runSources",[48,99,100],{},"quote",[48,102,103],{},"isAllowed",[48,105,106],{},"ALLOWED_COMMANDS"," and the source types",[30,109,110,115],{},[45,111,112],{},[48,113,114],{},"whatfrees\u002Fschema",[45,116,117,56,120,123],{},[48,118,119],{},"REPORT_SCHEMA",[48,121,122],{},"CHECK_SCHEMA"," and the report types",[20,125,126,127,129],{},"Nothing here deletes, moves or changes a file. ",[48,128,55],{}," writes only the size cache.",[131,132,55],"h2",{"id":55,"anchor":133},{"label":134,"icon":135},"Section titled \"scan\"","#",[137,138,141],"pre",{"language":139,"class":140,"wrap":14},"ts","shiki shiki-themes github-light-default github-dark-default dark:github-dark-default",[48,142,144,167,168,167,170,167,216],{"class":143},"language-ts",[145,146,149,153,157,160,164],"span",{"class":147,"style":148},"line","display: inline",[145,150,152],{"style":151},"color:#CF222E;--shiki-dark:#FF7B72","import",[145,154,156],{"style":155},"color:#1F2328;--shiki-dark:#E6EDF3"," { scan } ",[145,158,159],{"style":151},"from",[145,161,163],{"style":162},"color:#0A3069;--shiki-dark:#A5D6FF"," \"whatfrees\"",[145,165,166],{"style":155},";","\n",[145,169],{"class":147,"style":148},[145,171,172,175,179,182,185,189,192,195,198,201,204,207,210,213],{"class":147,"style":148},[145,173,174],{"style":151},"const",[145,176,178],{"style":177},"color:#0550AE;--shiki-dark:#79C0FF"," report",[145,180,181],{"style":151}," =",[145,183,184],{"style":151}," await",[145,186,188],{"style":187},"color:#8250DF;--shiki-dark:#D2A8FF"," scan",[145,190,191],{"style":155},"({ min: ",[145,193,194],{"style":177},"10",[145,196,197],{"style":151}," *",[145,199,200],{"style":177}," 1024",[145,202,203],{"style":151}," **",[145,205,206],{"style":177}," 2",[145,208,209],{"style":155},", budget: ",[145,211,212],{"style":177},"2",[145,214,215],{"style":155}," });",[145,217,218,221,224],{"class":147,"style":148},[145,219,220],{"style":155},"console.",[145,222,223],{"style":187},"log",[145,225,226],{"style":155},"(report.totals, report.partial);",[20,228,229,232,233,236,237,242],{},[48,230,231],{},"scan(options?)"," returns a ",[48,234,235],{},"Report",". It rejects on Windows. See ",[238,239,241],"a",{"href":240},"\u002Freference\u002Freport","the JSON report"," for its shape.",[24,244,245,261],{},[27,246,247],{},[30,248,249,252,255,258],{},[33,250,251],{},"Option",[33,253,254],{},"Type",[33,256,257],{},"Default",[33,259,260],{},"Meaning",[40,262,263,281,302,324,342,359,375,398],{},[30,264,265,270,275,278],{},[45,266,267],{},[48,268,269],{},"only",[45,271,272],{},[48,273,274],{},"string[]",[45,276,277],{},"all sources",[45,279,280],{},"Source ids to run. An unknown id throws",[30,282,283,288,292,295],{},[45,284,285],{},[48,286,287],{},"roots",[45,289,290],{},[48,291,274],{},[45,293,294],{},"none",[45,296,297,298,301],{},"Extra folders for the ",[48,299,300],{},"worktrees"," source",[30,303,304,309,312,317],{},[45,305,306],{},[48,307,308],{},"budget",[45,310,311],{},"number",[45,313,314],{},[48,315,316],{},"5",[45,318,319,320,323],{},"Seconds for the whole scan. With ",[48,321,322],{},"0",", owners answer and nothing is walked",[30,325,326,331,334,339],{},[45,327,328],{},[48,329,330],{},"exact",[45,332,333],{},"boolean",[45,335,336],{},[48,337,338],{},"false",[45,340,341],{},"Walk every tree to the end, with no cache",[30,343,344,349,351,356],{},[45,345,346],{},[48,347,348],{},"cache",[45,350,333],{},[45,352,353],{},[48,354,355],{},"true",[45,357,358],{},"Read and write the size cache",[30,360,361,366,368,372],{},[45,362,363],{},[48,364,365],{},"min",[45,367,311],{},[45,369,370],{},[48,371,322],{},[45,373,374],{},"Leave out entries that free fewer bytes. The totals still count them. The command line passes 50 MB",[30,376,377,382,384,388],{},[45,378,379],{},[48,380,381],{},"all",[45,383,333],{},[45,385,386],{},[48,387,338],{},[45,389,390,391,393,394,397],{},"Keep the entries ",[48,392,365],{}," and ",[48,395,396],{},"live"," would leave out",[30,399,400,404,409,412],{},[45,401,402],{},[48,403,91],{},[45,405,406],{},[48,407,408],{},"Source[]",[45,410,411],{},"the built-in ones",[45,413,414],{},"Sources to run instead",[20,416,417,418,420,421,423,424,427],{},"The library's ",[48,419,365],{}," defaults to ",[48,422,322],{},". The command line's ",[48,425,426],{},"--min"," defaults to 50 MB.",[131,429,59],{"id":59,"anchor":430},{"label":431,"icon":135},"Section titled \"check\"",[137,433,434],{"language":139,"class":140,"wrap":14},[48,435,436,167,449,167,451,167,474],{"class":143},[145,437,438,440,443,445,447],{"class":147,"style":148},[145,439,152],{"style":151},[145,441,442],{"style":155}," { check } ",[145,444,159],{"style":151},[145,446,163],{"style":162},[145,448,166],{"style":155},[145,450],{"class":147,"style":148},[145,452,453,455,458,460,462,465,468,471],{"class":147,"style":148},[145,454,174],{"style":151},[145,456,457],{"style":177}," answer",[145,459,181],{"style":151},[145,461,184],{"style":151},[145,463,464],{"style":187}," check",[145,466,467],{"style":155},"(",[145,469,470],{"style":162},"\"\u002Fhome\u002Fyou\u002F.codex\u002Fworktrees\u002F9f2c\u002Fapp\"",[145,472,473],{"style":155},");",[145,475,476,479,482,485,488,491,493,495,498],{"class":147,"style":148},[145,477,478],{"style":151},"if",[145,480,481],{"style":155}," (answer.verdict ",[145,483,484],{"style":151},"===",[145,486,487],{"style":162}," \"safe\"",[145,489,490],{"style":155},") console.",[145,492,223],{"style":187},[145,494,467],{"style":155},[145,496,497],{"style":162},"\"go on\"",[145,499,473],{"style":155},[20,501,502,232,505,508,509,512,513,516,517,519,520,393,523,526,527,530,531,533,534,538],{},[48,503,504],{},"check(path)",[48,506,507],{},"CheckResult",": ",[48,510,511],{},"{ schema, path, exists, verdict, deletable, evidence }",". ",[48,514,515],{},"deletable"," is ",[48,518,355],{}," only for ",[48,521,522],{},"safe",[48,524,525],{},"orphan"," on a path that exists. Check the ",[48,528,529],{},"verdict"," itself before automatic cleanup: an ",[48,532,525],{}," still needs manual review. See ",[238,535,537],{"href":536},"\u002Fguide\u002Fcheck","whatfrees check",".",[131,540,75],{"id":75,"anchor":541},{"label":542,"icon":135},"Section titled \"measure\"",[137,544,545],{"language":139,"class":140,"wrap":14},[48,546,547,167,561,167,563,167,598],{"class":143},[145,548,549,551,554,556,559],{"class":147,"style":148},[145,550,152],{"style":151},[145,552,553],{"style":155}," { measure } ",[145,555,159],{"style":151},[145,557,558],{"style":162}," \"whatfrees\u002Fmeasure\"",[145,560,166],{"style":155},[145,562],{"class":147,"style":148},[145,564,565,567,570,573,576,579,581,584,587,590,593,596],{"class":147,"style":148},[145,566,174],{"style":151},[145,568,569],{"style":155}," [",[145,571,572],{"style":177},"tree",[145,574,575],{"style":155},"] ",[145,577,578],{"style":151},"=",[145,580,184],{"style":151},[145,582,583],{"style":187}," measure",[145,585,586],{"style":155},"([",[145,588,589],{"style":162},"\"\u002Fhome\u002Fyou\u002Fapp\u002Fnode_modules\"",[145,591,592],{"style":155},"], { deadlineMs: ",[145,594,595],{"style":177},"2000",[145,597,215],{"style":155},[145,599,600,602,604],{"class":147,"style":148},[145,601,220],{"style":155},[145,603,223],{"style":187},[145,605,606],{"style":155},"(tree.frees, tree.apparent, tree.shared, tree.precision);",[20,608,609,612,613,616],{},[48,610,611],{},"measure(paths, options?)"," walks trees in parallel and returns one ",[48,614,615],{},"Measured"," per path. It doesn't follow symlinks or cross into another file system.",[24,618,619,629],{},[27,620,621],{},[30,622,623,625,627],{},[33,624,251],{},[33,626,257],{},[33,628,260],{},[40,630,631,646,664],{},[30,632,633,638,640],{},[45,634,635],{},[48,636,637],{},"deadlineMs",[45,639,294],{},[45,641,642,643],{},"Time budget. A tree still being read comes back as a ",[48,644,645],{},"lower-bound",[30,647,648,653,658],{},[45,649,650],{},[48,651,652],{},"workers",[45,654,655],{},[48,656,657],{},"4",[45,659,660,661,663],{},"Walker threads. ",[48,662,322],{}," walks in the calling thread",[30,665,666,671,673],{},[45,667,668],{},[48,669,670],{},"signal",[45,672,294],{},[45,674,675,676,679],{},"An ",[48,677,678],{},"AbortSignal",". Aborting rejects the call",[20,681,682,683,685,686,56,689,56,692,56,695,56,698,56,701,704,705,708,709,712,713,516,715,56,717,719,720,512,723,725],{},"A ",[48,684,615],{}," has ",[48,687,688],{},"path",[48,690,691],{},"frees",[48,693,694],{},"apparent",[48,696,697],{},"shared",[48,699,700],{},"precision",[48,702,703],{},"files"," and, when the path couldn't be read, ",[48,706,707],{},"error"," with the code, such as ",[48,710,711],{},"ENOENT",". Here ",[48,714,700],{},[48,716,330],{},[48,718,645],{}," or ",[48,721,722],{},"unmeasured",[48,724,703],{}," counts everything that isn't a folder.",[20,727,728,731,732,735,736,538],{},[48,729,730],{},"diskUsage(path)"," returns ",[48,733,734],{},"{ free, total }"," in bytes for the file system that holds ",[48,737,688],{},[131,739,743],{"id":740,"anchor":741},"defining-a-source",{"label":742,"icon":135},"Section titled \"Defining a source\"","Defining a source",[20,745,746,747,749,750,538],{},"A source is one place that holds space. Build it with ",[48,748,94],{},", then pass it to ",[48,751,55],{},[137,753,754],{"language":139,"class":140,"wrap":14},[48,755,756,167,768,167,782,167,784,167,799,167,810,167,820,167,836,167,852,167,863,167,868,167,878,167,888,167,898,167,908,167,932,167,937,167,942,167,947,167,949],{"class":143},[145,757,758,760,762,764,766],{"class":147,"style":148},[145,759,152],{"style":151},[145,761,156],{"style":155},[145,763,159],{"style":151},[145,765,163],{"style":162},[145,767,166],{"style":155},[145,769,770,772,775,777,780],{"class":147,"style":148},[145,771,152],{"style":151},[145,773,774],{"style":155}," { defineSource } ",[145,776,159],{"style":151},[145,778,779],{"style":162}," \"whatfrees\u002Fsources\"",[145,781,166],{"style":155},[145,783],{"class":147,"style":148},[145,785,786,788,791,793,796],{"class":147,"style":148},[145,787,174],{"style":151},[145,789,790],{"style":177}," scratch",[145,792,181],{"style":151},[145,794,795],{"style":187}," defineSource",[145,797,798],{"style":155},"({",[145,800,801,804,807],{"class":147,"style":148},[145,802,803],{"style":155},"  id: ",[145,805,806],{"style":162},"\"scratch\"",[145,808,809],{"style":155},",",[145,811,812,815,818],{"class":147,"style":148},[145,813,814],{"style":155},"  description: ",[145,816,817],{"style":162},"\"Folders named scratch in the project.\"",[145,819,809],{"style":155},[145,821,822,825,828,830,833],{"class":147,"style":148},[145,823,824],{"style":155},"  platforms: [",[145,826,827],{"style":162},"\"linux\"",[145,829,56],{"style":155},[145,831,832],{"style":162},"\"darwin\"",[145,834,835],{"style":155},"],",[145,837,838,841,844,847,850],{"class":147,"style":148},[145,839,840],{"style":187},"  detect",[145,842,843],{"style":155},": () ",[145,845,846],{"style":151},"=>",[145,848,849],{"style":177}," true",[145,851,809],{"style":155},[145,853,854,857,859,861],{"class":147,"style":148},[145,855,856],{"style":187},"  entries",[145,858,843],{"style":155},[145,860,846],{"style":151},[145,862,569],{"style":155},[145,864,865],{"class":147,"style":148},[145,866,867],{"style":155},"    {",[145,869,870,873,876],{"class":147,"style":148},[145,871,872],{"style":155},"      what: ",[145,874,875],{"style":162},"\"scratch folder\"",[145,877,809],{"style":155},[145,879,880,883,886],{"class":147,"style":148},[145,881,882],{"style":155},"      path: ",[145,884,885],{"style":162},"\"\u002Fhome\u002Fyou\u002Fapp\u002Fscratch\"",[145,887,809],{"style":155},[145,889,890,893,896],{"class":147,"style":148},[145,891,892],{"style":155},"      verdict: ",[145,894,895],{"style":162},"\"ask\"",[145,897,809],{"style":155},[145,899,900,903,906],{"class":147,"style":148},[145,901,902],{"style":155},"      evidence: [",[145,904,905],{"style":162},"\"Nothing says what it is for.\"",[145,907,835],{"style":155},[145,909,910,913,916,918,921,923,926,928,930],{"class":147,"style":148},[145,911,912],{"style":155},"      command: [",[145,914,915],{"style":162},"\"rm\"",[145,917,56],{"style":155},[145,919,920],{"style":162},"\"-rf\"",[145,922,56],{"style":155},[145,924,925],{"style":162},"\"--\"",[145,927,56],{"style":155},[145,929,885],{"style":162},[145,931,835],{"style":155},[145,933,934],{"class":147,"style":148},[145,935,936],{"style":155},"    },",[145,938,939],{"class":147,"style":148},[145,940,941],{"style":155},"  ],",[145,943,944],{"class":147,"style":148},[145,945,946],{"style":155},"});",[145,948],{"class":147,"style":148},[145,950,951,953,955,957,959,961,964,966],{"class":147,"style":148},[145,952,174],{"style":151},[145,954,178],{"style":177},[145,956,181],{"style":151},[145,958,184],{"style":151},[145,960,188],{"style":187},[145,962,963],{"style":155},"({ sources: [scratch], min: ",[145,965,322],{"style":177},[145,967,215],{"style":155},[24,969,970,979],{},[27,971,972],{},[30,973,974,977],{},[33,975,976],{},"Field",[33,978,260],{},[40,980,981,995,1009,1023,1037],{},[30,982,983,988],{},[45,984,985],{},[48,986,987],{},"id",[45,989,990,991,994],{},"Lowercase words joined by ",[48,992,993],{},"-",". Anything else throws",[30,996,997,1002],{},[45,998,999],{},[48,1000,1001],{},"description",[45,1003,1004,1005,1008],{},"What it covers. ",[48,1006,1007],{},"whatfrees sources"," prints it",[30,1010,1011,1016],{},[45,1012,1013],{},[48,1014,1015],{},"platforms",[45,1017,1018,56,1020,1022],{},[48,1019,827],{},[48,1021,832],{}," or both",[30,1024,1025,1030],{},[45,1026,1027],{},[48,1028,1029],{},"detect(ctx)",[45,1031,1032,1033,1036],{},"Whether there is anything to look at. Keep it cheap: a file check or a ",[48,1034,1035],{},"PATH"," lookup",[30,1038,1039,1044],{},[45,1040,1041],{},[48,1042,1043],{},"entries(ctx)",[45,1045,1046,1047,1050],{},"What it found, as ",[48,1048,1049],{},"Found"," items. May be async",[20,1052,1053,1056,1057,56,1060,56,1063,56,1066,1068,1069,1071,1072,1075],{},[48,1054,1055],{},"ctx"," holds ",[48,1058,1059],{},"platform",[48,1061,1062],{},"home",[48,1064,1065],{},"env",[48,1067,287],{},", a ",[48,1070,670],{}," that aborts when the budget runs out, and a ",[48,1073,1074],{},"deadline",". Stop work when the signal aborts.",[20,1077,682,1078,685,1080,56,1083,393,1085,1088,1089,56,1092,56,1094,56,1097,56,1100,393,1103,538],{},[48,1079,1049],{},[48,1081,1082],{},"what",[48,1084,529],{},[48,1086,1087],{},"command",". It may also have ",[48,1090,1091],{},"key",[48,1093,688],{},[48,1095,1096],{},"bytes",[48,1098,1099],{},"evidence",[48,1101,1102],{},"then",[48,1104,1105],{},"lastUsed",[1107,1108,1109,1122,1133],"ul",{},[1110,1111,1112,1113,1115,1116,1118,1119,1121],"li",{},"Leave out ",[48,1114,1096],{}," and whatfrees measures ",[48,1117,688],{},". Pass ",[48,1120,1096],{}," when the owner already knows the size.",[1110,1123,1124,1126,1127,1129,1130,538],{},[48,1125,1087],{}," is the words of a command, verb first. whatfrees quotes them. A command whose verb isn't in ",[48,1128,106],{}," throws, and the source is skipped with ",[48,1131,1132],{},"reason: \"error\"",[1110,1134,1135,1137,1138,1140,1141,538],{},[48,1136,1091],{}," is unique within the source. It defaults to ",[48,1139,688],{},". The entry's id is ",[48,1142,1143],{},"\u003Csource id>:\u003Ckey>",[20,1145,1146,1147,1150],{},"Ask the owner first. Run subprocesses with a timeout and pass them ",[48,1148,1149],{},"ctx.signal",". Never delete in a source.",[1152,1153,97],"h3",{"id":1154,"anchor":1155},"runsources",{"label":1156,"icon":135},"Section titled \"runSources\"",[20,1158,1159,1162,1163,512,1166,1169,1170,56,1173,56,1175,393,1177,512,1179,1181],{},[48,1160,1161],{},"runSources(list, options)"," runs sources under one budget and returns ",[48,1164,1165],{},"{ entries, skipped, partial }",[48,1167,1168],{},"options"," needs ",[48,1171,1172],{},"budgetMs",[48,1174,1059],{},[48,1176,1062],{},[48,1178,1065],{},[48,1180,55],{}," builds on it and adds the totals, the disk and the filters.",[131,1183,1187],{"id":1184,"anchor":1185},"types",{"label":1186,"icon":135},"Section titled \"Types\"","Types",[20,1189,1190,393,1192,1194,1195,56,1197,56,1200,56,1203,56,1206,56,1209,56,1212,56,1214,393,1217,512,1220,1222],{},[48,1191,50],{},[48,1193,114],{}," export ",[48,1196,235],{},[48,1198,1199],{},"Entry",[48,1201,1202],{},"Bytes",[48,1204,1205],{},"Disk",[48,1207,1208],{},"Skipped",[48,1210,1211],{},"Next",[48,1213,507],{},[48,1215,1216],{},"Verdict",[48,1218,1219],{},"Precision",[48,1221,114],{}," also exports the two schema ids as constants.",[137,1224,1225],{"language":139,"class":140,"wrap":14},[48,1226,1227,167,1247,167,1249,167,1295,167,1310],{"class":143},[145,1228,1229,1231,1234,1237,1240,1242,1245],{"class":147,"style":148},[145,1230,152],{"style":151},[145,1232,1233],{"style":155}," { CHECK_SCHEMA, REPORT_SCHEMA, ",[145,1235,1236],{"style":151},"type",[145,1238,1239],{"style":155}," Report } ",[145,1241,159],{"style":151},[145,1243,1244],{"style":162}," \"whatfrees\u002Fschema\"",[145,1246,166],{"style":155},[145,1248],{"class":147,"style":148},[145,1250,1251,1254,1257,1259,1263,1266,1269,1272,1275,1278,1281,1283,1286,1289,1292],{"class":147,"style":148},[145,1252,1253],{"style":151},"function",[145,1255,1256],{"style":187}," isReport",[145,1258,467],{"style":155},[145,1260,1262],{"style":1261},"color:#953800;--shiki-dark:#FFA657","value",[145,1264,1265],{"style":151},":",[145,1267,1268],{"style":155}," { ",[145,1270,1271],{"style":1261},"schema",[145,1273,1274],{"style":151},"?:",[145,1276,1277],{"style":177}," string",[145,1279,1280],{"style":155}," })",[145,1282,1265],{"style":151},[145,1284,1285],{"style":1261}," value",[145,1287,1288],{"style":151}," is",[145,1290,1291],{"style":1261}," Report",[145,1293,1294],{"style":155}," {",[145,1296,1297,1300,1303,1305,1308],{"class":147,"style":148},[145,1298,1299],{"style":151},"  return",[145,1301,1302],{"style":155}," value.schema ",[145,1304,484],{"style":151},[145,1306,1307],{"style":177}," REPORT_SCHEMA",[145,1309,166],{"style":155},[145,1311,1312],{"class":147,"style":148},[145,1313,1314],{"style":155},"}",[1316,1318,1319,1320,1323],{"id":55,"depth":1317,"text":55},2,{"id":59,"depth":1317,"text":59},{"id":75,"depth":1317,"text":75},{"id":740,"depth":1317,"text":743,"children":1321},[1322],{"id":1154,"depth":15,"text":97},{"id":1184,"depth":1317,"text":1187},{"path":240,"title":1325,"description":1326},"JSON report","The whatfrees\u002Freport@1 document that whatfrees --json prints, field by field.",1796464608940,"84b4d453-0d43-4339-8103-d1d78e551efe"]