inferred-types 0.55.17 → 0.55.19

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.
@@ -100,6 +100,7 @@ __export(index_exports, {
100
100
  handleDoneFn: () => handleDoneFn,
101
101
  hasCountryCode: () => hasCountryCode,
102
102
  hasDefaultValue: () => hasDefaultValue,
103
+ hasHtml: () => hasHtml,
103
104
  hasIndexOf: () => hasIndexOf,
104
105
  hasKeys: () => hasKeys,
105
106
  hasOverlappingKeys: () => hasOverlappingKeys,
@@ -107,6 +108,7 @@ __export(index_exports, {
107
108
  hasProtocolPrefix: () => hasProtocolPrefix,
108
109
  hasUrlPort: () => hasUrlPort,
109
110
  hasUrlQueryParameter: () => hasUrlQueryParameter,
111
+ hasValidHtml: () => hasValidHtml,
110
112
  hasWhiteSpace: () => hasWhiteSpace,
111
113
  idLiteral: () => idLiteral,
112
114
  idTypeGuard: () => idTypeGuard,
@@ -219,6 +221,8 @@ __export(index_exports, {
219
221
  isHexadecimal: () => isHexadecimal,
220
222
  isHmUrl: () => isHmUrl,
221
223
  isHomeDepotUrl: () => isHomeDepotUrl,
224
+ isHtml: () => isHtml,
225
+ isHtmlComponentTag: () => isHtmlComponentTag,
222
226
  isHtmlElement: () => isHtmlElement,
223
227
  isIkeaUrl: () => isIkeaUrl,
224
228
  isIndexable: () => isIndexable,
@@ -362,6 +366,10 @@ __export(index_exports, {
362
366
  isUsPhoneNumber: () => isUsPhoneNumber,
363
367
  isUsStateAbbreviation: () => isUsStateAbbreviation,
364
368
  isUsStateName: () => isUsStateName,
369
+ isValidAtomicTag: () => isValidAtomicTag,
370
+ isValidBlockTag: () => isValidBlockTag,
371
+ isValidHtml: () => isValidHtml,
372
+ isValidHtmlTag: () => isValidHtmlTag,
365
373
  isVariable: () => isVariable,
366
374
  isVisa: () => isVisa,
367
375
  isVisaMastercard: () => isVisaMastercard,
@@ -488,6 +496,7 @@ __export(index_exports, {
488
496
  unset: () => unset,
489
497
  uppercase: () => uppercase,
490
498
  urlMeta: () => urlMeta,
499
+ validHtmlAttributes: () => validHtmlAttributes,
491
500
  valuesOf: () => valuesOf,
492
501
  widen: () => widen,
493
502
  withDefaults: () => withDefaults,
@@ -832,6 +841,120 @@ var HASH_TABLE_CHAR = {
832
841
  ...HASH_TABLE_ALPHA_UPPER,
833
842
  ...HASH_TABLE_SPECIAL
834
843
  };
844
+ var HTML_BLOCK_TAGS = [
845
+ "a",
846
+ "abbr",
847
+ "address",
848
+ "article",
849
+ "aside",
850
+ "b",
851
+ "bdi",
852
+ "bdo",
853
+ "blockquote",
854
+ "body",
855
+ "button",
856
+ "canvas",
857
+ "caption",
858
+ "cite",
859
+ "code",
860
+ "colgroup",
861
+ "data",
862
+ "datalist",
863
+ "dd",
864
+ "del",
865
+ "details",
866
+ "dfn",
867
+ "dialog",
868
+ "div",
869
+ "dl",
870
+ "dt",
871
+ "em",
872
+ "fieldset",
873
+ "figcaption",
874
+ "figure",
875
+ "footer",
876
+ "form",
877
+ "h1",
878
+ "h2",
879
+ "h3",
880
+ "h4",
881
+ "h5",
882
+ "h6",
883
+ "head",
884
+ "header",
885
+ "html",
886
+ "i",
887
+ "iframe",
888
+ "ins",
889
+ "kbd",
890
+ "label",
891
+ "legend",
892
+ "li",
893
+ "main",
894
+ "map",
895
+ "mark",
896
+ "menu",
897
+ "meter",
898
+ "nav",
899
+ "noscript",
900
+ "object",
901
+ "ol",
902
+ "optgroup",
903
+ "option",
904
+ "output",
905
+ "p",
906
+ "picture",
907
+ "pre",
908
+ "progress",
909
+ "q",
910
+ "rp",
911
+ "rt",
912
+ "ruby",
913
+ "s",
914
+ "samp",
915
+ "script",
916
+ "section",
917
+ "select",
918
+ "small",
919
+ "span",
920
+ "strong",
921
+ "style",
922
+ "sub",
923
+ "summary",
924
+ "sup",
925
+ "svg",
926
+ "table",
927
+ "tbody",
928
+ "td",
929
+ "template",
930
+ "textarea",
931
+ "tfoot",
932
+ "th",
933
+ "thead",
934
+ "time",
935
+ "title",
936
+ "tr",
937
+ "u",
938
+ "ul",
939
+ "var",
940
+ "video"
941
+ ];
942
+ var HTML_ATOMIC_TAGS = [
943
+ "area",
944
+ "base",
945
+ "br",
946
+ "col",
947
+ "embed",
948
+ "hr",
949
+ "img",
950
+ "input",
951
+ "link",
952
+ "meta",
953
+ "param",
954
+ "source",
955
+ "track",
956
+ "wbr"
957
+ ];
835
958
  var ISO3166_1 = [
836
959
  { name: "Afghanistan", alpha2: "AF", countryCode: "004", alpha3: "AFG" },
837
960
  { name: "Albania", alpha2: "AL", countryCode: "008", alpha3: "ALB" },
@@ -3880,11 +4003,172 @@ function startsWith(startingWith) {
3880
4003
  };
3881
4004
  }
3882
4005
 
4006
+ // src/type-guards/html/component-tags.ts
4007
+ function isHtmlComponentTag(...names) {
4008
+ return (val) => {
4009
+ if (typeof val !== "string")
4010
+ return false;
4011
+ const trimmedVal = val.trim();
4012
+ const tagRegex = /^<\/?([\w-]+)(.*?)>$/;
4013
+ const match = tagRegex.exec(trimmedVal);
4014
+ if (!match) {
4015
+ return false;
4016
+ }
4017
+ const [, tagName, attributes] = match;
4018
+ const isClosingTag = trimmedVal.startsWith("</");
4019
+ const isKebabCase = /^[a-z][a-z0-9-]*$/.test(tagName);
4020
+ const isPascalCase = /^[A-Z][a-zA-Z0-9]*$/.test(tagName);
4021
+ const normalizedKebabCase = toKebabCase(tagName);
4022
+ const normalizedPascalCase = toPascalCase(tagName);
4023
+ const isValidName = names.some(
4024
+ (name) => isKebabCase && normalizedKebabCase === toKebabCase(name) || isPascalCase && normalizedPascalCase === toPascalCase(name)
4025
+ );
4026
+ if (!isValidName) {
4027
+ return false;
4028
+ }
4029
+ if (isClosingTag) {
4030
+ return attributes.trim() === "";
4031
+ }
4032
+ return validHtmlAttributes(attributes);
4033
+ };
4034
+ }
4035
+
4036
+ // src/type-guards/html/hasHtml.ts
4037
+ function hasHtml(val) {
4038
+ if (typeof val !== "string")
4039
+ return false;
4040
+ const htmlTagRegex = /.*<(\w+)>.*/;
4041
+ return !!htmlTagRegex.test(val);
4042
+ }
4043
+ function hasValidHtml(val) {
4044
+ if (typeof val !== "string")
4045
+ return false;
4046
+ const trimmedVal = val.trim();
4047
+ const tagRegex = /<\/?(\w+)([^>]*)>/g;
4048
+ const stack = [];
4049
+ let match;
4050
+ match = tagRegex.exec(trimmedVal);
4051
+ while (match !== null) {
4052
+ const [, tagName] = match;
4053
+ const isClosingTag = match[0].startsWith("</");
4054
+ const isAtomicTag = HTML_ATOMIC_TAGS.includes(tagName);
4055
+ if (isAtomicTag) {
4056
+ match = tagRegex.exec(trimmedVal);
4057
+ continue;
4058
+ }
4059
+ if (isClosingTag) {
4060
+ const lastTag = stack.pop();
4061
+ if (lastTag !== tagName) {
4062
+ return false;
4063
+ }
4064
+ } else {
4065
+ if (!HTML_BLOCK_TAGS.includes(tagName)) {
4066
+ return false;
4067
+ }
4068
+ stack.push(tagName);
4069
+ }
4070
+ match = tagRegex.exec(trimmedVal);
4071
+ }
4072
+ return stack.length === 0 && tagRegex.test(trimmedVal);
4073
+ }
4074
+
4075
+ // src/type-guards/html/html-tags.ts
4076
+ function isValidBlockTag(val) {
4077
+ return isString(val) && HTML_BLOCK_TAGS.includes(val.toLowerCase());
4078
+ }
4079
+ function isValidAtomicTag(val) {
4080
+ return isString(val) && HTML_ATOMIC_TAGS.includes(val.toLowerCase());
4081
+ }
4082
+ function isValidHtmlTag(...tags) {
4083
+ return (val) => {
4084
+ if (typeof val !== "string")
4085
+ return false;
4086
+ const trimmedVal = val.trim();
4087
+ const tagRegex = /^<\/?(\w+)(.*?)>$/;
4088
+ const match = tagRegex.exec(trimmedVal);
4089
+ if (!match) {
4090
+ return false;
4091
+ }
4092
+ const [, tagName, attributes] = match;
4093
+ const normalizedTagName = tagName.toLowerCase();
4094
+ const isClosingTag = trimmedVal.startsWith("</");
4095
+ const isAtomicTag = HTML_ATOMIC_TAGS.includes(normalizedTagName);
4096
+ const isBlockTag = HTML_BLOCK_TAGS.includes(normalizedTagName);
4097
+ if (
4098
+ // Validate tag name is within the provided `tags` scope
4099
+ !tags.map((t) => t.toLowerCase()).includes(normalizedTagName)
4100
+ ) {
4101
+ return false;
4102
+ }
4103
+ if (isClosingTag) {
4104
+ return attributes.trim() === "" && !isAtomicTag;
4105
+ }
4106
+ if (isAtomicTag) {
4107
+ return attributes.trim() === "" || validHtmlAttributes(attributes);
4108
+ }
4109
+ if (isBlockTag) {
4110
+ return validHtmlAttributes(attributes);
4111
+ }
4112
+ return false;
4113
+ };
4114
+ }
4115
+
4116
+ // src/type-guards/html/isHtml.ts
4117
+ function isHtml(val) {
4118
+ if (typeof val !== "string")
4119
+ return false;
4120
+ const trimmedVal = val.trim();
4121
+ const fullHtmlRegex = /^<(\w+).*<\/\1>$/;
4122
+ return fullHtmlRegex.test(trimmedVal);
4123
+ }
4124
+ function isValidHtml(val) {
4125
+ if (typeof val !== "string")
4126
+ return false;
4127
+ const trimmedVal = val.trim();
4128
+ const tagRegex = /<\/?(\w+)([^>]*)>/g;
4129
+ const stack = [];
4130
+ let match = tagRegex.exec(trimmedVal);
4131
+ while (match !== null) {
4132
+ const [, tagName] = match;
4133
+ const isClosingTag = match[0].startsWith("</");
4134
+ const isAtomicTag = HTML_ATOMIC_TAGS.includes(tagName);
4135
+ if (isAtomicTag) {
4136
+ match = tagRegex.exec(trimmedVal);
4137
+ continue;
4138
+ }
4139
+ if (isClosingTag) {
4140
+ const lastTag = stack.pop();
4141
+ if (lastTag !== tagName) {
4142
+ return false;
4143
+ }
4144
+ } else {
4145
+ if (!HTML_BLOCK_TAGS.includes(tagName)) {
4146
+ return false;
4147
+ }
4148
+ stack.push(tagName);
4149
+ }
4150
+ match = tagRegex.exec(trimmedVal);
4151
+ }
4152
+ const isBalanced = stack.length === 0;
4153
+ const validStructureRegex = /^<(\w+)[^>]*>[\s\S]*<\/\1>$/;
4154
+ return isBalanced && validStructureRegex.test(trimmedVal);
4155
+ }
4156
+
3883
4157
  // src/type-guards/html/isHtmlElement.ts
3884
4158
  function isHtmlElement(val) {
3885
4159
  return isObject(val) && "attributes" in val && "firstElementChild" in val && "innerHTML" in val;
3886
4160
  }
3887
4161
 
4162
+ // src/type-guards/html/validHtmlAttributes.ts
4163
+ function validHtmlAttributes(val) {
4164
+ if (typeof val !== "string")
4165
+ return false;
4166
+ const quoteRegex = /["']/g;
4167
+ const unmatchedQuotes = (val.match(quoteRegex)?.length || 0) % 2 !== 0;
4168
+ const invalidAssignment = /(\w+=)(?=\s|>|$)/.test(val);
4169
+ return !val.includes(">") && !unmatchedQuotes && !invalidAssignment;
4170
+ }
4171
+
3888
4172
  // src/type-guards/isAlpha.ts
3889
4173
  function isAlpha(value) {
3890
4174
  return isString(value) && split(value).every((v) => ALPHA_CHARS.includes(v));
@@ -6344,6 +6628,7 @@ function asVueRef(value) {
6344
6628
  handleDoneFn,
6345
6629
  hasCountryCode,
6346
6630
  hasDefaultValue,
6631
+ hasHtml,
6347
6632
  hasIndexOf,
6348
6633
  hasKeys,
6349
6634
  hasOverlappingKeys,
@@ -6351,6 +6636,7 @@ function asVueRef(value) {
6351
6636
  hasProtocolPrefix,
6352
6637
  hasUrlPort,
6353
6638
  hasUrlQueryParameter,
6639
+ hasValidHtml,
6354
6640
  hasWhiteSpace,
6355
6641
  idLiteral,
6356
6642
  idTypeGuard,
@@ -6463,6 +6749,8 @@ function asVueRef(value) {
6463
6749
  isHexadecimal,
6464
6750
  isHmUrl,
6465
6751
  isHomeDepotUrl,
6752
+ isHtml,
6753
+ isHtmlComponentTag,
6466
6754
  isHtmlElement,
6467
6755
  isIkeaUrl,
6468
6756
  isIndexable,
@@ -6606,6 +6894,10 @@ function asVueRef(value) {
6606
6894
  isUsPhoneNumber,
6607
6895
  isUsStateAbbreviation,
6608
6896
  isUsStateName,
6897
+ isValidAtomicTag,
6898
+ isValidBlockTag,
6899
+ isValidHtml,
6900
+ isValidHtmlTag,
6609
6901
  isVariable,
6610
6902
  isVisa,
6611
6903
  isVisaMastercard,
@@ -6732,6 +7024,7 @@ function asVueRef(value) {
6732
7024
  unset,
6733
7025
  uppercase,
6734
7026
  urlMeta,
7027
+ validHtmlAttributes,
6735
7028
  valuesOf,
6736
7029
  widen,
6737
7030
  withDefaults,