question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement transform module

See original GitHub issue

The transform method is a wrapper on top of “parse-traverse-generate” tool chain. Getting a regular expression string, and the nodes handler, transform should return a new (transformed) regular expression.

The issue depend on ~issue #5~.

An example of manual traversal, and code generation is shown in the Using traversal API section. A transform version of it should look like:

const regexpTree = require('regexp-tree');

const re = regexpTree.transform('/[a-z]{1,}/', {
  // Handle "Quantifier" node type,
  // transforming `{1,}` quantifier to `+`.
  onQuantifier(node) {
    // {1,} -> +
    if (
      node.type === 'Range' &&
      node.from === 1 &&
      !node.to
    ) {
      node.type = '+';
      delete node.from;
    }
  },
});

console.log(re); // '/[a-z]+/'

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mathiasbynenscommented, Apr 2, 2017

My vote goes to option 4.

1reaction
shvaikaleshcommented, Apr 2, 2017

What should be return value of transform?

  1. Receives string, returns string. Receives RegExp, returns RegExp.
  • It is not cool when function returns values of different types (hey, strpos).
  1. Always return string.
  • It is a bit awkward to make RegExp from string.
  1. Always return RegExp.
  • new RegExp may fail in some envs because of unsupported syntax.
  1. Return some Result object with toString and toRegExp.

EDIT: added downside of 3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to implement transformation modules | Memgraph Docs
The prerequisite of connecting Memgraph to a Pulsar stream is to have a transformation module that can produce Cypher queries based on the...
Read more >
Transforms - 3D Slicer documentation - Read the Docs
This module is used for creating, editing, and visualization of spatial transformations. Transformations are stored in transform nodes and define position, ...
Read more >
Module: transform — skimage v0.19.2 docs
Use an integral image to integrate over a given window. Parameters. iindarray. Integral image. startList of tuples, each tuple of length equal to...
Read more >
CSS Transforms Module Level 1 - W3C
1 Introduction. 1.1 Module Interactions; 1.2 CSS Values. 2 Terminology; 3 The Transform Rendering Model; 4 The transform Property.
Read more >
Get Started with TensorFlow Transform | TFX
Transform and how to use them. It will: ... Show the Apache Beam implementation used to transform data by converting the ... <module...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found