How to use the sanctuary.match function in sanctuary

To help you get started, we’ve selected a few sanctuary 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 voorhoede / playbook / src / url-matchers.js View on Github external
'use strict';

const { chain, match, pipe } = require('sanctuary');

const getYoutubeUrlId = pipe([
  match(/^https:\/\/w*\.*youtube\.com\/watch\?v=(\w{11})/),
  chain(match => match.groups[0]),
]);

const getYoutubePlaylistUrlId = pipe([
  match(/^https:\/\/w*\.*youtube\.com\/playlist\?list=([\w\d-]+)/),
  chain(match => match.groups[0]),
]);

module.exports = {
  getYoutubeUrlId,
  getYoutubePlaylistUrlId,
};
github raine / ramda-destruct / src / obj-destr.js View on Github external
S.fromMaybe(line, $do(function* () {
    const braceStart = yield S.indexOf('{', line);
    const braceEnd   = yield S.indexOf('}', line);
    const removeAfterStart = braceEnd - braceStart + 1;
    const insideBraces = slice(braceStart + 1, braceEnd, line);
    const hasSpaceFirst = isSpace(head(insideBraces));

    return yield S.match(/[a-zA-Z0-9_]+/g, insideBraces)
      .chain(sequence(Just))
      .concat(Just([]))
      .map(names =>
        pipe(
          op(__, names),
          uniq,
          sortBy(toLower),
          join(', '),
          fmt1(hasSpaceFirst ? '{ %s }' : '{%s}'),
          spliceStr(line, braceStart, removeAfterStart)
        )(name));
  }, Maybe))
);
github voorhoede / playbook / docs / .vuepress / config.js View on Github external
const documentsMetaData = require('../meta-tree.json');
const generateSidebar = require('../../src/generate-sidebar.js');
const urlMatchers = require('../../src/url-matchers.js');

const {
  chain,
  compose,
  find,
  pipe,
  prop,
  map,
  match,
} = require('sanctuary');

const getDropboxDocumentLocation = pipe([
  match(/paper\.dropbox\.com\/doc\/.+--\S{26}-(\w{21})/),
  chain(match => match.groups[0]),
  chain(urlId => find (doc => doc.id === urlId) (documentsMetaData)),
  map(compose (path.parse) (prop('location'))),
]);

module.exports = {
  title: 'Playbook',
  themeConfig: {
    sidebar: generateSidebar(documentsMetaData),
  },
  extendMarkdown: markdown => {
    markdown.use(markdownItForInline, 'internal-link', 'link_open', (tokens, index) => {
      const token = tokens[index];

      pipe([
        getDropboxDocumentLocation,
github voorhoede / playbook / src / url-matchers.js View on Github external
'use strict';

const { chain, match, pipe } = require('sanctuary');

const getYoutubeUrlId = pipe([
  match(/^https:\/\/w*\.*youtube\.com\/watch\?v=(\w{11})/),
  chain(match => match.groups[0]),
]);

const getYoutubePlaylistUrlId = pipe([
  match(/^https:\/\/w*\.*youtube\.com\/playlist\?list=([\w\d-]+)/),
  chain(match => match.groups[0]),
]);

module.exports = {
  getYoutubeUrlId,
  getYoutubePlaylistUrlId,
};
github raine / replem / lib / index.js View on Github external
if (overlaps(['-v', '--verbose'], process.argv))
  require('debug').enable('replem');

const debug = require('debug')('replem');

const capitalize = (str) => concat(toUpper(head(str)), tail(str));
const pascalCase = pipe(camelCase, capitalize);
const isUpper = (c) => toUpper(c) === c;
const isCapitalized = pipe(head, isUpper);
const pkgNameAsVar = ifElse(isCapitalized, pascalCase, camelCase);

const ALIAS  = /:([^!]+)/;
const EXTEND = /!$/;
const parseAlias = pipe(
  S.match(ALIAS), chain(nth(1)));
const parseExtend = pipe(
  S.match(EXTEND), map(T));
const rm = replace(__, '');
const cleanArg = pipe(...map(rm, [ EXTEND, ALIAS ]));
const orEmpty = S.fromMaybe({});

const parsePositionalArg = (arg) => {
  const cleaned = cleanArg(arg);
  return mergeAll([
    orEmpty(map(objOf('alias'),  parseAlias(arg))),
    orEmpty(map(objOf('extend'), parseExtend(arg))),
    { npa: npa(cleaned) }
  ]);
};

const contextForPkg = curry((_require, obj) => {
github raine / replem / lib / index.js View on Github external
require('debug').enable('replem');

const debug = require('debug')('replem');

const capitalize = (str) => concat(toUpper(head(str)), tail(str));
const pascalCase = pipe(camelCase, capitalize);
const isUpper = (c) => toUpper(c) === c;
const isCapitalized = pipe(head, isUpper);
const pkgNameAsVar = ifElse(isCapitalized, pascalCase, camelCase);

const ALIAS  = /:([^!]+)/;
const EXTEND = /!$/;
const parseAlias = pipe(
  S.match(ALIAS), chain(nth(1)));
const parseExtend = pipe(
  S.match(EXTEND), map(T));
const rm = replace(__, '');
const cleanArg = pipe(...map(rm, [ EXTEND, ALIAS ]));
const orEmpty = S.fromMaybe({});

const parsePositionalArg = (arg) => {
  const cleaned = cleanArg(arg);
  return mergeAll([
    orEmpty(map(objOf('alias'),  parseAlias(arg))),
    orEmpty(map(objOf('extend'), parseExtend(arg))),
    { npa: npa(cleaned) }
  ]);
};

const contextForPkg = curry((_require, obj) => {
  const module = _require(obj.name);
  return merge(