How to use the regenerate function in regenerate

To help you get started, we’ve selected a few regenerate 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 elastic / kibana / packages / kbn-test / src / mocha / xml.ts View on Github external
*
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

// @ts-ignore
import regenerate from 'regenerate';
import stripAnsi from 'strip-ansi';

// create a regular expression using regenerate() that selects any character that is explicitly allowed by https://www.w3.org/TR/xml/#NT-Char
const validXmlCharsRE = new RegExp(
  `(?:${regenerate()
    .add(0x9, 0xa, 0xd)
    .addRange(0x20, 0xd7ff)
    .addRange(0xe000, 0xfffd)
    .addRange(0x10000, 0x10ffff)
    .toString()})*`,
  'g'
);

export function escapeCdata(input: string) {
  const match = stripAnsi(input).match(validXmlCharsRE) || [];
  return match.join('');
}

regenerate

Generate JavaScript-compatible regular expressions based on a given set of Unicode symbols or code points.

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis