MCPcopy Create free account
hub / github.com/breck7/scroll / constructor

Method constructor

external/.tableSearch.js:2–35  ·  view source on GitHub ↗
(
    patchInput = "",
    grammar = {
      rowDelimiter: "&",
      columnDelimiter: "=",
      encodedRowDelimiter: "%2E%2E%2E",
      encodedColumnDelimiter: "%7E"
    }
  )

Source from the content-addressed store, hash-verified

1class Patch {
2 constructor(
3 patchInput = "",
4 grammar = {
5 rowDelimiter: "&",
6 columnDelimiter: "=",
7 encodedRowDelimiter: "%2E%2E%2E",
8 encodedColumnDelimiter: "%7E"
9 }
10 ) {
11 // The pipeline of encodings. Operations will be run in order for encoding (and reveresed for decoding).
12 this.encoders = [
13 {
14 encode: str => encodeURIComponent(str),
15 decode: str => decodeURIComponent(str)
16 },
17 {
18 encode: str => this.replaceAll(str, this.grammar.columnDelimiter, this.grammar.encodedColumnDelimiter),
19 decode: str => this.replaceAll(str, this.grammar.encodedColumnDelimiter, this.grammar.columnDelimiter)
20 },
21 {
22 encode: str => this.replaceAll(str, this.grammar.rowDelimiter, this.grammar.encodedRowDelimiter),
23 decode: str => this.replaceAll(str, this.grammar.encodedRowDelimiter, this.grammar.rowDelimiter)
24 },
25 {
26 // Turn "%20" into "+" for prettier urls.
27 encode: str => str.replace(/\%20/g, "+"),
28 decode: str => str.replace(/\+/g, "%20")
29 }
30 ]
31 this.grammar = grammar
32 if (typeof patchInput === "string") this.uriEncodedString = patchInput
33 else if (Array.isArray(patchInput)) this.uriEncodedString = this.arrayToEncodedString(patchInput)
34 else this.uriEncodedString = this.objectToEncodedString(patchInput)
35 }
36 replaceAll(str, search, replace) {
37 return str.split(search).join(replace)
38 }

Callers

nothing calls this directly

Calls 4

replaceAllMethod · 0.95
arrayToEncodedStringMethod · 0.95
objectToEncodedStringMethod · 0.95
replaceMethod · 0.80

Tested by

no test coverage detected