MCPcopy
hub / github.com/ether/etherpad / Builder

Class Builder

src/static/js/Builder.ts:23–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21 * @returns {Builder}
22 */
23export class Builder {
24 private readonly oldLen: number;
25 private assem: SmartOpAssembler;
26 private readonly o: Op;
27 private charBank: StringAssembler;
28
29 constructor(oldLen: number) {
30 this.oldLen = oldLen
31 this.assem = new SmartOpAssembler()
32 this.o = new Op()
33 this.charBank = new StringAssembler()
34 }
35
36 /**
37 * @param {number} N - Number of characters to keep.
38 * @param {number} L - Number of newlines among the `N` characters. If positive, the last
39 * character must be a newline.
40 * @param {(string|Attribute[])} attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...'
41 * (no pool needed in latter case).
42 * @param {?AttributePool.ts} pool - Attribute pool, only required if `attribs` is a list of
43 * attribute key, value pairs.
44 * @returns {Builder} this
45 */
46 keep = (N: number, L?: number, attribs?: string|Attribute[], pool?: AttributePool): Builder => {
47 this.o.opcode = '=';
48 this.o.attribs = typeof attribs === 'string'
49 ? attribs : new AttributeMap(pool).update(attribs || []).toString();
50 this.o.chars = N;
51 this.o.lines = (L || 0);
52 this.assem.append(this.o);
53 return this;
54 }
55
56
57 /**
58 * @param {string} text - Text to keep.
59 * @param {(string|Attribute[])} attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...'
60 * (no pool needed in latter case).
61 * @param {?AttributePool.ts} pool - Attribute pool, only required if `attribs` is a list of
62 * attribute key, value pairs.
63 * @returns {Builder} this
64 */
65 keepText= (text: string, attribs?: string|Attribute[], pool?: AttributePool): Builder=> {
66 for (const op of opsFromText('=', text, attribs, pool)) this.assem.append(op);
67 return this;
68 }
69
70
71 /**
72 * @param {string} text - Text to insert.
73 * @param {(string|Attribute[])} attribs - Either [[key1,value1],[key2,value2],...] or '*0*1...'
74 * (no pool needed in latter case).
75 * @param {?AttributePool.ts} pool - Attribute pool, only required if `attribs` is a list of
76 * attribute key, value pairs.
77 * @returns {Builder} this
78 */
79 insert= (text: string, attribs: string | Attribute[] | undefined, pool?: AttributePool | null | undefined): Builder => {
80 for (const op of opsFromText('+', text, attribs, pool)) this.assem.append(op);

Callers

nothing calls this directly

Calls 4

packFunction · 0.90
updateMethod · 0.80
appendMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected