@punks/backend-core 0.0.76 → 0.0.78
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 +207 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/utils/encoding.d.ts +5 -0
- package/dist/cjs/types/utils/html.d.ts +61 -0
- package/dist/cjs/types/utils/index.d.ts +2 -0
- package/dist/cjs/types/utils/uid.d.ts +1 -0
- package/dist/esm/index.js +202 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/utils/encoding.d.ts +5 -0
- package/dist/esm/types/utils/html.d.ts +61 -0
- package/dist/esm/types/utils/index.d.ts +2 -0
- package/dist/esm/types/utils/uid.d.ts +1 -0
- package/dist/index.d.ts +15 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -440,6 +440,200 @@ const jsonSerialize = (obj, options) => {
|
|
|
440
440
|
return JSON.stringify(obj, replacer, spaces);
|
|
441
441
|
};
|
|
442
442
|
|
|
443
|
+
const encodeUtf8 = (value) => Buffer.from(value).toString("utf-8");
|
|
444
|
+
const decodeUtf8 = (value) => Buffer.from(value, "utf-8");
|
|
445
|
+
const encodeBase64 = (value) => Buffer.from(value).toString("base64");
|
|
446
|
+
const decodeBase64 = (value) => Buffer.from(value, "base64");
|
|
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
|
+
|
|
443
637
|
const maskVariable = (value, unmaskedLength = 4) => value
|
|
444
638
|
? value.substring(0, unmaskedLength).concat(Array.from(value.substring(unmaskedLength))
|
|
445
639
|
.map(() => "*")
|
|
@@ -506,6 +700,13 @@ const newUuid = () => {
|
|
|
506
700
|
return v.toString(16);
|
|
507
701
|
});
|
|
508
702
|
};
|
|
703
|
+
const generateHash = (length) => {
|
|
704
|
+
let text = "";
|
|
705
|
+
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
706
|
+
for (let i = 0; i < length; i++)
|
|
707
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
708
|
+
return text;
|
|
709
|
+
};
|
|
509
710
|
|
|
510
711
|
function serializeQueryString(obj) {
|
|
511
712
|
let queryString = "";
|
|
@@ -31290,9 +31491,13 @@ exports.camelToSnakeCase = camelToSnakeCase;
|
|
|
31290
31491
|
exports.createDayPath = createDayPath;
|
|
31291
31492
|
exports.csvBuild = csvBuild;
|
|
31292
31493
|
exports.csvParse = csvParse;
|
|
31494
|
+
exports.decodeBase64 = decodeBase64;
|
|
31495
|
+
exports.decodeUtf8 = decodeUtf8;
|
|
31293
31496
|
exports.deserializeQueryString = deserializeQueryString;
|
|
31294
31497
|
exports.distinct = distinct;
|
|
31295
31498
|
exports.distinctElements = distinctElements;
|
|
31499
|
+
exports.encodeBase64 = encodeBase64;
|
|
31500
|
+
exports.encodeUtf8 = encodeUtf8;
|
|
31296
31501
|
exports.ensureDirectory = ensureDirectory;
|
|
31297
31502
|
exports.ensureStartSlash = ensureStartSlash;
|
|
31298
31503
|
exports.ensureTailingSlash = ensureTailingSlash;
|
|
@@ -31301,6 +31506,7 @@ exports.excelParse = excelParse;
|
|
|
31301
31506
|
exports.first = first;
|
|
31302
31507
|
exports.flatten = flatten;
|
|
31303
31508
|
exports.floorDateToSecond = floorDateToSecond;
|
|
31509
|
+
exports.generateHash = generateHash;
|
|
31304
31510
|
exports.getDirectoryFilePaths = getDirectoryFilePaths;
|
|
31305
31511
|
exports.getDirectoryPath = getDirectoryPath;
|
|
31306
31512
|
exports.getQueryParameter = getQueryParameter;
|
|
@@ -31332,6 +31538,7 @@ exports.serializeQueryString = serializeQueryString;
|
|
|
31332
31538
|
exports.sleep = sleep;
|
|
31333
31539
|
exports.sort = sort;
|
|
31334
31540
|
exports.splitPath = splitPath;
|
|
31541
|
+
exports.stripTags = stripTags;
|
|
31335
31542
|
exports.subArrays = subArrays;
|
|
31336
31543
|
exports.subtractTime = subtractTime;
|
|
31337
31544
|
exports.testInternetConnection = testInternetConnection;
|