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 19, 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 operatorSpacing = i => join(i.map(string =>
                                 string
                                 .replace(/\s*([-=+/*%<>])\s*/g," $1 ")
                                 .replace(/([-+=/*%<>])\s*([-+=])/g, "$1$2")
                                ));

var markdownCodeIndent = str => str.replace(/^/mg, "    ");

var cutboxFunctions = [
  {
    name: "Squeeze",
    fn: squeeze,
  },
  {
    name: "Operator spacing",
    fn: operatorSpacing
  },
  {
    name: "Double Quoted",
    fn: i => join(i.map(e => `"${e}"`)),
  },
  {
    name: "Single Quoted",
    fn: i => join(i.map(e => `'${e}'`)),
  },
  {
    name: "Array formatted (quoted)",
    fn: i => `[
${join(i.map(e => `"${e}",`))}
]`,
  },
  {
    name: "Array formatted (unquoted)",
    fn: i => `[
${join(i.map(e => `${e},`))}
]`,
  },
  {
    name: "Localized Pair",
    fn: i => `"${i[0]}" = "${i[1]}";`
  },
  {
    name: "Markdown code fenced",
    fn: i => `\`\`\`
${join(i)}
\`\`\``
  },
  {
    name: "Markdown code indented",
    fn: i => join(
      i.map(e => markdownCodeIndent(e) )
    )
  },
  {
    name: "Upper cased",
    fn: i => join(i.map(e => e.toUpperCase())),
  },
  {
    name: "Lower cased",
    fn: i => join(i.map(e => e.toLowerCase())),
  },
];