docs(regexp): update module example to get full jsr score (#4796)

This commit is contained in:
Satya Rohith 2024-05-21 22:13:25 +05:30 committed by GitHub
parent 78614676a1
commit 376f4da0de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -1,6 +1,24 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible. // This module is browser compatible.
/**
* This module contains functions to escape strings for use in regular expressions.
*
* @example
* ```ts
* import { escape } from "@std/regexp/escape";
* import { assertEquals, assertMatch, assertNotMatch } from "@std/assert";
*
* const re = new RegExp(`^${escape(".")}$`, "u");
*
* assertEquals("^\\.$", re.source);
* assertMatch(".", re);
* assertNotMatch("a", re);
* ```
*
* @module
*/
// // For future forward-compatibility with regexp `v` flag, reservedCharMap is // // For future forward-compatibility with regexp `v` flag, reservedCharMap is
// // autogenerated from the ClassSetReservedDoublePunctuator, // // autogenerated from the ClassSetReservedDoublePunctuator,
// // ClassSetSyntaxCharacter, and ClassSetReservedPunctuator categories in the // // ClassSetSyntaxCharacter, and ClassSetReservedPunctuator categories in the
@ -27,7 +45,7 @@ const reservedCharMap = {
"&": "\\x26", "&": "\\x26",
"!": "\\x21", "!": "\\x21",
"#": "\\x23", "#": "\\x23",
"$": "\\$", $: "\\$",
"%": "\\x25", "%": "\\x25",
"*": "\\*", "*": "\\*",
"+": "\\+", "+": "\\+",

View File

@ -7,6 +7,18 @@
* such as escaping text for interpolation into a regexp. * such as escaping text for interpolation into a regexp.
* *
* @module * @module
*
* @example
* ```ts
* import { escape } from "@std/regexp";
* import { assertEquals, assertMatch, assertNotMatch } from "@std/assert";
*
* const re = new RegExp(`^${escape(".")}$`, "u");
*
* assertEquals("^\\.$", re.source);
* assertMatch(".", re);
* assertNotMatch("a", re);
* ```
*/ */
export * from "./escape.ts"; export * from "./escape.ts";