Package detail

@a-la/markers

a-la180MIT1.3.0

A set of service markers used by alamode, e.g., to cut and paste comments.

markers, a-la

readme

@a-la/markers

npm version

@a-la/markers is a set of service markers used by alamode, e.g., to cut and paste comments.

yarn add -E @a-la/markers

Table Of Contents

API

The package is available by importing its default function:

import makeRules from '@a-la/markers'

makeRules(
  rules?: !Array<!_restream.Rule>,
): !Array<!_restream.Rule>

This function will surround the rules with cut and paste rules for markers, to exclude from transforms:

  • strings
  • template literals
  • block comments
  • inline comments
  • regexes

[!] Important The current implementation does not support the following:

// the // will be considered to be a comment and break the process
// because the string literal will not be complete without the closing `
const noLink = `https://${host}/test`
export { noLink }
/* yarn example/ */
import makeRules from '@a-la/markers'

const { rules, markers } = makeRules([
  {
    re: 'ALAMODE_RULE',
    replacement(match) {
      return match
    },
  },
])

console.log('\nRules:')
console.log(rules)

console.log('\nMarkers:')
console.log(markers)
Rules:
[ { re: /\\[\\`'"\/]/g, replacement: [Function: replacement] },
  { re: /\/\*(?:[\s\S]+?)\*\//g,
    replacement: [Function: replacement] },
  { re: /\/\/(.+)/gm, replacement: [Function: replacement] },
  { re: /(["'])(.*?)\1/gm, replacement: [Function: replacement] },
  { re: /\[(.*?)\]/gm, replacement: [Function: replacement] },
  { re: /\/(.+?)\//gm, replacement: [Function: replacement] },
  { re: /`([\s\S]*?)`/gm, replacement: [Function: replacement] },
  { re: 'ALAMODE_RULE', replacement: [Function: replacement] },
  { re: /%%_RESTREAM_LITERALS_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] },
  { re: /%%_RESTREAM_REGEXES_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] },
  { re: /%%_RESTREAM_REGEXGROUPS_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] },
  { re: /%%_RESTREAM_STRINGS_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] },
  { re: /%%_RESTREAM_INLINECOMMENTS_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] },
  { re: /%%_RESTREAM_COMMENTS_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] },
  { re: /%%_RESTREAM_ESCAPES_REPLACEMENT_(\d+)_%%/g,
    replacement: [Function: replacement] } ]

Markers:
{ literals: 
   { name: 'literals',
     re: /`([\s\S]*?)`/gm,
     regExp: /%%_RESTREAM_LITERALS_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 },
  strings: 
   { name: 'strings',
     re: /(["'])(.*?)\1/gm,
     regExp: /%%_RESTREAM_STRINGS_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 },
  comments: 
   { name: 'comments',
     re: /\/\*(?:[\s\S]+?)\*\//g,
     regExp: /%%_RESTREAM_COMMENTS_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 },
  inlineComments: 
   { name: 'inlineComments',
     re: /\/\/(.+)/gm,
     regExp: /%%_RESTREAM_INLINECOMMENTS_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 },
  escapes: 
   { name: 'escapes',
     re: /\\[\\`'"\/]/g,
     regExp: /%%_RESTREAM_ESCAPES_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 },
  regexes: 
   { name: 'regexes',
     re: /\/(.+?)\//gm,
     regExp: /%%_RESTREAM_REGEXES_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 },
  regexGroups: 
   { name: 'regexGroups',
     re: /\[(.*?)\]/gm,
     regExp: /%%_RESTREAM_REGEXGROUPS_REPLACEMENT_(\d+)_%%/g,
     getReplacement: [Function: getDefaultReplacement],
     map: {},
     lastIndex: 0 } }

Copyright

Art Deco © Art Deco for À La Mode 2019 Tech Nation Visa Tech Nation Visa Sucks

changelog

12 May 2019

1.3.0

  • [feature] Add the stop rule for debugging.

24 April 2019

1.2.0

  • [api] Export inlineCommentsRe and commentsRe regexes.
  • [fix] Apply a patch to remove type warning:
      mr.map(makePasteRule) // warning
      mr.map(m => makePasteRule(m)) // fix

22 April 2019

1.1.0

  • [package] Publish src as a module.
  • [deps] Update and unlock dependencies.

1 September 2018

1.0.3

  • [fix] Return additional markers, including regexes, etc.

1.0.2

  • [fix] Ensure correct order to match strings before regexes.
  • [test] Install snapshot-context.

1.0.1

  • [feature] Mark escaped characters before all, and cut & paste regexes.

1.0.0