@datawheel/bespoke 0.1.12 → 0.1.13
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/index.js +17 -9
- package/dist/server.js +76 -75
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -306,12 +306,12 @@ var init_stats = __esm({
|
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
|
-
var
|
|
309
|
+
var libraries;
|
|
310
310
|
var init_libs = __esm({
|
|
311
311
|
"libs/libs.ts"() {
|
|
312
312
|
init_esm_shims();
|
|
313
313
|
init_stats();
|
|
314
|
-
|
|
314
|
+
libraries = {
|
|
315
315
|
d3: {
|
|
316
316
|
...d3Array,
|
|
317
317
|
...d3Collection,
|
|
@@ -329,7 +329,6 @@ var init_libs = __esm({
|
|
|
329
329
|
},
|
|
330
330
|
stats: stats_default
|
|
331
331
|
};
|
|
332
|
-
libs_default = libs;
|
|
333
332
|
}
|
|
334
333
|
});
|
|
335
334
|
function mortarEval(varInnerName, varOuterValue, logic, formatterFunctions, attributes = void 0, blockContext) {
|
|
@@ -353,10 +352,10 @@ function mortarEval(varInnerName, varOuterValue, logic, formatterFunctions, attr
|
|
|
353
352
|
let output;
|
|
354
353
|
if (attributes) {
|
|
355
354
|
const fn = new Function(varInnerName, "console", "libs", "formatters", "locale", "variables", logic);
|
|
356
|
-
output = fn(varOuterValue, pConsole,
|
|
355
|
+
output = fn(varOuterValue, pConsole, libraries, formatterFunctions, locale, attributes);
|
|
357
356
|
} else {
|
|
358
357
|
const fn = new Function(varInnerName, "console", "libs", "formatters", "locale", logic);
|
|
359
|
-
output = fn(varOuterValue, pConsole,
|
|
358
|
+
output = fn(varOuterValue, pConsole, libraries, formatterFunctions, locale);
|
|
360
359
|
}
|
|
361
360
|
if (typeof output === "object" && Object.keys(output).length > 0) {
|
|
362
361
|
Object.assign(vars, output);
|
|
@@ -591,7 +590,7 @@ function varSwap(sourceString, formatterFunctions, blockContext, passive = false
|
|
|
591
590
|
return passive ? match2 : "N/A";
|
|
592
591
|
}
|
|
593
592
|
try {
|
|
594
|
-
return formatter(value,
|
|
593
|
+
return formatter(value, libraries, formatterFunctions);
|
|
595
594
|
} catch (err) {
|
|
596
595
|
console.error(
|
|
597
596
|
`Error using formatter ${formatter.name}
|
|
@@ -1077,7 +1076,7 @@ var init_runConsumers = __esm({
|
|
|
1077
1076
|
}
|
|
1078
1077
|
};
|
|
1079
1078
|
const crawlDown = async (bid2, cascader = false) => {
|
|
1080
|
-
if (cascader
|
|
1079
|
+
if (cascader) {
|
|
1081
1080
|
variablesById[bid2] = {};
|
|
1082
1081
|
statusById[bid2] = { hiddenByCascade: cascader };
|
|
1083
1082
|
for (let i = 0; i < blocks[bid2].consumers.length; i += 1) {
|
|
@@ -1311,7 +1310,7 @@ var init_FUNC = __esm({
|
|
|
1311
1310
|
setVariables: actions.onSetVariables ? actions.onSetVariables : (d) => d,
|
|
1312
1311
|
openModal: actions.onOpenModal ? actions.onOpenModal : (d) => d,
|
|
1313
1312
|
formatters,
|
|
1314
|
-
libs:
|
|
1313
|
+
libs: libraries,
|
|
1315
1314
|
locale
|
|
1316
1315
|
};
|
|
1317
1316
|
function parseFunction(obj) {
|
|
@@ -1363,7 +1362,16 @@ var init_lib2 = __esm({
|
|
|
1363
1362
|
init_FUNC();
|
|
1364
1363
|
init_getLocales();
|
|
1365
1364
|
({ localeDefault: localeDefault4 } = getLocales_default());
|
|
1366
|
-
blockSchema = new schema.Entity("block" /* BLOCKS
|
|
1365
|
+
blockSchema = new schema.Entity("block" /* BLOCKS */, {}, {
|
|
1366
|
+
mergeStrategy(a, b) {
|
|
1367
|
+
if (b.block_input)
|
|
1368
|
+
return a || {};
|
|
1369
|
+
return {
|
|
1370
|
+
...a,
|
|
1371
|
+
...b
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
});
|
|
1367
1375
|
blockSchema.define({
|
|
1368
1376
|
consumers: [blockSchema],
|
|
1369
1377
|
inputs: [blockSchema]
|
package/dist/server.js
CHANGED
|
@@ -39,7 +39,6 @@ var BlockModel = class extends Model {
|
|
|
39
39
|
}
|
|
40
40
|
toJSON() {
|
|
41
41
|
const attributes = this.get({ plain: true });
|
|
42
|
-
delete attributes.block_input;
|
|
43
42
|
const { inputs = [], consumers = [], contentByLocale = [] } = this;
|
|
44
43
|
return {
|
|
45
44
|
...attributes,
|
|
@@ -362,7 +361,7 @@ var stats_default = {
|
|
|
362
361
|
};
|
|
363
362
|
|
|
364
363
|
// libs/libs.ts
|
|
365
|
-
var
|
|
364
|
+
var libraries = {
|
|
366
365
|
d3: {
|
|
367
366
|
...d3Array,
|
|
368
367
|
...d3Collection,
|
|
@@ -382,7 +381,7 @@ var libs = {
|
|
|
382
381
|
};
|
|
383
382
|
var declaredFormatters = {};
|
|
384
383
|
function declareFormatter(manifest) {
|
|
385
|
-
const func = manifest.logicFactory(
|
|
384
|
+
const func = manifest.logicFactory(libraries);
|
|
386
385
|
declaredFormatters[manifest.name] = {
|
|
387
386
|
description: manifest.description,
|
|
388
387
|
inputType: manifest.inputType,
|
|
@@ -474,8 +473,8 @@ __export(formatters_exports, {
|
|
|
474
473
|
var abbreviate_default = declareFormatter({
|
|
475
474
|
name: "abbreviate",
|
|
476
475
|
description: "Abbreviates a number into a smaller more human-readable number.",
|
|
477
|
-
logicFactory(
|
|
478
|
-
return (n) =>
|
|
476
|
+
logicFactory(libs) {
|
|
477
|
+
return (n) => libs.d3plus.formatAbbreviate(n);
|
|
479
478
|
},
|
|
480
479
|
inputType: "number",
|
|
481
480
|
testValue: "123456",
|
|
@@ -486,7 +485,7 @@ var abbreviate_default = declareFormatter({
|
|
|
486
485
|
var abs_default = declareFormatter({
|
|
487
486
|
name: "abs",
|
|
488
487
|
description: "Simple Absolute Value.",
|
|
489
|
-
logicFactory(
|
|
488
|
+
logicFactory(libs) {
|
|
490
489
|
return (n) => Math.abs(n);
|
|
491
490
|
},
|
|
492
491
|
inputType: "number",
|
|
@@ -532,8 +531,8 @@ var bucket_default = declareFormatter({
|
|
|
532
531
|
var commas_default = declareFormatter({
|
|
533
532
|
name: "commas",
|
|
534
533
|
description: "* Rounds to nearest whole number and adds commas.",
|
|
535
|
-
logicFactory(
|
|
536
|
-
return (n) =>
|
|
534
|
+
logicFactory(libs) {
|
|
535
|
+
return (n) => libs.d3.format(",")(Math.round(n));
|
|
537
536
|
},
|
|
538
537
|
inputType: "number",
|
|
539
538
|
testValue: "1234.6",
|
|
@@ -544,12 +543,12 @@ var commas_default = declareFormatter({
|
|
|
544
543
|
var date_default = declareFormatter({
|
|
545
544
|
name: "date",
|
|
546
545
|
description: "Formats a date into '%B %d, %Y' format.",
|
|
547
|
-
logicFactory(
|
|
546
|
+
logicFactory(libs) {
|
|
548
547
|
return (n) => {
|
|
549
548
|
if (typeof n === "string") {
|
|
550
|
-
n =
|
|
549
|
+
n = libs.d3plus.date(n);
|
|
551
550
|
}
|
|
552
|
-
return
|
|
551
|
+
return libs.d3.timeFormat("%B %d, %Y")(n);
|
|
553
552
|
};
|
|
554
553
|
},
|
|
555
554
|
inputType: "date",
|
|
@@ -559,12 +558,12 @@ var date_default = declareFormatter({
|
|
|
559
558
|
|
|
560
559
|
// libs/formatters/dollar.js
|
|
561
560
|
var dollar_default = declareFormatter({
|
|
562
|
-
name: "
|
|
561
|
+
name: "dollar",
|
|
563
562
|
description: "Adds a US dollar sign to the beginning of a String or Number.",
|
|
564
|
-
logicFactory(
|
|
563
|
+
logicFactory(libs) {
|
|
565
564
|
return (n) => {
|
|
566
565
|
if (typeof n === "number")
|
|
567
|
-
n =
|
|
566
|
+
n = libs.d3plus.formatAbbreviate(n);
|
|
568
567
|
return n.charAt(0) === "-" ? n.replace("-", "-$") : `$${n}`;
|
|
569
568
|
};
|
|
570
569
|
},
|
|
@@ -577,7 +576,7 @@ var dollar_default = declareFormatter({
|
|
|
577
576
|
var formatFieldName_default = declareFormatter({
|
|
578
577
|
name: "formatFieldName",
|
|
579
578
|
description: "Based on field name returns a string",
|
|
580
|
-
logicFactory(
|
|
579
|
+
logicFactory(libs) {
|
|
581
580
|
return (n) => {
|
|
582
581
|
if (n.contentType.toLowerCase() === "stat") {
|
|
583
582
|
if (n.field === "title")
|
|
@@ -609,7 +608,7 @@ var formatFieldName_default = declareFormatter({
|
|
|
609
608
|
var grewTo_default = declareFormatter({
|
|
610
609
|
name: "grewTo",
|
|
611
610
|
description: "Returns the text with grow direction: 'declined from', 'grew to' o 'stayed at'",
|
|
612
|
-
logicFactory(
|
|
611
|
+
logicFactory(libs) {
|
|
613
612
|
return (n) => n < 0 ? "declined from" : n > 0 ? "grew to" : "stayed at";
|
|
614
613
|
},
|
|
615
614
|
inputType: "number",
|
|
@@ -621,7 +620,7 @@ var grewTo_default = declareFormatter({
|
|
|
621
620
|
var grewWord_default = declareFormatter({
|
|
622
621
|
name: "grewWord",
|
|
623
622
|
description: "Returns either 'grew', 'declined', or 'stayed' depending on the provided number's sign.",
|
|
624
|
-
logicFactory(
|
|
623
|
+
logicFactory(libs) {
|
|
625
624
|
return (n) => n < 0 ? "declined" : n > 0 ? "grew" : "stayed";
|
|
626
625
|
},
|
|
627
626
|
inputType: "number",
|
|
@@ -633,7 +632,7 @@ var grewWord_default = declareFormatter({
|
|
|
633
632
|
var growing_default = declareFormatter({
|
|
634
633
|
name: "growing",
|
|
635
634
|
description: "Returns either 'declining', 'growing' depending on the provided number's sign.",
|
|
636
|
-
logicFactory(
|
|
635
|
+
logicFactory(libs) {
|
|
637
636
|
return (n) => n < 0 ? "declining" : "growing";
|
|
638
637
|
},
|
|
639
638
|
inputType: "number",
|
|
@@ -671,8 +670,8 @@ var growth_default = declareFormatter({
|
|
|
671
670
|
var growthPct_default = declareFormatter({
|
|
672
671
|
name: "growthPct",
|
|
673
672
|
description: "Abbreviates a growth value, turns it absolute, and adds a percent sign.",
|
|
674
|
-
logicFactory(
|
|
675
|
-
return (n) => `${
|
|
673
|
+
logicFactory(libs) {
|
|
674
|
+
return (n) => `${libs.d3plus.formatAbbreviate(Math.abs(n))}%`;
|
|
676
675
|
},
|
|
677
676
|
inputType: "number",
|
|
678
677
|
testValue: "12345",
|
|
@@ -683,7 +682,7 @@ var growthPct_default = declareFormatter({
|
|
|
683
682
|
var growthWord_default = declareFormatter({
|
|
684
683
|
name: "growthWord",
|
|
685
684
|
description: "Returns either 'growth' or 'decline' depending on the provided number's sign.",
|
|
686
|
-
logicFactory(
|
|
685
|
+
logicFactory(libs) {
|
|
687
686
|
return (n) => n < 0 ? "decline" : "growth";
|
|
688
687
|
},
|
|
689
688
|
inputType: "number",
|
|
@@ -695,7 +694,7 @@ var growthWord_default = declareFormatter({
|
|
|
695
694
|
var highWord_default = declareFormatter({
|
|
696
695
|
name: "highWord",
|
|
697
696
|
description: "Returns either 'higher than', 'lower than', or 'approximately the same as' depending on the provided number's sign.",
|
|
698
|
-
logicFactory(
|
|
697
|
+
logicFactory(libs) {
|
|
699
698
|
return (n) => n < 0 ? "lower than" : n > 0 ? "higher than" : "approximately the same as";
|
|
700
699
|
},
|
|
701
700
|
inputType: "number",
|
|
@@ -707,7 +706,7 @@ var highWord_default = declareFormatter({
|
|
|
707
706
|
var increaseWord_default = declareFormatter({
|
|
708
707
|
name: "increaseWord",
|
|
709
708
|
description: "Returns either 'increase', 'decrease', or 'change' depending on the provided number's sign.",
|
|
710
|
-
logicFactory(
|
|
709
|
+
logicFactory(libs) {
|
|
711
710
|
return (n) => n < 0 ? "decrease" : n > 0 ? "increase" : "change";
|
|
712
711
|
},
|
|
713
712
|
inputType: "number",
|
|
@@ -719,7 +718,7 @@ var increaseWord_default = declareFormatter({
|
|
|
719
718
|
var increasedWord_default = declareFormatter({
|
|
720
719
|
name: "increasedWord",
|
|
721
720
|
description: "Returns either 'increased', 'decreased', or 'remained the same' depending on the provided number's sign.",
|
|
722
|
-
logicFactory(
|
|
721
|
+
logicFactory(libs) {
|
|
723
722
|
return (n) => n < 0 ? "decreased" : n > 0 ? "increased" : "remained the same";
|
|
724
723
|
},
|
|
725
724
|
inputType: "number",
|
|
@@ -731,7 +730,7 @@ var increasedWord_default = declareFormatter({
|
|
|
731
730
|
var increasing_default = declareFormatter({
|
|
732
731
|
name: "increasing",
|
|
733
732
|
description: "Returns either 'decreasing', 'increasing' or 'maintaining' depending on the provided number's sign.",
|
|
734
|
-
logicFactory(
|
|
733
|
+
logicFactory(libs) {
|
|
735
734
|
return (n) => n < 0 ? "decreasing" : n > 0 ? "increasing" : "maintaining";
|
|
736
735
|
},
|
|
737
736
|
inputType: "number",
|
|
@@ -743,7 +742,7 @@ var increasing_default = declareFormatter({
|
|
|
743
742
|
var largerThan_default = declareFormatter({
|
|
744
743
|
name: "largerThan",
|
|
745
744
|
description: "Returns either 'higher than', 'lower than', or 'approximately the same as' depending on the provided number's sign",
|
|
746
|
-
logicFactory(
|
|
745
|
+
logicFactory(libs) {
|
|
747
746
|
return (n) => n < 0 ? "smaller than" : n > 0 ? "larger than" : "the same as";
|
|
748
747
|
},
|
|
749
748
|
inputType: "number",
|
|
@@ -755,7 +754,7 @@ var largerThan_default = declareFormatter({
|
|
|
755
754
|
var list_default = declareFormatter({
|
|
756
755
|
name: "list",
|
|
757
756
|
description: "Joins an array of strings together, adding commas and 'and' when necessary.",
|
|
758
|
-
logicFactory(
|
|
757
|
+
logicFactory(libs) {
|
|
759
758
|
return (n) => n.reduce((str, item, i) => {
|
|
760
759
|
if (!i)
|
|
761
760
|
str += item;
|
|
@@ -777,7 +776,7 @@ var list_default = declareFormatter({
|
|
|
777
776
|
var longWord_default = declareFormatter({
|
|
778
777
|
name: "longWord",
|
|
779
778
|
description: "",
|
|
780
|
-
logicFactory(
|
|
779
|
+
logicFactory(libs) {
|
|
781
780
|
return (n) => n < 0 ? "shorter" : n > 0 ? "longer" : "similar";
|
|
782
781
|
},
|
|
783
782
|
inputType: "number",
|
|
@@ -789,7 +788,7 @@ var longWord_default = declareFormatter({
|
|
|
789
788
|
var lowerCaseFirst_default = declareFormatter({
|
|
790
789
|
name: "lowerCaseFirst",
|
|
791
790
|
description: "Converts the first letter of a string to lowercase",
|
|
792
|
-
logicFactory(
|
|
791
|
+
logicFactory(libs) {
|
|
793
792
|
return (n) => typeof n === "string" ? n.charAt(0).toLowerCase() + n.slice(1) : n;
|
|
794
793
|
},
|
|
795
794
|
inputType: "string",
|
|
@@ -801,7 +800,7 @@ var lowerCaseFirst_default = declareFormatter({
|
|
|
801
800
|
var moreFewerWord_default = declareFormatter({
|
|
802
801
|
name: "moreFewerWord",
|
|
803
802
|
description: "",
|
|
804
|
-
logicFactory(
|
|
803
|
+
logicFactory(libs) {
|
|
805
804
|
return (n) => n < 0 ? "fewer" : "more";
|
|
806
805
|
},
|
|
807
806
|
inputType: "number",
|
|
@@ -813,7 +812,7 @@ var moreFewerWord_default = declareFormatter({
|
|
|
813
812
|
var moreLess_default = declareFormatter({
|
|
814
813
|
name: "moreLess",
|
|
815
814
|
description: "Returns either 'more' or 'less' depending on the provided number's sign.",
|
|
816
|
-
logicFactory(
|
|
815
|
+
logicFactory(libs) {
|
|
817
816
|
return (n) => n < 0 ? "less" : "more";
|
|
818
817
|
},
|
|
819
818
|
inputType: "number",
|
|
@@ -825,7 +824,7 @@ var moreLess_default = declareFormatter({
|
|
|
825
824
|
var moreWord_default = declareFormatter({
|
|
826
825
|
name: "moreLess",
|
|
827
826
|
description: "Returns either 'more than', 'less than', or 'approximately the same' depending on the provided number's sign.",
|
|
828
|
-
logicFactory(
|
|
827
|
+
logicFactory(libs) {
|
|
829
828
|
return (n) => n < 0 ? "less than" : n > 0 ? "more than" : "approximately the same";
|
|
830
829
|
},
|
|
831
830
|
inputType: "number",
|
|
@@ -837,7 +836,7 @@ var moreWord_default = declareFormatter({
|
|
|
837
836
|
var olderWord_default = declareFormatter({
|
|
838
837
|
name: "olderWord",
|
|
839
838
|
description: "",
|
|
840
|
-
logicFactory(
|
|
839
|
+
logicFactory(libs) {
|
|
841
840
|
return (n) => n < 0 ? "getting younger" : n > 0 ? "getting older" : "staying the same age";
|
|
842
841
|
},
|
|
843
842
|
inputType: "number",
|
|
@@ -849,7 +848,7 @@ var olderWord_default = declareFormatter({
|
|
|
849
848
|
var olderYounger_default = declareFormatter({
|
|
850
849
|
name: "olderYounger",
|
|
851
850
|
description: "",
|
|
852
|
-
logicFactory(
|
|
851
|
+
logicFactory(libs) {
|
|
853
852
|
return (n) => n < 0 ? "younger than" : n > 0 ? "older than" : "the same age as";
|
|
854
853
|
},
|
|
855
854
|
inputType: "number",
|
|
@@ -861,7 +860,7 @@ var olderYounger_default = declareFormatter({
|
|
|
861
860
|
var plural_default = declareFormatter({
|
|
862
861
|
name: "plural",
|
|
863
862
|
description: "Pluralizes a word.",
|
|
864
|
-
logicFactory(
|
|
863
|
+
logicFactory(libs) {
|
|
865
864
|
return (n) => n.replace(/\w$/g, (chr) => chr === "y" ? "ies" : `${chr}s`);
|
|
866
865
|
},
|
|
867
866
|
inputType: "string",
|
|
@@ -873,7 +872,7 @@ var plural_default = declareFormatter({
|
|
|
873
872
|
var pxToInt_default = declareFormatter({
|
|
874
873
|
name: "pxToInt",
|
|
875
874
|
description: "Takes a pixel value and converts it to an integer",
|
|
876
|
-
logicFactory(
|
|
875
|
+
logicFactory(libs) {
|
|
877
876
|
return (n) => parseInt(n.replace(/\D+/g, ""), 10);
|
|
878
877
|
},
|
|
879
878
|
inputType: "string",
|
|
@@ -885,13 +884,13 @@ var pxToInt_default = declareFormatter({
|
|
|
885
884
|
var salary_default = declareFormatter({
|
|
886
885
|
name: "salary",
|
|
887
886
|
description: "Displays salary values with proper precision (ie. '$74,200' instead of '$74.2k')",
|
|
888
|
-
logicFactory(
|
|
887
|
+
logicFactory(libs) {
|
|
889
888
|
return (n) => {
|
|
890
889
|
let str;
|
|
891
890
|
if (n < 1e6) {
|
|
892
|
-
str =
|
|
891
|
+
str = libs.d3.format(",")(n.toFixed(0));
|
|
893
892
|
} else
|
|
894
|
-
str =
|
|
893
|
+
str = libs.d3plus.formatAbbreviate(n);
|
|
895
894
|
return `$${str}`;
|
|
896
895
|
};
|
|
897
896
|
},
|
|
@@ -904,7 +903,7 @@ var salary_default = declareFormatter({
|
|
|
904
903
|
var stripEntities_default = declareFormatter({
|
|
905
904
|
name: "stripEntities",
|
|
906
905
|
description: "Removes non breaking spaces & other html entities from a string",
|
|
907
|
-
logicFactory(
|
|
906
|
+
logicFactory(libs) {
|
|
908
907
|
return (n) => typeof n === "string" ? String(n).replace(/&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});/ig, " ") : n;
|
|
909
908
|
},
|
|
910
909
|
inputType: "string",
|
|
@@ -916,7 +915,7 @@ var stripEntities_default = declareFormatter({
|
|
|
916
915
|
var stripHTML_default = declareFormatter({
|
|
917
916
|
name: "stripHTML",
|
|
918
917
|
description: "Converts html tags to spaces, then removes redundant spaces",
|
|
919
|
-
logicFactory(
|
|
918
|
+
logicFactory(libs) {
|
|
920
919
|
return (n) => {
|
|
921
920
|
const entities = {
|
|
922
921
|
"&": "&",
|
|
@@ -943,7 +942,7 @@ var stripHTML_default = declareFormatter({
|
|
|
943
942
|
var stripOL_default = declareFormatter({
|
|
944
943
|
name: "stripOL",
|
|
945
944
|
description: "Removes ordered list wrapper tags from a string.",
|
|
946
|
-
logicFactory(
|
|
945
|
+
logicFactory(libs) {
|
|
947
946
|
return (n) => n.replace(/<ol>/g, "").replace(/<\/ol>/g, "");
|
|
948
947
|
},
|
|
949
948
|
inputType: "string",
|
|
@@ -955,7 +954,7 @@ var stripOL_default = declareFormatter({
|
|
|
955
954
|
var stripP_default = declareFormatter({
|
|
956
955
|
name: "stripP",
|
|
957
956
|
description: "Removes all paragraph tags from a string.",
|
|
958
|
-
logicFactory(
|
|
957
|
+
logicFactory(libs) {
|
|
959
958
|
return (n) => n.replace(/<p>/g, "").replace(/<\/p>/g, "");
|
|
960
959
|
},
|
|
961
960
|
inputType: "string",
|
|
@@ -967,7 +966,7 @@ var stripP_default = declareFormatter({
|
|
|
967
966
|
var stripUL_default = declareFormatter({
|
|
968
967
|
name: "stripUL",
|
|
969
968
|
description: "Removes unordered list wrapper tags from a string.",
|
|
970
|
-
logicFactory(
|
|
969
|
+
logicFactory(libs) {
|
|
971
970
|
return (n) => n.replace(/<ul>/g, "").replace(/<\/ul>/g, "");
|
|
972
971
|
},
|
|
973
972
|
inputType: "string",
|
|
@@ -979,7 +978,7 @@ var stripUL_default = declareFormatter({
|
|
|
979
978
|
var toKebabCase_default = declareFormatter({
|
|
980
979
|
name: "toKebabCase",
|
|
981
980
|
description: "Takes a camelCase or PascalCase string and converts it to kebab-case.",
|
|
982
|
-
logicFactory(
|
|
981
|
+
logicFactory(libs) {
|
|
983
982
|
return (n) => {
|
|
984
983
|
if (typeof n === "string") {
|
|
985
984
|
n = n.charAt(0).toLowerCase() + n.substring(1);
|
|
@@ -997,7 +996,7 @@ var toKebabCase_default = declareFormatter({
|
|
|
997
996
|
var toSpacedCase_default = declareFormatter({
|
|
998
997
|
name: "toSpacedCase",
|
|
999
998
|
description: "Takes a camelCase or PascalCase string and adds spaces (I know Spaced Case isn't a thing, deal with it).",
|
|
1000
|
-
logicFactory(
|
|
999
|
+
logicFactory(libs) {
|
|
1001
1000
|
return (n) => {
|
|
1002
1001
|
if (typeof n === "string") {
|
|
1003
1002
|
return n.replace(/([A-Z])/g, " $1").toLowerCase().trim();
|
|
@@ -1014,7 +1013,7 @@ var toSpacedCase_default = declareFormatter({
|
|
|
1014
1013
|
var upperCaseFirst_default = declareFormatter({
|
|
1015
1014
|
name: "upperCaseFirst",
|
|
1016
1015
|
description: "Converts the first letter of a string to uppercase",
|
|
1017
|
-
logicFactory(
|
|
1016
|
+
logicFactory(libs) {
|
|
1018
1017
|
return (n) => n.charAt(0).toUpperCase() + n.slice(1);
|
|
1019
1018
|
},
|
|
1020
1019
|
inputType: "string",
|
|
@@ -3745,37 +3744,39 @@ async function endpointNextJsHandlerFactory(req, res) {
|
|
|
3745
3744
|
const key = endpointKey(method, pathString);
|
|
3746
3745
|
return map[key];
|
|
3747
3746
|
});
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
if (
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
if (handlerObj.handler) {
|
|
3759
|
-
if (["POST", "DELETE"].includes(method)) {
|
|
3760
|
-
req.body = await parseBody(req);
|
|
3747
|
+
if (handlerObj) {
|
|
3748
|
+
const session = await getAuth_default.getSession(req, res);
|
|
3749
|
+
if (handlerObj.roleRequired) {
|
|
3750
|
+
if (!session) {
|
|
3751
|
+
return res.status(401).json({ error: "Unauthorized. Must be logged in." });
|
|
3752
|
+
}
|
|
3753
|
+
const userRoles = session && session.user && session.user.bespoke_roles && Array.isArray(session.user.bespoke_roles) ? session.user.bespoke_roles : [];
|
|
3754
|
+
if (!userRoles.includes(handlerObj.roleRequired)) {
|
|
3755
|
+
return res.status(402).json({ error: "Forbidden. Not enough roles." });
|
|
3756
|
+
}
|
|
3761
3757
|
}
|
|
3762
|
-
|
|
3763
|
-
if (
|
|
3764
|
-
|
|
3758
|
+
if (handlerObj.handler) {
|
|
3759
|
+
if (["POST", "DELETE"].includes(method)) {
|
|
3760
|
+
req.body = await parseBody(req);
|
|
3765
3761
|
}
|
|
3766
|
-
|
|
3767
|
-
if (result
|
|
3768
|
-
|
|
3769
|
-
res.writeHead(result.status, { "Content-Type": "image/png" }).end(image, "binary");
|
|
3770
|
-
} else {
|
|
3771
|
-
res.status(result.status).json({ data: result.data });
|
|
3762
|
+
return Promise.resolve(req).then((req2) => handlerObj.handler(req2, res, session ? session : void 0)).then((result) => {
|
|
3763
|
+
if (result && "error" in result) {
|
|
3764
|
+
throw new BackendError(result.status, result.error);
|
|
3772
3765
|
}
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3766
|
+
if (result.ok) {
|
|
3767
|
+
if (result.data instanceof Buffer) {
|
|
3768
|
+
const image = result.data;
|
|
3769
|
+
res.writeHead(result.status, { "Content-Type": "image/png" }).end(image, "binary");
|
|
3770
|
+
} else {
|
|
3771
|
+
res.status(result.status).json({ data: result.data });
|
|
3772
|
+
}
|
|
3773
|
+
}
|
|
3774
|
+
}).catch((err) => {
|
|
3775
|
+
if (verbose4)
|
|
3776
|
+
console.trace("Backend Error", err);
|
|
3777
|
+
res.status(err.code).json({ error: err.message });
|
|
3778
|
+
});
|
|
3779
|
+
}
|
|
3779
3780
|
}
|
|
3780
3781
|
} else if (!path) {
|
|
3781
3782
|
await endpointMap.then(console.log);
|