Vedinsoh

Vedinsoh

// Name: Units Convert
// Description: Convert between metric and imperial units
// Author: Vedinsoh
// GitHub: @Vedinsoh
import "@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: @Vedinsoh
import "@johnlindquist/kit";
import net from "node:net";
import { URL } from "node:url";
const getLookupData = async (query) => {
// Reference: https://ip-api.com/docs/api:json
const 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}
`)
);