Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Javascript Examples

Jason Milkins edited this page May 17, 2018 · 26 revisions

Example ~/.cutbox.js

var join = i => i.join(i.length > 0 ? "\n" : "");

var squeeze = i => join( i.map( s => s.replace(/\s+/g, ' ')));

var cutboxFunctions = [
  {
    name: "Squeeze",
    key: "s",
    fn: squeeze,
  },
  {
    name: "Double Quoted",
    key: "\"",
    fn: i => join(i.map(e => `"${e}"`)),
  },
  {
    name: "Single Quoted",
    key: "'",
    fn: i => join(i.map(e => `'${e}'`)),
  },
  {
    name: "Array formatted (quoted)",
    key: "[",
    fn: i => `[
${join(i.map(e => `"${e}",`))}
]`,
  },
  {
    name: "Array formatted (unquoted)",
    key: "[",
    fn: i => `[
${join(i.map(e => `${e},`))}
]`,
  },
  {
    name: "Cutbox Issue URL",
    key: "i",
    fn: i => join(i.map(e => `https://github.com/CutBox/CutBox/issues/${e}`)),
  },
  {
    name: "Markdown code fenced",
    key: "`",
    fn: i => `\`\`\`
${join(i)}
\`\`\``
  },
  {
    name: "Markdown code indented",
    key: "c",
    fn: i => join(
      i.map(e => `    ${e}`)
    )
  },
  {
    name: "Upper cased",
    key: "u",
    fn: i => join(i.map(e => e.toUpperCase())),
  },
  {
    name: "Lower cased",
    key: "l",
    fn: i => join(i.map(e => e.toLowerCase())),
  },
];