-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.js
More file actions
18 lines (11 loc) · 820 Bytes
/
transform.js
File metadata and controls
18 lines (11 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const applyEachLine = (applier, {applyToBlankline} = {}) => (input, ...args) =>
input.split('\n').map(line => (applyToBlankline || line) && applier(line, ...args));
export const prepend = (input, target) => target + ' ' + input;
export const prependEachLine = ({applyToBlankline} = {}) => (input, target) =>
applyEachLine(prepend, {applyToBlankline})(input, target);
export const append = (input, target) => input + ' ' + target;
export const wrap = (input, start, end = start) => start + input + end;
export const wrapEachLine = ({applyToBlankline} = {}) => (input, start, end = start) =>
applyEachLine(wrap, {applyToBlankline})(input, start, end);
export const linkify = url => `[](${url})`;
export const linkifyEachLine = ({applyToBlankline} = {}) => url => applyEachLine(linkify, {applyToBlankline})(url);