How to use the alfy.config function in alfy

To help you get started, we’ve selected a few alfy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonrohan / alfred-figma / index.js View on Github external
const alfy = require('alfy')
const utils = require('./lib/utils')

const promises = []
const items = []

// teams config
const teams = alfy.config.get('figma.teams') ? JSON.parse(alfy.config.get('figma.teams')) : []
const isAddingTeam = alfy.input.match(/^add\shttps:\/\/www\.figma\.com\/files\/team\/(\d+)\/([^\/]+)/i)

if(isAddingTeam) {
  return alfy.output([{
    title: isAddingTeam[2],
    subtitle: `Add ${isAddingTeam[2]} team’s project files to your search results.`,
    arg: JSON.stringify({id: isAddingTeam[1], name: isAddingTeam[2]}),
    variables: {
      action: 'add',
      notification: `${isAddingTeam[2]} team’s projects and files added to search results.`
    }
  }])
}

Promise.all(teams.map(team => {
  return Promise.resolve(items.push({
github bikenik / alfred-anki / src / anki / anki-add-card.js View on Github external
/* eslint-disable no-unused-vars */
/* eslint-disable camelcase */
const alfy = require('alfy')
const ankiConnect = require('./anki-connect')
const decks = require('./anki-decks')

const nameOfDeck = alfy.config.get('default-deck')
const note_type = Object.keys(alfy.config.get('default-model'))[0]

const logResult = {
	error: [],
	result: []
}

module.exports = async function (output) {
	/* eslint-disable no-await-in-loop */
	for (let i = 0; i < output.length; i++) {
		if (output[i].Homnum) {
			output[i].Headword = `${output[i].Headword}<span class="HOMNUM-title">${
				output[i].Homnum.toString()}</span>`
		}

		delete output[i].Inflections // Can't understood the reason of error without delete
github bikenik / alfred-anki / src / index.js View on Github external
/* eslint camelcase: ["error", {properties: "never"}] */
/* eslint-parserOptions: {"ecmaVersion: 2017"} */

'use strict'
const fs = require('fs')
const alfy = require('alfy')
const jsonfile = require('jsonfile')
const pMap = require('p-map')
const {markdownIt} = require('./utils/engine')
const ankiAddCard = require('./anki/anki-add-card')
const config = require('./config').card

const modelFieldNames = require(`${process.env.alfred_workflow_data}/anki-model-fields.json`)

const modelId = alfy.config.get('default-model') ? alfy.config.get('default-model')[Object.keys(alfy.config.get('default-model'))[0]] : null

const header = jsonfile.readFileSync(config.input)

let firstField = [Object.keys(header)[0]]
if (firstField[0] === undefined) {
	firstField = modelFieldNames[0]
	header[firstField] = ''
}

async function main(id) {
	setupDirStructure()
	const cleanedInput = cleanInput(header)
	const output = await processInput(cleanedInput, id)
	await ankiAddCard(output)
}
github bikenik / alfred-anki / src / cmd / models.js View on Github external
const mapper = key => ({
		title: `${key}${
			Object.keys(alfy.config.get(key))[0] === undefined ? config.models['default-model'] : Object.keys(alfy.config.get(key))[0]}`,
		subtitle: '↵ pick out another model...',
		valid: false,
		autocomplete: `!model ${key} `,
		icon: {path: './icons/Model.png'}
	})
github bikenik / alfred-anki / src / anki / anki-info.js View on Github external
const alfy = require('alfy')
const jsonfile = require('jsonfile')
const WorkflowError = require('../utils/error')
const decks = require('../anki/anki-decks')
const {errorAction} = require('../utils/error')
const config = require('../config').card
const {modelExist} = require('./anki-models')
const ankiConnect = require('./anki-connect')

const fileAnkiDecks = `${process.env.alfred_workflow_data}/anki-decks.json`
const model = alfy.config.get('default-model') ? Object.keys(alfy.config.get('default-model'))[0] : null

module.exports = async () => {
	const introMessage = [{
		name: 'intro',
		title: alfy.config.get('default-deck') ? 'Create new card (⌘ + ↵)' : 'press ↵ or ↹ to select default deck',
		subtitle: alfy.config.get('default-deck') ? `🧰 ${alfy.config.get('default-deck')}${model}    👤 ${alfy.config.get('default-profile')}` : '',
		icon: {path: './icons/anki.png'},
		autocomplete: '!deck default-deck ',
		valid: false,
		arg: '',
		quicklookurl: `${config.mediaDir}/_preview.html`,
		mods: {
			alt: {
				subtitle: '❌ RESET',
				valid: true,
				variables: {
github bikenik / alfred-anki / src / cmd / decks.js View on Github external
const mapper = key => ({
		title: `${key}${
			alfy.config.get(key) === undefined ? config.defaults['default-deck'] : alfy.config.get(key)}`,
		subtitle: '↵ pick out another ...',
		valid: false,
		autocomplete: `!deck ${key} `,
		icon: {path: './icons/deck-settings.png'}
	})
github bikenik / alfred-anki / src / wf / index.js View on Github external
item.subtitle = field
		item.arg = ''
		item.quicklookurl = `${config.mediaDir}/_preview.html`
		item.icon = alfy.config.get('fields') && alfy.config.get('fields')[modelId][field] === 'rli' ? fs.existsSync(`./icons/${field}.png`) ? `./icons/${field}_marked.png` : './icons/flag_marked.png' : fs.existsSync(`./icons/${field}.png`) ? `./icons/${field}.png` : './icons/flag.png'
		item.variables = variables(field)
		item.mods = mods(field)
		items.push(item.getProperties())
	}

	const tags = new Render('Tags',
		'title', 'variables', 'quicklookurl', 'subtitle', 'arg', 'icon', 'mods')
	tags.title = header[modelId] && header[modelId].Tag ? header[modelId].Tag : '...'
	tags.subtitle = 'Choose your tags'
	tags.arg = ''
	tags.quicklookurl = `${config.mediaDir}/_preview.html`
	tags.icon = alfy.config.get('Tag') === 'rli' ? './icons/tag_marked.png' : './icons/tag.png'
	tags.variables = {
		mode: 'Tags',
		action: 'work'
	}
	tags.mods = mods('Tag')
	items.push(tags.getProperties())
	return items
}
github bikenik / alfred-anki / src / cmd / del.js View on Github external
const mapper = key => ({
		title: key,
		subtitle: `current deck is ⇒ ${alfy.config.get('default-deck')} | ↵ choose this or pick out another`,
		valid: false,
		autocomplete: `!del ${key} `,
		icon: {path: './icons/delete.png'}
	})
github bikenik / alfred-anki / src / utils / error.js View on Github external
case 'modelExist':
			if (alfy.config.get('default-model')) {
				title = `model "${Object.keys(alfy.config.get('default-model'))[0]}" was not found`
				subtitle = `Pres ⇤ (tab) to pick out exist note type. Or ⇧↵ to open Anki & choose another profile which has current note type.`
				text = {largetype: subtitle}
				autocomplete = '!models default-model '
			} else {
				title = `no model selected`
				subtitle = `Pres ⇤ (tab) to pick out exist note type. Or ⇧↵ to open Anki & choose another profile which has current note type.`
				text = {largetype: subtitle}
				autocomplete = '!models default-model '
			}

			break
		case 'new-profile':
			title = `Select model for [👤${alfy.config.get('default-profile')}] profile`
			subtitle = `Pres ⇤ (tab) to pick out exist profile. Or ⇧↵ to open Anki & choose another profile which has current note type.`
			text = {largetype: subtitle}
			autocomplete = '!models default-model '
			break
		case '!deck decks':
			title = null
			subtitle = '⇧↵ to open Anki. | ⌘L to see the stack trace'
			text = {largetype: subtitle}
			autocomplete = '!deck '
			break
		case '!model models':
			title = null
			subtitle = '⇧↵ to open Anki. | ⌘L to see the stack trace'
			text = {largetype: subtitle}
			autocomplete = '!model '
			break
github importre / alfred-hl / src / utils.js View on Github external
const alfy = require('alfy');

function getRtf(colorList, codeBlock, bg) {
  return `{\\rtf1\\ansi
{\\fonttbl\\f0\\fswiss\\fcharset0 Menlo;}
{\\colortbl;${colorList};}
\\f0\\fs24
${codeBlock}${bg}
}`;
}

module.exports = {
  theme: alfy.config.get('theme') || 'github',
  getRtf: getRtf,
};