@aglyn/shared-util-tools 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +39 -0
- package/src/index.d.ts +72 -0
- package/src/index.js +87 -0
- package/src/index.js.map +1 -0
- package/src/lib/apply-mixins.d.ts +24 -0
- package/src/lib/apply-mixins.js +31 -0
- package/src/lib/apply-mixins.js.map +1 -0
- package/src/lib/array/array-copy-deep.d.ts +6 -0
- package/src/lib/array/array-copy-deep.js +25 -0
- package/src/lib/array/array-copy-deep.js.map +1 -0
- package/src/lib/array/array-copy-shallow.d.ts +19 -0
- package/src/lib/array/array-copy-shallow.js +20 -0
- package/src/lib/array/array-copy-shallow.js.map +1 -0
- package/src/lib/array/array-from-length.d.ts +18 -0
- package/src/lib/array/array-from-length.js +23 -0
- package/src/lib/array/array-from-length.js.map +1 -0
- package/src/lib/array/array-from.d.ts +24 -0
- package/src/lib/array/array-from.js +26 -0
- package/src/lib/array/array-from.js.map +1 -0
- package/src/lib/array/array-move-at-index.d.ts +24 -0
- package/src/lib/array/array-move-at-index.js +32 -0
- package/src/lib/array/array-move-at-index.js.map +1 -0
- package/src/lib/array/array-of-entries-to-object.d.ts +23 -0
- package/src/lib/array/array-of-entries-to-object.js +26 -0
- package/src/lib/array/array-of-entries-to-object.js.map +1 -0
- package/src/lib/array/array-overrides.d.ts +29 -0
- package/src/lib/array/array-overrides.js +71 -0
- package/src/lib/array/array-overrides.js.map +1 -0
- package/src/lib/array/array-push-at-index.d.ts +28 -0
- package/src/lib/array/array-push-at-index.js +32 -0
- package/src/lib/array/array-push-at-index.js.map +1 -0
- package/src/lib/array/array-remove-at-index.d.ts +23 -0
- package/src/lib/array/array-remove-at-index.js +26 -0
- package/src/lib/array/array-remove-at-index.js.map +1 -0
- package/src/lib/array/array-remove-item.d.ts +23 -0
- package/src/lib/array/array-remove-item.js +27 -0
- package/src/lib/array/array-remove-item.js.map +1 -0
- package/src/lib/array/array-safe.d.ts +21 -0
- package/src/lib/array/array-safe.js +29 -0
- package/src/lib/array/array-safe.js.map +1 -0
- package/src/lib/array/array-sort-by-deep-property.d.ts +26 -0
- package/src/lib/array/array-sort-by-deep-property.js +39 -0
- package/src/lib/array/array-sort-by-deep-property.js.map +1 -0
- package/src/lib/array/array-sort-by.d.ts +26 -0
- package/src/lib/array/array-sort-by.js +36 -0
- package/src/lib/array/array-sort-by.js.map +1 -0
- package/src/lib/array/array-update-at-index.d.ts +18 -0
- package/src/lib/array/array-update-at-index.js +22 -0
- package/src/lib/array/array-update-at-index.js.map +1 -0
- package/src/lib/array/array-update.d.ts +23 -0
- package/src/lib/array/array-update.js +25 -0
- package/src/lib/array/array-update.js.map +1 -0
- package/src/lib/bitwise/bitwise-has-all-attributes.d.ts +18 -0
- package/src/lib/bitwise/bitwise-has-all-attributes.js +21 -0
- package/src/lib/bitwise/bitwise-has-all-attributes.js.map +1 -0
- package/src/lib/bitwise/bitwise-has-attribute.d.ts +18 -0
- package/src/lib/bitwise/bitwise-has-attribute.js +21 -0
- package/src/lib/bitwise/bitwise-has-attribute.js.map +1 -0
- package/src/lib/bitwise/bitwise-has-only-attributes.d.ts +18 -0
- package/src/lib/bitwise/bitwise-has-only-attributes.js +21 -0
- package/src/lib/bitwise/bitwise-has-only-attributes.js.map +1 -0
- package/src/lib/contrast.d.ts +65 -0
- package/src/lib/contrast.js +78 -0
- package/src/lib/contrast.js.map +1 -0
- package/src/lib/copy-shallow.d.ts +19 -0
- package/src/lib/copy-shallow.js +20 -0
- package/src/lib/copy-shallow.js.map +1 -0
- package/src/lib/copy.d.ts +19 -0
- package/src/lib/copy.js +20 -0
- package/src/lib/copy.js.map +1 -0
- package/src/lib/create-chained-function.d.ts +38 -0
- package/src/lib/create-chained-function.js +46 -0
- package/src/lib/create-chained-function.js.map +1 -0
- package/src/lib/crud.d.ts +46 -0
- package/src/lib/crud.js +55 -0
- package/src/lib/crud.js.map +1 -0
- package/src/lib/css.d.ts +41 -0
- package/src/lib/css.js +54 -0
- package/src/lib/css.js.map +1 -0
- package/src/lib/escape-html.d.ts +38 -0
- package/src/lib/escape-html.js +47 -0
- package/src/lib/escape-html.js.map +1 -0
- package/src/lib/falsy.d.ts +23 -0
- package/src/lib/falsy.js +25 -0
- package/src/lib/falsy.js.map +1 -0
- package/src/lib/get-display-name.d.ts +46 -0
- package/src/lib/get-display-name.js +64 -0
- package/src/lib/get-display-name.js.map +1 -0
- package/src/lib/get-property.d.ts +30 -0
- package/src/lib/get-property.js +36 -0
- package/src/lib/get-property.js.map +1 -0
- package/src/lib/get-static-field.d.ts +23 -0
- package/src/lib/get-static-field.js +25 -0
- package/src/lib/get-static-field.js.map +1 -0
- package/src/lib/guards/index.d.ts +46 -0
- package/src/lib/guards/index.js +47 -0
- package/src/lib/guards/index.js.map +1 -0
- package/src/lib/guards/lib/_has-own-property.d.ts +24 -0
- package/src/lib/guards/lib/_has-own-property.js +27 -0
- package/src/lib/guards/lib/_has-own-property.js.map +1 -0
- package/src/lib/guards/lib/_is-arr-empty.d.ts +23 -0
- package/src/lib/guards/lib/_is-arr-empty.js +25 -0
- package/src/lib/guards/lib/_is-arr-empty.js.map +1 -0
- package/src/lib/guards/lib/_is-arr-of-arr.d.ts +25 -0
- package/src/lib/guards/lib/_is-arr-of-arr.js +31 -0
- package/src/lib/guards/lib/_is-arr-of-arr.js.map +1 -0
- package/src/lib/guards/lib/_is-arr.d.ts +21 -0
- package/src/lib/guards/lib/_is-arr.js +23 -0
- package/src/lib/guards/lib/_is-arr.js.map +1 -0
- package/src/lib/guards/lib/_is-big.d.ts +25 -0
- package/src/lib/guards/lib/_is-big.js +27 -0
- package/src/lib/guards/lib/_is-big.js.map +1 -0
- package/src/lib/guards/lib/_is-bool.d.ts +25 -0
- package/src/lib/guards/lib/_is-bool.js +27 -0
- package/src/lib/guards/lib/_is-bool.js.map +1 -0
- package/src/lib/guards/lib/_is-buff.d.ts +25 -0
- package/src/lib/guards/lib/_is-buff.js +29 -0
- package/src/lib/guards/lib/_is-buff.js.map +1 -0
- package/src/lib/guards/lib/_is-ctor.d.ts +25 -0
- package/src/lib/guards/lib/_is-ctor.js +30 -0
- package/src/lib/guards/lib/_is-ctor.js.map +1 -0
- package/src/lib/guards/lib/_is-empty-str-or-arr.d.ts +25 -0
- package/src/lib/guards/lib/_is-empty-str-or-arr.js +29 -0
- package/src/lib/guards/lib/_is-empty-str-or-arr.js.map +1 -0
- package/src/lib/guards/lib/_is-equality-same-type.d.ts +25 -0
- package/src/lib/guards/lib/_is-equality-same-type.js +33 -0
- package/src/lib/guards/lib/_is-equality-same-type.js.map +1 -0
- package/src/lib/guards/lib/_is-fn-t.d.ts +25 -0
- package/src/lib/guards/lib/_is-fn-t.js +27 -0
- package/src/lib/guards/lib/_is-fn-t.js.map +1 -0
- package/src/lib/guards/lib/_is-length-of.d.ts +47 -0
- package/src/lib/guards/lib/_is-length-of.js +49 -0
- package/src/lib/guards/lib/_is-length-of.js.map +1 -0
- package/src/lib/guards/lib/_is-length.d.ts +25 -0
- package/src/lib/guards/lib/_is-length.js +34 -0
- package/src/lib/guards/lib/_is-length.js.map +1 -0
- package/src/lib/guards/lib/_is-null.d.ts +25 -0
- package/src/lib/guards/lib/_is-null.js +27 -0
- package/src/lib/guards/lib/_is-null.js.map +1 -0
- package/src/lib/guards/lib/_is-num-neg.d.ts +25 -0
- package/src/lib/guards/lib/_is-num-neg.js +28 -0
- package/src/lib/guards/lib/_is-num-neg.js.map +1 -0
- package/src/lib/guards/lib/_is-num-pos.d.ts +25 -0
- package/src/lib/guards/lib/_is-num-pos.js +28 -0
- package/src/lib/guards/lib/_is-num-pos.js.map +1 -0
- package/src/lib/guards/lib/_is-num-t.d.ts +25 -0
- package/src/lib/guards/lib/_is-num-t.js +27 -0
- package/src/lib/guards/lib/_is-num-t.js.map +1 -0
- package/src/lib/guards/lib/_is-num-zero.d.ts +25 -0
- package/src/lib/guards/lib/_is-num-zero.js +28 -0
- package/src/lib/guards/lib/_is-num-zero.js.map +1 -0
- package/src/lib/guards/lib/_is-num.d.ts +26 -0
- package/src/lib/guards/lib/_is-num.js +29 -0
- package/src/lib/guards/lib/_is-num.js.map +1 -0
- package/src/lib/guards/lib/_is-obj-t.d.ts +26 -0
- package/src/lib/guards/lib/_is-obj-t.js +28 -0
- package/src/lib/guards/lib/_is-obj-t.js.map +1 -0
- package/src/lib/guards/lib/_is-obj.d.ts +27 -0
- package/src/lib/guards/lib/_is-obj.js +32 -0
- package/src/lib/guards/lib/_is-obj.js.map +1 -0
- package/src/lib/guards/lib/_is-prim.d.ts +27 -0
- package/src/lib/guards/lib/_is-prim.js +35 -0
- package/src/lib/guards/lib/_is-prim.js.map +1 -0
- package/src/lib/guards/lib/_is-promise-like.d.ts +24 -0
- package/src/lib/guards/lib/_is-promise-like.js +28 -0
- package/src/lib/guards/lib/_is-promise-like.js.map +1 -0
- package/src/lib/guards/lib/_is-str-empty.d.ts +25 -0
- package/src/lib/guards/lib/_is-str-empty.js +28 -0
- package/src/lib/guards/lib/_is-str-empty.js.map +1 -0
- package/src/lib/guards/lib/_is-str-t.d.ts +26 -0
- package/src/lib/guards/lib/_is-str-t.js +28 -0
- package/src/lib/guards/lib/_is-str-t.js.map +1 -0
- package/src/lib/guards/lib/_is-sym-t.d.ts +25 -0
- package/src/lib/guards/lib/_is-sym-t.js +27 -0
- package/src/lib/guards/lib/_is-sym-t.js.map +1 -0
- package/src/lib/guards/lib/_is-und-or-null.d.ts +25 -0
- package/src/lib/guards/lib/_is-und-or-null.js +29 -0
- package/src/lib/guards/lib/_is-und-or-null.js.map +1 -0
- package/src/lib/guards/lib/_is-und-t.d.ts +25 -0
- package/src/lib/guards/lib/_is-und-t.js +27 -0
- package/src/lib/guards/lib/_is-und-t.js.map +1 -0
- package/src/lib/interop-default.d.ts +18 -0
- package/src/lib/interop-default.js +21 -0
- package/src/lib/interop-default.js.map +1 -0
- package/src/lib/length.d.ts +22 -0
- package/src/lib/length.js +28 -0
- package/src/lib/length.js.map +1 -0
- package/src/lib/linear-regex.d.ts +136 -0
- package/src/lib/linear-regex.js +1140 -0
- package/src/lib/linear-regex.js.map +1 -0
- package/src/lib/no-side-effects.d.ts +29 -0
- package/src/lib/no-side-effects.js +33 -0
- package/src/lib/no-side-effects.js.map +1 -0
- package/src/lib/noop.d.ts +21 -0
- package/src/lib/noop.js +22 -0
- package/src/lib/noop.js.map +1 -0
- package/src/lib/normalized.d.ts +164 -0
- package/src/lib/normalized.js +232 -0
- package/src/lib/normalized.js.map +1 -0
- package/src/lib/number/number-from-hexadecimal.d.ts +24 -0
- package/src/lib/number/number-from-hexadecimal.js +29 -0
- package/src/lib/number/number-from-hexadecimal.js.map +1 -0
- package/src/lib/number/number-to-hexadecimal.d.ts +22 -0
- package/src/lib/number/number-to-hexadecimal.js +24 -0
- package/src/lib/number/number-to-hexadecimal.js.map +1 -0
- package/src/lib/number/to-num.d.ts +41 -0
- package/src/lib/number/to-num.js +41 -0
- package/src/lib/number/to-num.js.map +1 -0
- package/src/lib/numeronym.d.ts +41 -0
- package/src/lib/numeronym.js +54 -0
- package/src/lib/numeronym.js.map +1 -0
- package/src/lib/object/object-clone-deep.d.ts +21 -0
- package/src/lib/object/object-clone-deep.js +24 -0
- package/src/lib/object/object-clone-deep.js.map +1 -0
- package/src/lib/object/object-clone.d.ts +21 -0
- package/src/lib/object/object-clone.js +24 -0
- package/src/lib/object/object-clone.js.map +1 -0
- package/src/lib/object/object-delete-property.d.ts +28 -0
- package/src/lib/object/object-delete-property.js +32 -0
- package/src/lib/object/object-delete-property.js.map +1 -0
- package/src/lib/object/object-get-deep-property.d.ts +35 -0
- package/src/lib/object/object-get-deep-property.js +40 -0
- package/src/lib/object/object-get-deep-property.js.map +1 -0
- package/src/lib/object/object-get-keys-and-symbol-properties.d.ts +23 -0
- package/src/lib/object/object-get-keys-and-symbol-properties.js +30 -0
- package/src/lib/object/object-get-keys-and-symbol-properties.js.map +1 -0
- package/src/lib/object/object-remap.d.ts +33 -0
- package/src/lib/object/object-remap.js +36 -0
- package/src/lib/object/object-remap.js.map +1 -0
- package/src/lib/object/object-safe.d.ts +27 -0
- package/src/lib/object/object-safe.js +30 -0
- package/src/lib/object/object-safe.js.map +1 -0
- package/src/lib/object/object-set-deep-property.d.ts +35 -0
- package/src/lib/object/object-set-deep-property.js +44 -0
- package/src/lib/object/object-set-deep-property.js.map +1 -0
- package/src/lib/object/object-update.d.ts +28 -0
- package/src/lib/object/object-update.js +32 -0
- package/src/lib/object/object-update.js.map +1 -0
- package/src/lib/operator/compare.d.ts +26 -0
- package/src/lib/operator/compare.js +42 -0
- package/src/lib/operator/compare.js.map +1 -0
- package/src/lib/operator/definitions.d.ts +184 -0
- package/src/lib/operator/definitions.js +110 -0
- package/src/lib/operator/definitions.js.map +1 -0
- package/src/lib/operator/index.d.ts +19 -0
- package/src/lib/operator/index.js +20 -0
- package/src/lib/operator/index.js.map +1 -0
- package/src/lib/operator/inference.d.ts +66 -0
- package/src/lib/operator/inference.js +60 -0
- package/src/lib/operator/inference.js.map +1 -0
- package/src/lib/secret-box.d.ts +152 -0
- package/src/lib/secret-box.js +263 -0
- package/src/lib/secret-box.js.map +1 -0
- package/src/lib/serialize/base64-isomorphic-decode.d.ts +23 -0
- package/src/lib/serialize/base64-isomorphic-decode.js +28 -0
- package/src/lib/serialize/base64-isomorphic-decode.js.map +1 -0
- package/src/lib/serialize/base64-isomorphic-encode.d.ts +23 -0
- package/src/lib/serialize/base64-isomorphic-encode.js +28 -0
- package/src/lib/serialize/base64-isomorphic-encode.js.map +1 -0
- package/src/lib/serialize/json-deserialize.d.ts +25 -0
- package/src/lib/serialize/json-deserialize.js +27 -0
- package/src/lib/serialize/json-deserialize.js.map +1 -0
- package/src/lib/serialize/json-serialize.d.ts +25 -0
- package/src/lib/serialize/json-serialize.js +27 -0
- package/src/lib/serialize/json-serialize.js.map +1 -0
- package/src/lib/serialize/php-serial-deserialize-from-byte-stream.d.ts +77 -0
- package/src/lib/serialize/php-serial-deserialize-from-byte-stream.js +77 -0
- package/src/lib/serialize/php-serial-deserialize-from-byte-stream.js.map +1 -0
- package/src/lib/serialize/php-serial-is-serialized-byte-stream.d.ts +77 -0
- package/src/lib/serialize/php-serial-is-serialized-byte-stream.js +77 -0
- package/src/lib/serialize/php-serial-is-serialized-byte-stream.js.map +1 -0
- package/src/lib/serialize/php-serial-serialize-to-byte-stream.d.ts +77 -0
- package/src/lib/serialize/php-serial-serialize-to-byte-stream.js +77 -0
- package/src/lib/serialize/php-serial-serialize-to-byte-stream.js.map +1 -0
- package/src/lib/split-display-name.d.ts +36 -0
- package/src/lib/split-display-name.js +47 -0
- package/src/lib/split-display-name.js.map +1 -0
- package/src/lib/str.d.ts +21 -0
- package/src/lib/str.js +23 -0
- package/src/lib/str.js.map +1 -0
- package/src/lib/trim.d.ts +25 -0
- package/src/lib/trim.js +28 -0
- package/src/lib/trim.js.map +1 -0
- package/src/lib/truthy.d.ts +23 -0
- package/src/lib/truthy.js +30 -0
- package/src/lib/truthy.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/shared/util/tools/src/lib/interop-default.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nexport function interopDefault(mod: any) {\n return mod?.default || mod\n}\n\nexport default interopDefault\n"],"names":["interopDefault","mod","default"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,OAAO,SAASA,eAAeC,GAAQ;IACrC,OAAOA,CAAAA,uBAAAA,IAAKC,OAAO,KAAID;AACzB;AAEA,eAAeD,eAAc"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Shortcut for retrieving the length property,
|
|
19
|
+
* defaults to zero (0) if the property does not exist
|
|
20
|
+
*/
|
|
21
|
+
export declare function length(val: unknown): number;
|
|
22
|
+
export default length;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2022 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ /**
|
|
17
|
+
* Shortcut for retrieving the length property,
|
|
18
|
+
* defaults to zero (0) if the property does not exist
|
|
19
|
+
*/ export function length(val) {
|
|
20
|
+
if (val && (typeof val === 'object' || typeof val === 'string' || Array.isArray(val))) {
|
|
21
|
+
var _val_length;
|
|
22
|
+
return (_val_length = val['length']) != null ? _val_length : 0;
|
|
23
|
+
}
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
export default length;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=length.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/shared/util/tools/src/lib/length.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2022 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n/**\n * Shortcut for retrieving the length property,\n * defaults to zero (0) if the property does not exist\n */\nexport function length(val: unknown): number {\n if (val && (typeof val === 'object' || typeof val === 'string' || Array.isArray(val))) {\n return (val as any)['length'] ?? 0\n }\n return 0\n}\nexport default length\n"],"names":["length","val","Array","isArray"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD;;;CAGC,GACD,OAAO,SAASA,OAAOC,GAAY;IACjC,IAAIA,OAAQ,CAAA,OAAOA,QAAQ,YAAY,OAAOA,QAAQ,YAAYC,MAAMC,OAAO,CAACF,IAAG,GAAI;YAC9E;QAAP,QAAO,cAAA,AAACA,GAAW,CAAC,SAAS,YAAtB,cAA0B;IACnC;IACA,OAAO;AACT;AACA,eAAeD,OAAM"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* A linear-time regular-expression engine (SEC-M8 / AGL-1881), for patterns
|
|
19
|
+
* someone other than the platform wrote that run where every tenant renders:
|
|
20
|
+
* host redirect rules, and the conditions a component or layout property
|
|
21
|
+
* declares (AGL-2893).
|
|
22
|
+
*
|
|
23
|
+
* WHY THIS EXISTS
|
|
24
|
+
*
|
|
25
|
+
* Redirect regexes are attacker-authored (any `author` on a paid site can
|
|
26
|
+
* write `source` straight to Firestore — the console's validation is not a
|
|
27
|
+
* control) and they execute on the tenant render path, in the Node process
|
|
28
|
+
* shared by every tenant. `RegExp.prototype.exec` is a backtracking matcher,
|
|
29
|
+
* so a pattern like `(a|a|aa)+` against `"aaaa…a!"` costs exponential time:
|
|
30
|
+
* measured at 59 s for a 9-character pattern and a 27-character path, and it
|
|
31
|
+
* keeps doubling from there. That is a multi-tenant denial of service. A
|
|
32
|
+
* property condition's pattern is the same hazard with a wider door: it can
|
|
33
|
+
* arrive from a marketplace listing, and it runs on every page that places
|
|
34
|
+
* the component and in the console of everyone who installed it.
|
|
35
|
+
*
|
|
36
|
+
* Three heuristics have been tried and bypassed (AGL-505 star height, a
|
|
37
|
+
* length cap, nesting limits). A shape heuristic can never be sound: deciding
|
|
38
|
+
* whether an arbitrary backtracking regex is safe is the same problem as
|
|
39
|
+
* bounding its search tree. So this module does not inspect patterns for
|
|
40
|
+
* dangerous shapes. It removes the backtracking engine.
|
|
41
|
+
*
|
|
42
|
+
* HOW IT IS LINEAR BY CONSTRUCTION
|
|
43
|
+
*
|
|
44
|
+
* The pattern is parsed into an AST, compiled to a small NFA bytecode, and
|
|
45
|
+
* executed by a Thompson/Pike simulation: instead of trying one path at a
|
|
46
|
+
* time and backtracking, it advances *all* live NFA states one input
|
|
47
|
+
* character at a time, deduplicated by program counter. Each of the
|
|
48
|
+
* `programLength` states is visited at most once per input character, so the
|
|
49
|
+
* worst case is exactly `O(inputLength × programLength)` — there is no input
|
|
50
|
+
* that makes it exponential, because there is no search tree to explode.
|
|
51
|
+
*
|
|
52
|
+
* Thread priority ordering, and cutting lower-priority threads when a match
|
|
53
|
+
* is found, reproduce JavaScript's leftmost-first (greedy/lazy) semantics and
|
|
54
|
+
* its capture-group results, so ordinary patterns behave exactly as they did.
|
|
55
|
+
*
|
|
56
|
+
* `new RegExp` is never called on the pattern. Constructs that cannot be
|
|
57
|
+
* simulated in linear time — backreferences and lookaround — are not merely
|
|
58
|
+
* rejected by a checker that might have a hole; there is no instruction that
|
|
59
|
+
* could execute them, and the parser has no production that accepts them.
|
|
60
|
+
*
|
|
61
|
+
* WHAT THIS DOES NOT DO
|
|
62
|
+
*
|
|
63
|
+
* It is not a general-purpose RegExp replacement. It implements the subset
|
|
64
|
+
* documented in `UNSUPPORTED_SYNTAX` below and nothing else, and it makes no
|
|
65
|
+
* attempt at unicode mode or `lastIndex`. Of the flags, `i`, `m`, `s` and `y`
|
|
66
|
+
* mean what they mean to a fresh `RegExp`'s `test` (see {@link FLAG_CHARS});
|
|
67
|
+
* `g` and `d` change nothing a match answers, so they are accepted and have
|
|
68
|
+
* no effect; `u` and `v` are refused.
|
|
69
|
+
*/
|
|
70
|
+
/**
|
|
71
|
+
* Syntax deliberately outside the supported subset. Each entry is a
|
|
72
|
+
* construct that either cannot be simulated in linear time at all
|
|
73
|
+
* (backreferences, lookaround) or that is simply not implemented. Word
|
|
74
|
+
* boundaries are the exception `compileLinearTest` makes: it reads them, and
|
|
75
|
+
* `compileLinearPattern`, which redirect rules are held to, does not.
|
|
76
|
+
*/
|
|
77
|
+
export declare const UNSUPPORTED_SYNTAX: readonly ["lookahead `(?=…)` / `(?!…)`", "lookbehind `(?<=…)` / `(?<!…)`", "backreferences `\\1`…`\\9`, `\\k<name>`", "named groups `(?<name>…)`", "word boundaries `\\b` / `\\B`", "unicode property escapes `\\p{…}` / `\\P{…}`", "inline flags and other `(?…)` groups", "negated shorthands (`\\D`, `\\W`, `\\S`) inside a `[…]` class"];
|
|
78
|
+
/**
|
|
79
|
+
* The flags a pattern may carry, as the characters `RegExp` spells them.
|
|
80
|
+
* `g` and `d` are here because a fresh `RegExp`'s `test` answers the same
|
|
81
|
+
* with them as without; `u` and `v` are not, because unicode mode is not
|
|
82
|
+
* implemented.
|
|
83
|
+
*/
|
|
84
|
+
export declare const FLAG_CHARS = "dgimsy";
|
|
85
|
+
/**
|
|
86
|
+
* A compiled pattern. `exec` mirrors the slice of `RegExp.prototype.exec`
|
|
87
|
+
* the redirect matcher uses: index 0 is the whole match, index n is capture
|
|
88
|
+
* group n, and a group that did not participate is `undefined`.
|
|
89
|
+
*/
|
|
90
|
+
export interface LinearPattern {
|
|
91
|
+
readonly source: string;
|
|
92
|
+
/** Instruction count — worst-case cost is `input.length × programLength`. */
|
|
93
|
+
readonly programLength: number;
|
|
94
|
+
exec(input: string): Array<string | undefined> | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Compiles a pattern for linear-time matching, or returns null when it is
|
|
98
|
+
* malformed or uses syntax outside the supported subset.
|
|
99
|
+
*
|
|
100
|
+
* Takes no flags, and scans as redirect rules always have (see `ScanMode`).
|
|
101
|
+
* Never throws, and never hands the pattern to `new RegExp`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function compileLinearPattern(pattern: string): LinearPattern | null;
|
|
104
|
+
/**
|
|
105
|
+
* Explains why {@link compileLinearPattern} refuses a pattern, for
|
|
106
|
+
* console-side validation. Returns null when the pattern is fine.
|
|
107
|
+
*/
|
|
108
|
+
export declare function explainLinearPattern(pattern: string): string | null;
|
|
109
|
+
/** A compiled pattern that answers one question: does the input match. */
|
|
110
|
+
export interface LinearTest {
|
|
111
|
+
readonly source: string;
|
|
112
|
+
readonly flags: string;
|
|
113
|
+
/** Instruction count — worst-case cost is `input.length × programLength`. */
|
|
114
|
+
readonly programLength: number;
|
|
115
|
+
/**
|
|
116
|
+
* What `new RegExp(source, flags).test(input)` answers for a fresh
|
|
117
|
+
* `RegExp`, in time linear in the input.
|
|
118
|
+
*/
|
|
119
|
+
test(input: string): boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Compiles a pattern and its flags into a {@link LinearTest}, or returns null
|
|
123
|
+
* when either is malformed or outside the supported subset: the syntax in
|
|
124
|
+
* `UNSUPPORTED_SYNTAX` except word boundaries, which this reads, and any flag
|
|
125
|
+
* outside {@link FLAG_CHARS}.
|
|
126
|
+
*
|
|
127
|
+
* Unlike {@link compileLinearPattern} it scans to the end of the input (see
|
|
128
|
+
* `ScanMode`), so every pattern it accepts answers what `RegExp` answers.
|
|
129
|
+
* Never throws, and never hands the pattern to `new RegExp`.
|
|
130
|
+
*/
|
|
131
|
+
export declare function compileLinearTest(pattern: string, flags?: string): LinearTest | null;
|
|
132
|
+
/**
|
|
133
|
+
* Explains why {@link compileLinearTest} refuses a pattern or its flags.
|
|
134
|
+
* Returns null when both are fine.
|
|
135
|
+
*/
|
|
136
|
+
export declare function explainLinearTest(pattern: string, flags?: string): string | null;
|