// Name: Units Convert// Description: Convert between metric and imperial units// Author: Vedinsoh// GitHub: @Vedinsohimport "@johnlindquist/kit";const convert = await npm("convert-units");const getAllPossibilities = (unit) => {const possibilities = unit? convert().from(unit).possibilities(): convert().possibilities();return possibilities.map((u) => {const uDetails = convert().describe(u);return {name: `${u} - ${uDetails.plural}`,value: u,};}).sort((a, b) => {const aDetails = convert().describe(a.value);const bDetails = convert().describe(b.value);if (aDetails.system === bDetails.system) {return aDetails.value - bDetails.value;}return aDetails.system - bDetails.system;});};const getUnitString = (unit) => {const unitDetails = convert().describe(unit);return `${unitDetails.plural} (${unit})`;};const convertUnits = (from, to, amount) => {return String(convert(amount).from(from).to(to));};const fromUnit = await arg({placeholder: "From",choices: getAllPossibilities(),enter: "To",});const toUnit = await arg({placeholder: "To",choices: getAllPossibilities(fromUnit),enter: "Amount",hint: `Convert from ${fromUnit} to...`,});await arg({placeholder: "Amount",type: "number",enter: "Exit",hint: `${getUnitString(fromUnit)} equals...`,onInput: (input) => {const result = convertUnits(fromUnit, toUnit, input);setPanel(md(`# ${result} ${getUnitString(toUnit)}`));},shortcuts: [{name: "Copy result",key: `${cmd}+c`,onPress: (input) => {copy(convertUnits(fromUnit, toUnit, input));},bar: "right",},],});
// Name: IP & Domain Lookup// Description: Get information about an IP address or domain// Author: Vedinsoh// GitHub: @Vedinsohimport "@johnlindquist/kit";import net from "node:net";import { URL } from "node:url";const getLookupData = async (query) => {// Reference: https://ip-api.com/docs/api:jsonconst response = await get(`http://ip-api.com/json/${query}?fields=status,message,continent,country,countryCode,regionName,city,zip,lat,lon,timezone,isp,org,as,query`);if (response.data.status === "fail") {throw new Error(response.data.message);}return response.data;};let lookupQuery = await arg({placeholder: "Enter IP address or domain",validate: (value) => {if (net.isIP(value) !== 0) {return true;} else {try {new URL(`https://${value}`);return true;} catch (e) {return "Please enter a valid IP address or domain";}}},});const data = await getLookupData(lookupQuery);div(md(`# IP Lookup: ${lookupQuery}- **IP:** ${data.query}- **ISP:** ${data.isp}- **Organization:** ${data.org}- **AS:** ${data.as}- **Continent:** ${data.continent}- **Country:** ${data.country} (${data.countryCode})- **Region:** ${data.regionName}- **City:** ${data.city}- **Zip Code:** ${data.zip}- **Latitude:** ${data.lat}- **Longitude:** ${data.lon}- **Timezone:** ${data.timezone}`));
// Name: Time from now// Description: Calculates the time from now to a given time in the future or past// Author: Vedinsoh// GitHub: @Vedinsohimport "@johnlindquist/kit";const [startDay, startHour, startMinute, startSecond] = await fields([{name: "day",label: "Day",type: "number",value: 0,},{name: "hour",label: "Hour",type: "number",value: 0,},{name: "minute",label: "Minute",type: "number",value: 0,},{name: "second",label: "Second",type: "number",value: 0,},]);function parseNumber(value) {const parsed = parseInt(value, 10);return Number.isNaN(parsed) ? 0 : parsed;}const values = {day: parseNumber(startDay),hour: parseNumber(startHour),minute: parseNumber(startMinute),second: parseNumber(startSecond),};function calculate() {const now = new Date();const future = new Date(now);future.setDate(future.getDate() + values.day);future.setHours(future.getHours() + values.hour);future.setMinutes(future.getMinutes() + values.minute);future.setSeconds(future.getSeconds() + values.second);return future.toLocaleString();}function displayInputs() {const formatDisplayValue = (value, label = "") => {if (value !== 0) {return `${value} ${label}${Math.abs(value) !== 1 ? "s" : ""}`;}return "";};const displayDay = formatDisplayValue(values.day, "day");const displayHour = formatDisplayValue(values.hour, "hour");const displayMinute = formatDisplayValue(values.minute, "minute");const displaySecond = formatDisplayValue(values.second, "second");return [displayDay, displayHour, displayMinute, displaySecond].filter((value) => value).join(", ");}div(`<div><div class="text-center text-2xl m-16">${displayInputs()} from now:</div><div class="text-center text-4xl p-10 font-semibold">${calculate()}</div></div>`);