Alken E

Alken E

// Name: JS Expression
// Description: I prefer to define it as a simple calculator
// Global Objects
let arr = [1, 2, 3, 4, 5]
let obj = {name: 'Mike', age: 20}
// Global Functions
let {
ceil, floor, round, trunc, abs, PI,
sin, cos, tan, log, log2, log10, exp, sqrt, cbrt, pow
} = Math
// Factorial
let fact = num => _.reduce(_.range(1, num + 1), (acc, i) => acc * i, 1)
let selected = await arg({
placeholder: 'Expression ...',
enter: 'Copy & Exit',
shortcuts: [{
name: 'Repalce', key: 'cmd+r', bar: 'right', onPress: async (input, {focused}) => {
setInput(evalExp(input))
}
}]
}, async (input) => {
let res = input ? evalExp(input) : ''
return md(`~~~javascript\n${res}\n~~~`)
})
if (selected) await copy(evalExp(selected))
function evalExp(input) {
let value = eval(`(${input})`)
if (typeof value == 'number') return (value % 1 != 0 ? value.toFixed(2) : value) + ''
if (typeof value == 'array') return JSON.stringify(value, null, 2)
if (typeof value == 'object') return JSON.stringify(value, null, 2)
if (typeof value == 'function') return ''
}
<img width="768" alt="image" src="https://github.com/johnlindquist/kit/assets/61105068/5a168b8c-db66-4912-8cd0-afbc741b78a6">

// Name: Steam
import axios from 'axios'
import cheerio from 'cheerio'
// Language-dependent configuration
const cc = 'US'
const l = 'english'
function buildResult(value, image, title) {
return {
name: 'abc',
value: value,
html: `
<div class="flex flex-row h-full w-full">
<img class="h-full" src="${image}"/>
<h2 class="flex-1 flex flex-row items-center justify-center">${title}</h2>
<div class="flex flex-row text-xxs items-center justify-right">open</div>
</div>
`,
}
}
let url = await arg('Keyword ...', async keyword => {
if (keyword.trim() == '') return []
let {data} = await axios.get(
'https://store.steampowered.com/search/suggest?term=' + keyword +
'&f=games&cc=' + cc + '&realm=1&l=s' + l + '&v=19040599&excluded_content_descriptors%5B%5D=3' +
'&excluded_content_descriptors%5B%5D=4&use_store_query=1&use_search_spellcheck=1&search_creators_and_tags=1'
);
let $ = cheerio.load(data);
let games = $('a').get().map(aTag => {
if ($(aTag).hasClass('match_app')) {
let name = $(aTag).find('.match_name').text();
let price = $(aTag).find('.match_subtitle').text();
let cover = $(aTag).find('.match_img img').attr('src');
let url = $(aTag).attr('href');
return buildResult(url, cover, `${name} - ${price}`)
}
if ($(aTag).hasClass('match_tag')) {
let name = $(aTag).find('.match_name span').text();
let count = $(aTag).find('.match_subtitle').text();
let url = $(aTag).attr('href');
return buildResult(url, 'https://pbs.twimg.com/profile_images/861662902780018688/SFie8jER_x96.jpg', `${name} - ${count}`)
}
if ($(aTag).hasClass('match_creator')) {
let name = $(aTag).find('.match_name').text();
let count = $(aTag).find('.match_subtitle').text();
let cover = $(aTag).find('.match_img img').attr('src');
let url = $(aTag).attr('href');
return buildResult(url, cover, `${name} - ${count}`)
}
});
return games.filter(x => x);
});
await $`open ${url}`
<img width="768" alt="image" src="https://github.com/johnlindquist/kit/assets/61105068/c38983bb-f26f-4bb5-a556-9b1b995f38df">