@punks/backend-core 0.0.77 → 0.0.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +190 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/utils/html.d.ts +61 -0
- package/dist/cjs/types/utils/index.d.ts +2 -1
- package/dist/esm/index.js +190 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/utils/html.d.ts +61 -0
- package/dist/esm/types/utils/index.d.ts +2 -1
- package/dist/index.d.ts +9 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -445,6 +445,195 @@ const decodeUtf8 = (value) => Buffer.from(value, "utf-8");
|
|
|
445
445
|
const encodeBase64 = (value) => Buffer.from(value).toString("base64");
|
|
446
446
|
const decodeBase64 = (value) => Buffer.from(value, "base64");
|
|
447
447
|
|
|
448
|
+
// borrowed from https://github.com/ericnorris/striptags
|
|
449
|
+
function isSpace(character) {
|
|
450
|
+
return (character == " " ||
|
|
451
|
+
character == "\n" ||
|
|
452
|
+
character == "\r" ||
|
|
453
|
+
character == "\t");
|
|
454
|
+
}
|
|
455
|
+
function isQuote(character) {
|
|
456
|
+
return character == '"' || character == "'";
|
|
457
|
+
}
|
|
458
|
+
const TAG_START = "<";
|
|
459
|
+
const TAG_END = ">";
|
|
460
|
+
const ENCODED_TAG_START = "<";
|
|
461
|
+
const ENCODED_TAG_END = ">";
|
|
462
|
+
class InPlaintextState {
|
|
463
|
+
constructor(options) {
|
|
464
|
+
this.options = options;
|
|
465
|
+
}
|
|
466
|
+
consume(character, transition) {
|
|
467
|
+
if (character == TAG_START) {
|
|
468
|
+
transition(new InTagNameState(this.options));
|
|
469
|
+
return "";
|
|
470
|
+
}
|
|
471
|
+
else if (character == TAG_END &&
|
|
472
|
+
this.options.encodePlaintextTagDelimiters) {
|
|
473
|
+
return ENCODED_TAG_END;
|
|
474
|
+
}
|
|
475
|
+
return character;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
class InTagNameState {
|
|
479
|
+
constructor(options) {
|
|
480
|
+
this.options = options;
|
|
481
|
+
this.nameBuffer = "";
|
|
482
|
+
this.isClosingTag = false;
|
|
483
|
+
}
|
|
484
|
+
consume(character, transition) {
|
|
485
|
+
if (this.nameBuffer.length == 0) {
|
|
486
|
+
if (isSpace(character)) {
|
|
487
|
+
transition(new InPlaintextState(this.options));
|
|
488
|
+
return ((this.options.encodePlaintextTagDelimiters
|
|
489
|
+
? ENCODED_TAG_START
|
|
490
|
+
: "<") + character);
|
|
491
|
+
}
|
|
492
|
+
if (character == "/") {
|
|
493
|
+
this.isClosingTag = true;
|
|
494
|
+
return "";
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (isSpace(character)) {
|
|
498
|
+
if (this.isNameBufferAnAllowedTag()) {
|
|
499
|
+
transition(new InTagState(0 /* TagMode.Allowed */, this.options));
|
|
500
|
+
return (TAG_START +
|
|
501
|
+
(this.isClosingTag ? "/" : "") +
|
|
502
|
+
this.nameBuffer +
|
|
503
|
+
character);
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
transition(new InTagState(1 /* TagMode.Disallowed */, this.options));
|
|
507
|
+
return this.options.tagReplacementText;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
if (character == TAG_START) {
|
|
511
|
+
this.nameBuffer += ENCODED_TAG_START;
|
|
512
|
+
return "";
|
|
513
|
+
}
|
|
514
|
+
if (character == TAG_END) {
|
|
515
|
+
transition(new InPlaintextState(this.options));
|
|
516
|
+
if (this.isNameBufferAnAllowedTag()) {
|
|
517
|
+
return (TAG_START +
|
|
518
|
+
(this.isClosingTag ? "/" : "") +
|
|
519
|
+
this.nameBuffer +
|
|
520
|
+
character);
|
|
521
|
+
}
|
|
522
|
+
else {
|
|
523
|
+
return this.options.tagReplacementText;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (character == "-" && this.nameBuffer == "!-") {
|
|
527
|
+
transition(new InCommentState(this.options));
|
|
528
|
+
return "";
|
|
529
|
+
}
|
|
530
|
+
this.nameBuffer += character;
|
|
531
|
+
return "";
|
|
532
|
+
}
|
|
533
|
+
isNameBufferAnAllowedTag() {
|
|
534
|
+
const tagName = this.nameBuffer.toLowerCase();
|
|
535
|
+
if (this.options.allowedTags) {
|
|
536
|
+
return this.options.allowedTags.has(tagName);
|
|
537
|
+
}
|
|
538
|
+
else if (this.options.disallowedTags) {
|
|
539
|
+
return !this.options.disallowedTags.has(tagName);
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
class InTagState {
|
|
547
|
+
constructor(mode, options) {
|
|
548
|
+
this.mode = mode;
|
|
549
|
+
this.options = options;
|
|
550
|
+
}
|
|
551
|
+
consume(character, transition) {
|
|
552
|
+
if (character == TAG_END) {
|
|
553
|
+
transition(new InPlaintextState(this.options));
|
|
554
|
+
}
|
|
555
|
+
else if (isQuote(character)) {
|
|
556
|
+
transition(new InQuotedStringInTagState(this.mode, character, this.options));
|
|
557
|
+
}
|
|
558
|
+
if (this.mode == 1 /* TagMode.Disallowed */) {
|
|
559
|
+
return "";
|
|
560
|
+
}
|
|
561
|
+
if (character == TAG_START) {
|
|
562
|
+
return ENCODED_TAG_START;
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
return character;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
class InQuotedStringInTagState {
|
|
570
|
+
constructor(mode, quoteCharacter, options) {
|
|
571
|
+
this.mode = mode;
|
|
572
|
+
this.quoteCharacter = quoteCharacter;
|
|
573
|
+
this.options = options;
|
|
574
|
+
}
|
|
575
|
+
consume(character, transition) {
|
|
576
|
+
if (character == this.quoteCharacter) {
|
|
577
|
+
transition(new InTagState(this.mode, this.options));
|
|
578
|
+
}
|
|
579
|
+
if (this.mode == 1 /* TagMode.Disallowed */) {
|
|
580
|
+
return "";
|
|
581
|
+
}
|
|
582
|
+
if (character == TAG_START) {
|
|
583
|
+
return ENCODED_TAG_START;
|
|
584
|
+
}
|
|
585
|
+
else if (character == TAG_END) {
|
|
586
|
+
return ENCODED_TAG_END;
|
|
587
|
+
}
|
|
588
|
+
else {
|
|
589
|
+
return character;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
class InCommentState {
|
|
594
|
+
constructor(options) {
|
|
595
|
+
this.options = options;
|
|
596
|
+
this.consecutiveHyphens = 0;
|
|
597
|
+
}
|
|
598
|
+
consume(character, transition) {
|
|
599
|
+
if (character == ">" && this.consecutiveHyphens >= 2) {
|
|
600
|
+
transition(new InPlaintextState(this.options));
|
|
601
|
+
}
|
|
602
|
+
else if (character == "-") {
|
|
603
|
+
this.consecutiveHyphens++;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
this.consecutiveHyphens = 0;
|
|
607
|
+
}
|
|
608
|
+
return "";
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const DefaultStateMachineOptions = {
|
|
612
|
+
tagReplacementText: "",
|
|
613
|
+
encodePlaintextTagDelimiters: true,
|
|
614
|
+
};
|
|
615
|
+
class StateMachine {
|
|
616
|
+
constructor(partialOptions = {}) {
|
|
617
|
+
this.state = new InPlaintextState({
|
|
618
|
+
...DefaultStateMachineOptions,
|
|
619
|
+
...partialOptions,
|
|
620
|
+
});
|
|
621
|
+
this.transitionFunction = ((next) => {
|
|
622
|
+
this.state = next;
|
|
623
|
+
}).bind(this);
|
|
624
|
+
}
|
|
625
|
+
consume(text) {
|
|
626
|
+
let outputBuffer = "";
|
|
627
|
+
for (const character of text) {
|
|
628
|
+
outputBuffer += this.state.consume(character, this.transitionFunction);
|
|
629
|
+
}
|
|
630
|
+
return outputBuffer;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
function stripTags(text, options = {}) {
|
|
634
|
+
return new StateMachine(options).consume(text);
|
|
635
|
+
}
|
|
636
|
+
|
|
448
637
|
const maskVariable = (value, unmaskedLength = 4) => value
|
|
449
638
|
? value.substring(0, unmaskedLength).concat(Array.from(value.substring(unmaskedLength))
|
|
450
639
|
.map(() => "*")
|
|
@@ -31349,6 +31538,7 @@ exports.serializeQueryString = serializeQueryString;
|
|
|
31349
31538
|
exports.sleep = sleep;
|
|
31350
31539
|
exports.sort = sort;
|
|
31351
31540
|
exports.splitPath = splitPath;
|
|
31541
|
+
exports.stripTags = stripTags;
|
|
31352
31542
|
exports.subArrays = subArrays;
|
|
31353
31543
|
exports.subtractTime = subtractTime;
|
|
31354
31544
|
exports.testInternetConnection = testInternetConnection;
|