@mavogel/awscdk-rootmail 0.0.315 → 0.0.317
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/.jsii +3 -3
- package/lib/rootmail.js +1 -1
- package/lib/ses-receive.js +1 -1
- package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +14 -14
- package/node_modules/@aws-sdk/client-route-53/dist-cjs/endpoint/ruleset.js +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +2 -0
- package/node_modules/@aws-sdk/client-route-53/dist-es/endpoint/ruleset.js +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-es/models/models_0.js +2 -0
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/AssociateVPCWithHostedZoneCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/CreateHealthCheckCommand.d.ts +2 -2
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/CreateHostedZoneCommand.d.ts +2 -2
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/CreateVPCAssociationAuthorizationCommand.d.ts +2 -2
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/DeleteVPCAssociationAuthorizationCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/DisassociateVPCFromHostedZoneCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/GetHealthCheckCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/GetHostedZoneCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/ListHealthChecksCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/ListHostedZonesByVPCCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/ListVPCAssociationAuthorizationsCommand.d.ts +1 -1
- package/node_modules/@aws-sdk/client-route-53/dist-types/commands/UpdateHealthCheckCommand.d.ts +2 -2
- package/node_modules/@aws-sdk/client-route-53/dist-types/models/models_0.d.ts +2 -0
- package/node_modules/@aws-sdk/client-route-53/dist-types/ts3.4/models/models_0.d.ts +2 -0
- package/node_modules/@aws-sdk/client-route-53/package.json +14 -14
- package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +9 -1
- package/node_modules/@aws-sdk/client-s3/dist-es/protocols/Aws_restXml.js +8 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/commands/CreateBucketCommand.d.ts +7 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/commands/HeadBucketCommand.d.ts +1 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/commands/ListBucketsCommand.d.ts +1 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/commands/ListDirectoryBucketsCommand.d.ts +1 -0
- package/node_modules/@aws-sdk/client-s3/dist-types/models/models_0.d.ts +58 -16
- package/node_modules/@aws-sdk/client-s3/dist-types/ts3.4/models/models_0.d.ts +8 -4
- package/node_modules/@aws-sdk/client-s3/package.json +19 -19
- package/node_modules/@aws-sdk/client-ses/package.json +14 -14
- package/node_modules/@aws-sdk/client-ssm/package.json +14 -14
- package/node_modules/@aws-sdk/client-sso/package.json +13 -13
- package/node_modules/@aws-sdk/core/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +6 -6
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-flexible-checksums/package.json +4 -4
- package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +5 -5
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +4 -4
- package/node_modules/@aws-sdk/nested-clients/package.json +13 -13
- package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +2 -2
- package/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/util-endpoints/dist-cjs/index.js +30 -0
- package/node_modules/@aws-sdk/util-endpoints/dist-es/index.js +1 -0
- package/node_modules/@aws-sdk/util-endpoints/dist-es/resolveDefaultAwsRegionalEndpointsConfig.js +21 -0
- package/node_modules/@aws-sdk/util-endpoints/dist-types/index.d.ts +1 -0
- package/node_modules/@aws-sdk/util-endpoints/dist-types/resolveDefaultAwsRegionalEndpointsConfig.d.ts +56 -0
- package/node_modules/@aws-sdk/util-endpoints/dist-types/ts3.4/index.d.ts +1 -0
- package/node_modules/@aws-sdk/util-endpoints/dist-types/ts3.4/resolveDefaultAwsRegionalEndpointsConfig.d.ts +35 -0
- package/node_modules/@aws-sdk/util-endpoints/package.json +2 -1
- package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +20 -20
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +80 -6
- package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +20 -20
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/ErrorSchema.js +10 -0
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/ListSchema.js +10 -0
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/MapSchema.js +10 -0
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +10 -0
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/SimpleSchema.js +10 -0
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/StructureSchema.js +10 -0
- package/node_modules/@smithy/core/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/ErrorSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/ListSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/MapSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/SimpleSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/StructureSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +1 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/ErrorSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/ListSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/MapSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/SimpleSchema.d.ts +3 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/StructureSchema.d.ts +3 -0
- package/node_modules/@smithy/core/package.json +2 -2
- package/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js +2 -2
- package/node_modules/@smithy/fetch-http-handler/dist-es/fetch-http-handler.js +4 -4
- package/node_modules/@smithy/fetch-http-handler/dist-types/fetch-http-handler.d.ts +1 -1
- package/node_modules/@smithy/fetch-http-handler/dist-types/ts3.4/fetch-http-handler.d.ts +1 -1
- package/node_modules/@smithy/fetch-http-handler/package.json +1 -1
- package/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js +5 -2
- package/node_modules/@smithy/middleware-endpoint/dist-es/adaptors/createConfigValueProvider.js +3 -0
- package/node_modules/@smithy/middleware-endpoint/dist-es/adaptors/getEndpointFromInstructions.js +1 -1
- package/node_modules/@smithy/middleware-endpoint/dist-es/endpointMiddleware.js +1 -1
- package/node_modules/@smithy/middleware-endpoint/dist-types/resolveEndpointConfig.d.ts +5 -2
- package/node_modules/@smithy/middleware-endpoint/dist-types/ts3.4/resolveEndpointConfig.d.ts +5 -2
- package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
- package/node_modules/@smithy/middleware-retry/package.json +2 -2
- package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +11 -9
- package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +4 -3
- package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +7 -6
- package/node_modules/@smithy/node-http-handler/dist-types/node-http-handler.d.ts +1 -1
- package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +1 -1
- package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http-handler.d.ts +1 -1
- package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-handler.d.ts +1 -1
- package/node_modules/@smithy/node-http-handler/package.json +1 -1
- package/node_modules/@smithy/smithy-client/package.json +4 -4
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
- package/node_modules/@smithy/util-stream/package.json +3 -3
- package/node_modules/cdk-nag/.jsii +2 -2
- package/node_modules/cdk-nag/lib/ignore-suppression-conditions.js +5 -5
- package/node_modules/cdk-nag/lib/nag-logger.js +2 -2
- package/node_modules/cdk-nag/lib/nag-pack.js +1 -1
- package/node_modules/cdk-nag/lib/nag-rules.js +1 -1
- package/node_modules/cdk-nag/lib/nag-suppressions.js +1 -1
- package/node_modules/cdk-nag/lib/packs/aws-solutions.js +1 -1
- package/node_modules/cdk-nag/lib/packs/hipaa-security.js +1 -1
- package/node_modules/cdk-nag/lib/packs/nist-800-53-r4.js +1 -1
- package/node_modules/cdk-nag/lib/packs/nist-800-53-r5.js +1 -1
- package/node_modules/cdk-nag/lib/packs/pci-dss-321.js +1 -1
- package/node_modules/cdk-nag/lib/packs/serverless.js +1 -1
- package/node_modules/cdk-nag/package.json +2 -2
- package/node_modules/fast-xml-parser/CHANGELOG.md +77 -0
- package/node_modules/fast-xml-parser/README.md +39 -52
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +1 -0
- package/node_modules/fast-xml-parser/lib/fxp.cjs +1 -0
- package/node_modules/fast-xml-parser/lib/fxp.d.cts +458 -0
- package/node_modules/fast-xml-parser/lib/fxp.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxp.min.js.map +1 -0
- package/node_modules/fast-xml-parser/lib/fxparser.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxparser.min.js.map +1 -0
- package/node_modules/fast-xml-parser/lib/fxvalidator.min.js +2 -0
- package/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +1 -0
- package/node_modules/fast-xml-parser/package.json +36 -20
- package/node_modules/fast-xml-parser/src/cli/cli.js +16 -12
- package/node_modules/fast-xml-parser/src/cli/man.js +6 -1
- package/node_modules/fast-xml-parser/src/cli/read.js +30 -79
- package/node_modules/fast-xml-parser/src/fxp.d.ts +52 -9
- package/node_modules/fast-xml-parser/src/fxp.js +11 -8
- package/node_modules/fast-xml-parser/src/ignoreAttributes.js +18 -0
- package/node_modules/fast-xml-parser/src/util.js +14 -18
- package/node_modules/fast-xml-parser/src/{v5 → v6}/CharsSymbol.js +1 -1
- package/node_modules/fast-xml-parser/src/{v5/valueParsers → v6}/EntitiesParser.js +3 -6
- package/node_modules/fast-xml-parser/src/{v5 → v6}/OptionsBuilder.js +3 -6
- package/node_modules/fast-xml-parser/src/{v5 → v6}/OutputBuilders/BaseOutputBuilder.js +1 -3
- package/node_modules/fast-xml-parser/src/{v5 → v6}/OutputBuilders/JsArrBuilder.js +3 -3
- package/node_modules/fast-xml-parser/src/{v5 → v6}/OutputBuilders/JsMinArrBuilder.js +3 -5
- package/node_modules/fast-xml-parser/src/{v5 → v6}/OutputBuilders/JsObjBuilder.js +3 -5
- package/node_modules/fast-xml-parser/src/{v5 → v6}/OutputBuilders/ParserOptionsBuilder.js +6 -11
- package/node_modules/fast-xml-parser/src/{v5 → v6}/TagPath.js +1 -1
- package/node_modules/fast-xml-parser/src/{v5 → v6}/TagPathMatcher.js +3 -5
- package/node_modules/fast-xml-parser/src/{v5 → v6}/XMLParser.js +3 -5
- package/node_modules/fast-xml-parser/src/{v5 → v6}/Xml2JsParser.js +8 -10
- package/node_modules/fast-xml-parser/src/{v5 → v6}/XmlPartReader.js +24 -26
- package/node_modules/fast-xml-parser/src/{v5 → v6}/XmlSpecialTagsReader.js +5 -12
- package/node_modules/fast-xml-parser/src/{v5 → v6}/inputSource/BufferSource.js +1 -3
- package/node_modules/fast-xml-parser/src/{v5 → v6}/inputSource/StringSource.js +1 -3
- package/node_modules/fast-xml-parser/src/{v5 → v6/valueParsers}/EntitiesParser.js +3 -5
- package/node_modules/fast-xml-parser/src/{v5 → v6}/valueParsers/booleanParser.js +1 -2
- package/node_modules/fast-xml-parser/src/{v5 → v6}/valueParsers/booleanParserExt.js +1 -2
- package/node_modules/fast-xml-parser/src/{v5 → v6}/valueParsers/currency.js +1 -3
- package/node_modules/fast-xml-parser/src/{v5 → v6}/valueParsers/join.js +1 -2
- package/node_modules/fast-xml-parser/src/{v5 → v6}/valueParsers/number.js +2 -4
- package/node_modules/fast-xml-parser/src/{v5 → v6}/valueParsers/trim.js +1 -3
- package/node_modules/fast-xml-parser/src/validator.js +5 -5
- package/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +17 -13
- package/node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js +1 -2
- package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +288 -71
- package/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +3 -5
- package/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +28 -23
- package/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +21 -8
- package/node_modules/fast-xml-parser/src/xmlparser/node2json.js +8 -2
- package/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +22 -7
- package/node_modules/strnum/.github/SECURITY.md +5 -0
- package/node_modules/strnum/CHANGELOG.md +33 -0
- package/node_modules/strnum/README.md +14 -3
- package/node_modules/strnum/algo.stflow +84 -0
- package/node_modules/strnum/package.json +9 -2
- package/node_modules/strnum/strnum.js +72 -67
- package/node_modules/strnum/strnum.test.js +29 -6
- package/node_modules/strnum/test.js +9 -0
- package/package.json +1 -1
- /package/node_modules/fast-xml-parser/src/{v5 → v6}/Report.js +0 -0
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let METADATA_SYMBOL;
|
|
4
|
+
|
|
5
|
+
if (typeof Symbol !== "function") {
|
|
6
|
+
METADATA_SYMBOL = "@@xmlMetadata";
|
|
7
|
+
} else {
|
|
8
|
+
METADATA_SYMBOL = Symbol("XML Node Metadata");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class XmlNode{
|
|
4
12
|
constructor(tagname) {
|
|
5
13
|
this.tagname = tagname;
|
|
6
14
|
this.child = []; //nested tags, text, cdata, comments in order
|
|
@@ -11,15 +19,22 @@ class XmlNode{
|
|
|
11
19
|
if(key === "__proto__") key = "#__proto__";
|
|
12
20
|
this.child.push( {[key]: val });
|
|
13
21
|
}
|
|
14
|
-
addChild(node) {
|
|
22
|
+
addChild(node, startIndex) {
|
|
15
23
|
if(node.tagname === "__proto__") node.tagname = "#__proto__";
|
|
16
24
|
if(node[":@"] && Object.keys(node[":@"]).length > 0){
|
|
17
25
|
this.child.push( { [node.tagname]: node.child, [":@"]: node[":@"] });
|
|
18
26
|
}else{
|
|
19
27
|
this.child.push( { [node.tagname]: node.child });
|
|
20
28
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
// if requested, add the startIndex
|
|
30
|
+
if (startIndex !== undefined) {
|
|
31
|
+
// Note: for now we just overwrite the metadata. If we had more complex metadata,
|
|
32
|
+
// we might need to do an object append here: metadata = { ...metadata, startIndex }
|
|
33
|
+
this.child[this.child.length - 1][METADATA_SYMBOL] = { startIndex };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** symbol used for metadata */
|
|
37
|
+
static getMetaDataSymbol() {
|
|
38
|
+
return METADATA_SYMBOL;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
If you believe you have found a security vulnerability in this repository which can be potentially harful for the users in anyway, please do not report security vulnerabilities through public GitHub issues. Instead, please report it to us as described below.
|
|
2
|
+
|
|
3
|
+
## Security contact information
|
|
4
|
+
|
|
5
|
+
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
**2.1.1 / 2025-05-15**
|
|
3
|
+
- remove unnecessary check to remove lint error
|
|
4
|
+
|
|
5
|
+
**2.1.0 / 2025-05-01**
|
|
6
|
+
- fix e-notation
|
|
7
|
+
- to return string when invalid enotation is found. Eg `E24`
|
|
8
|
+
- to return valid number when only leading zero before e char is present
|
|
9
|
+
|
|
10
|
+
**2.0.5 / 2025-02-27**
|
|
11
|
+
- changes done in 1.1.2
|
|
12
|
+
|
|
13
|
+
**1.1.2 / 2025-02-27**
|
|
14
|
+
- fix skiplike for 0
|
|
15
|
+
|
|
16
|
+
**1.1.1 / 2025-02-21**
|
|
17
|
+
- All recent fixes of version 2
|
|
18
|
+
|
|
19
|
+
**2.0.4 / 2025-02-20**
|
|
20
|
+
- remove console log
|
|
21
|
+
|
|
22
|
+
**2.0.3 / 2025-02-20**
|
|
23
|
+
- fix for string which are falsly identified as e-notation
|
|
24
|
+
|
|
25
|
+
**2.0.1 / 2025-02-20**
|
|
26
|
+
- fix: handle only zeros
|
|
27
|
+
- fix: return original string when NaN
|
|
28
|
+
|
|
29
|
+
**2.0.0 / 2025-02-20**
|
|
30
|
+
- Migrating to ESM modules. No functional change
|
|
31
|
+
|
|
32
|
+
**1.1.0 / 2025-02-20**
|
|
33
|
+
- fix (#9): support missing floating point and e notations
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# strnum
|
|
2
2
|
Parse string into Number based on configuration
|
|
3
3
|
|
|
4
|
+
## Users
|
|
5
|
+
|
|
6
|
+
<a href="https://github.com/aws-amplify" target="_blank"><img src="https://avatars.githubusercontent.com/u/41077760?s=100&v=4"></a>
|
|
7
|
+
<a href="https://github.com/astrapay" target="_blank"><img src="https://avatars.githubusercontent.com/u/90901882?s=100&v=4"></a>
|
|
8
|
+
<a href="https://github.com/process-analytics" target="_blank"><img src="https://avatars.githubusercontent.com/u/60110287?s=100&v=4"></a>
|
|
9
|
+
<a href="https://github.com/NaturalIntelligence" target="_blank"><img src="https://avatars.githubusercontent.com/u/16322633?s=100&v=4"></a>
|
|
10
|
+
Many React Native projects and plugins
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
4
14
|
```bash
|
|
5
15
|
npm install strnum
|
|
6
16
|
```
|
|
@@ -80,7 +90,8 @@ toNumber("+1212121212", { skipLike: /\+[0-9]{10}/} )); //"+1212121212"
|
|
|
80
90
|
|
|
81
91
|
Supported Options
|
|
82
92
|
```js
|
|
83
|
-
hex
|
|
93
|
+
hex: true, //when hexadecimal string should be parsed
|
|
84
94
|
leadingZeros: true, //when number with leading zeros like 08 should be parsed. 0.0 is not impacted
|
|
85
|
-
eNotation: true
|
|
86
|
-
|
|
95
|
+
eNotation: true, //when number with eNotation or number parsed in eNotation should be considered
|
|
96
|
+
skipLike: /regex/ //when string should not be parsed when it matches the specified regular expression
|
|
97
|
+
```
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
FLOW: toNumber
|
|
3
|
+
input: x, options
|
|
4
|
+
IF not string
|
|
5
|
+
END x
|
|
6
|
+
ELSE_IF should skip
|
|
7
|
+
END x
|
|
8
|
+
ELSE_IF 0
|
|
9
|
+
END 0
|
|
10
|
+
ELSE_IF hex is supported AND x is hex
|
|
11
|
+
END int of x of base 16
|
|
12
|
+
ELSE_IF possible e notation
|
|
13
|
+
FOLLOW: resolve enotation (x, trimmed x, options)
|
|
14
|
+
ELSE
|
|
15
|
+
IF match numeric pattern
|
|
16
|
+
separate sign, leading zeros, pure number
|
|
17
|
+
IF x doesn't starts with "[+-]0."
|
|
18
|
+
END number(x)
|
|
19
|
+
IF leading zeros are not allowed
|
|
20
|
+
IF leading zeros > 1
|
|
21
|
+
#00.1
|
|
22
|
+
END x
|
|
23
|
+
ELSE_IF leading zeros == 1 AND decimal is not adjacent to leading zeros
|
|
24
|
+
#06.5
|
|
25
|
+
#but not 0.65, .65, 6.0
|
|
26
|
+
END x
|
|
27
|
+
ELSE_IF str has only zeros
|
|
28
|
+
END 0
|
|
29
|
+
ELSE
|
|
30
|
+
parse x to number
|
|
31
|
+
IF parsed x == 0 or -0
|
|
32
|
+
END parsed x
|
|
33
|
+
ELSE_IF parsed x is eNotation
|
|
34
|
+
IF conversion to enotation is allowed
|
|
35
|
+
END parsed x
|
|
36
|
+
ELSE
|
|
37
|
+
END x
|
|
38
|
+
ELSE_IF floating number
|
|
39
|
+
IF parsed x is 0
|
|
40
|
+
END parsed x
|
|
41
|
+
ELSE_IF parsed x == number without leading 0s
|
|
42
|
+
#0.456. 0.79000
|
|
43
|
+
END parsed x
|
|
44
|
+
ELSE_IF parsed x is negative AND == parsed x == number without leading 0s
|
|
45
|
+
END parsed x
|
|
46
|
+
ELSE
|
|
47
|
+
END x
|
|
48
|
+
ELSE_IF leading 0s are present
|
|
49
|
+
IF parsed x == x without leading 0s
|
|
50
|
+
END parsed x
|
|
51
|
+
ELSE
|
|
52
|
+
END x
|
|
53
|
+
ELSE
|
|
54
|
+
IF parsed x == x (consider sign)
|
|
55
|
+
END parsed x
|
|
56
|
+
ELSE
|
|
57
|
+
END x
|
|
58
|
+
|
|
59
|
+
ELSE
|
|
60
|
+
END x
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
FLOW: resolve enotation
|
|
65
|
+
input: x, trimmed x, options
|
|
66
|
+
IF eNotation has not to be evaluated
|
|
67
|
+
END x
|
|
68
|
+
IF match eNotation pattern
|
|
69
|
+
extract sign, eChar, leading zeros
|
|
70
|
+
find if eChar adjacent to leading zeros
|
|
71
|
+
|
|
72
|
+
IF leading zeros > 1 AND eChar adjacent to leading zeros
|
|
73
|
+
# 00e, -00e
|
|
74
|
+
END x
|
|
75
|
+
ELSE_IF exp is `0e`, `0.e`, `-0.e`, `-0e`
|
|
76
|
+
END number(x);
|
|
77
|
+
ELSE_IF leading zeros are allowed but eChar is not adjacent to leading zeros
|
|
78
|
+
# -003e2
|
|
79
|
+
remove leading zeros
|
|
80
|
+
END number(x)
|
|
81
|
+
ELSE
|
|
82
|
+
END x
|
|
83
|
+
ELSE
|
|
84
|
+
END x
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strnum",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Parse String to Number based on configuration",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "strnum.js",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "jasmine strnum.test.js"
|
|
@@ -18,7 +19,13 @@
|
|
|
18
19
|
},
|
|
19
20
|
"author": "Amit Gupta (https://amitkumargupta.work/)",
|
|
20
21
|
"license": "MIT",
|
|
22
|
+
"funding": [
|
|
23
|
+
{
|
|
24
|
+
"type": "github",
|
|
25
|
+
"url": "https://github.com/sponsors/NaturalIntelligence"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
21
28
|
"devDependencies": {
|
|
22
|
-
"jasmine": "^
|
|
29
|
+
"jasmine": "^5.6.0"
|
|
23
30
|
}
|
|
24
31
|
}
|
|
@@ -1,111 +1,109 @@
|
|
|
1
1
|
const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
|
|
2
|
-
const numRegex = /^([\-\+])?(0*)(
|
|
3
|
-
// const octRegex =
|
|
2
|
+
const numRegex = /^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/;
|
|
3
|
+
// const octRegex = /^0x[a-z0-9]+/;
|
|
4
4
|
// const binRegex = /0x[a-z0-9]+/;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
//polyfill
|
|
8
|
-
if (!Number.parseInt && window.parseInt) {
|
|
9
|
-
Number.parseInt = window.parseInt;
|
|
10
|
-
}
|
|
11
|
-
if (!Number.parseFloat && window.parseFloat) {
|
|
12
|
-
Number.parseFloat = window.parseFloat;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
|
|
16
7
|
const consider = {
|
|
17
8
|
hex : true,
|
|
9
|
+
// oct: false,
|
|
18
10
|
leadingZeros: true,
|
|
19
11
|
decimalPoint: "\.",
|
|
20
|
-
eNotation: true
|
|
12
|
+
eNotation: true,
|
|
21
13
|
//skipLike: /regex/
|
|
22
14
|
};
|
|
23
15
|
|
|
24
|
-
function toNumber(str, options = {}){
|
|
25
|
-
// const options = Object.assign({}, consider);
|
|
26
|
-
// if(opt.leadingZeros === false){
|
|
27
|
-
// options.leadingZeros = false;
|
|
28
|
-
// }else if(opt.hex === false){
|
|
29
|
-
// options.hex = false;
|
|
30
|
-
// }
|
|
31
|
-
|
|
16
|
+
export default function toNumber(str, options = {}){
|
|
32
17
|
options = Object.assign({}, consider, options );
|
|
33
18
|
if(!str || typeof str !== "string" ) return str;
|
|
34
19
|
|
|
35
20
|
let trimmedStr = str.trim();
|
|
36
|
-
|
|
37
|
-
// else if(trimmedStr === "+0.0") return 0;
|
|
38
|
-
// else if(trimmedStr === "-0.0") return -0;
|
|
39
|
-
|
|
21
|
+
|
|
40
22
|
if(options.skipLike !== undefined && options.skipLike.test(trimmedStr)) return str;
|
|
23
|
+
else if(str==="0") return 0;
|
|
41
24
|
else if (options.hex && hexRegex.test(trimmedStr)) {
|
|
42
|
-
return
|
|
43
|
-
// }
|
|
25
|
+
return parse_int(trimmedStr, 16);
|
|
26
|
+
// }else if (options.oct && octRegex.test(str)) {
|
|
44
27
|
// return Number.parseInt(val, 8);
|
|
28
|
+
}else if (trimmedStr.search(/.+[eE].+/)!== -1) { //eNotation
|
|
29
|
+
return resolveEnotation(str,trimmedStr,options);
|
|
45
30
|
// }else if (options.parseBin && binRegex.test(str)) {
|
|
46
31
|
// return Number.parseInt(val, 2);
|
|
47
32
|
}else{
|
|
48
33
|
//separate negative sign, leading zeros, and rest number
|
|
49
34
|
const match = numRegex.exec(trimmedStr);
|
|
35
|
+
// +00.123 => [ , '+', '00', '.123', ..
|
|
50
36
|
if(match){
|
|
51
|
-
const sign = match[1];
|
|
37
|
+
const sign = match[1] || "";
|
|
52
38
|
const leadingZeros = match[2];
|
|
53
39
|
let numTrimmedByZeros = trimZeros(match[3]); //complete num without leading zeros
|
|
40
|
+
const decimalAdjacentToLeadingZeros = sign ? // 0., -00., 000.
|
|
41
|
+
str[leadingZeros.length+1] === "."
|
|
42
|
+
: str[leadingZeros.length] === ".";
|
|
43
|
+
|
|
54
44
|
//trim ending zeros for floating number
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
if(!options.leadingZeros //leading zeros are not allowed
|
|
46
|
+
&& (leadingZeros.length > 1
|
|
47
|
+
|| (leadingZeros.length === 1 && !decimalAdjacentToLeadingZeros))){
|
|
48
|
+
// 00, 00.3, +03.24, 03, 03.24
|
|
49
|
+
return str;
|
|
50
|
+
}
|
|
59
51
|
else{//no leading zeros or leading zeros are allowed
|
|
60
52
|
const num = Number(trimmedStr);
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}else if(eNotation){ //given number has enotation
|
|
53
|
+
const parsedStr = String(num);
|
|
54
|
+
|
|
55
|
+
if( num === 0) return num;
|
|
56
|
+
if(parsedStr.search(/[eE]/) !== -1){ //given number is long and parsed to eNotation
|
|
66
57
|
if(options.eNotation) return num;
|
|
67
58
|
else return str;
|
|
68
59
|
}else if(trimmedStr.indexOf(".") !== -1){ //floating number
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// const p = numStr.indexOf(".");
|
|
74
|
-
// const givenIntPart = numStr.substr(0,p);
|
|
75
|
-
// const givenDecPart = numStr.substr(p+1);
|
|
76
|
-
if(numStr === "0" && (numTrimmedByZeros === "") ) return num; //0.0
|
|
77
|
-
else if(numStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
|
78
|
-
else if( sign && numStr === "-"+numTrimmedByZeros) return num;
|
|
60
|
+
if(parsedStr === "0") return num; //0.0
|
|
61
|
+
else if(parsedStr === numTrimmedByZeros) return num; //0.456. 0.79000
|
|
62
|
+
else if( parsedStr === `${sign}${numTrimmedByZeros}`) return num;
|
|
79
63
|
else return str;
|
|
80
64
|
}
|
|
81
65
|
|
|
66
|
+
let n = leadingZeros? numTrimmedByZeros : trimmedStr;
|
|
82
67
|
if(leadingZeros){
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
else if(sign+numTrimmedByZeros === numStr) return num;
|
|
89
|
-
else return str;
|
|
68
|
+
// -009 => -9
|
|
69
|
+
return (n === parsedStr) || (sign+n === parsedStr) ? num : str
|
|
70
|
+
}else {
|
|
71
|
+
// +9
|
|
72
|
+
return (n === parsedStr) || (n === sign+parsedStr) ? num : str
|
|
90
73
|
}
|
|
91
|
-
|
|
92
|
-
if(trimmedStr === numStr) return num;
|
|
93
|
-
else if(trimmedStr === sign+numStr) return num;
|
|
94
|
-
// else{
|
|
95
|
-
// //number with +/- sign
|
|
96
|
-
// trimmedStr.test(/[-+][0-9]);
|
|
97
|
-
|
|
98
|
-
// }
|
|
99
|
-
return str;
|
|
100
74
|
}
|
|
101
|
-
// else if(!eNotation && trimmedStr && trimmedStr !== Number(trimmedStr) ) return str;
|
|
102
|
-
|
|
103
75
|
}else{ //non-numeric string
|
|
104
76
|
return str;
|
|
105
77
|
}
|
|
106
78
|
}
|
|
107
79
|
}
|
|
108
80
|
|
|
81
|
+
const eNotationRegx = /^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;
|
|
82
|
+
function resolveEnotation(str,trimmedStr,options){
|
|
83
|
+
if(!options.eNotation) return str;
|
|
84
|
+
const notation = trimmedStr.match(eNotationRegx);
|
|
85
|
+
if(notation){
|
|
86
|
+
let sign = notation[1] || "";
|
|
87
|
+
const eChar = notation[3].indexOf("e") === -1 ? "E" : "e";
|
|
88
|
+
const leadingZeros = notation[2];
|
|
89
|
+
const eAdjacentToLeadingZeros = sign ? // 0E.
|
|
90
|
+
str[leadingZeros.length+1] === eChar
|
|
91
|
+
: str[leadingZeros.length] === eChar;
|
|
92
|
+
|
|
93
|
+
if(leadingZeros.length > 1 && eAdjacentToLeadingZeros) return str;
|
|
94
|
+
else if(leadingZeros.length === 1
|
|
95
|
+
&& (notation[3].startsWith(`.${eChar}`) || notation[3][0] === eChar)){
|
|
96
|
+
return Number(trimmedStr);
|
|
97
|
+
}else if(options.leadingZeros && !eAdjacentToLeadingZeros){ //accept with leading zeros
|
|
98
|
+
//remove leading 0s
|
|
99
|
+
trimmedStr = (notation[1] || "") + notation[3];
|
|
100
|
+
return Number(trimmedStr);
|
|
101
|
+
}else return str;
|
|
102
|
+
}else{
|
|
103
|
+
return str;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
109
107
|
/**
|
|
110
108
|
*
|
|
111
109
|
* @param {string} numStr without leading zeros
|
|
@@ -116,9 +114,16 @@ function trimZeros(numStr){
|
|
|
116
114
|
numStr = numStr.replace(/0+$/, ""); //remove ending zeros
|
|
117
115
|
if(numStr === ".") numStr = "0";
|
|
118
116
|
else if(numStr[0] === ".") numStr = "0"+numStr;
|
|
119
|
-
else if(numStr[numStr.length-1] === ".") numStr = numStr.
|
|
117
|
+
else if(numStr[numStr.length-1] === ".") numStr = numStr.substring(0,numStr.length-1);
|
|
120
118
|
return numStr;
|
|
121
119
|
}
|
|
122
120
|
return numStr;
|
|
123
121
|
}
|
|
124
|
-
|
|
122
|
+
|
|
123
|
+
function parse_int(numStr, base){
|
|
124
|
+
//polyfill
|
|
125
|
+
if(parseInt) return parseInt(numStr, base);
|
|
126
|
+
else if(Number.parseInt) return Number.parseInt(numStr, base);
|
|
127
|
+
else if(window && window.parseInt) return window.parseInt(numStr, base);
|
|
128
|
+
else throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")
|
|
129
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import toNumber from "./strnum.js";
|
|
2
2
|
|
|
3
3
|
describe("Should convert all the valid numeric strings to number", () => {
|
|
4
4
|
it("should return undefined, null, empty string, or non-numeric as it is", () => {
|
|
@@ -6,6 +6,8 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
6
6
|
expect(toNumber(null)).toEqual(null);
|
|
7
7
|
expect(toNumber("")).toEqual("");
|
|
8
8
|
expect(toNumber("string")).toEqual("string");
|
|
9
|
+
expect(toNumber("e89794659669cb7bb967db73a7ea6889c3891727")).toEqual("e89794659669cb7bb967db73a7ea6889c3891727");
|
|
10
|
+
|
|
9
11
|
});
|
|
10
12
|
it("should not parse number with spaces or comma", () => {
|
|
11
13
|
expect(toNumber("12,12")).toEqual("12,12");
|
|
@@ -34,6 +36,14 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
34
36
|
expect(toNumber("JVBERi0xLjMNCiXi48")).toEqual("JVBERi0xLjMNCiXi48");
|
|
35
37
|
})
|
|
36
38
|
it("leading zeros", () => {
|
|
39
|
+
expect(toNumber("0")).toEqual(0);
|
|
40
|
+
expect(toNumber("00")).toEqual(0);
|
|
41
|
+
expect(toNumber("00.0")).toEqual(0);
|
|
42
|
+
|
|
43
|
+
expect(toNumber("0",{ leadingZeros : false})).toEqual(0);
|
|
44
|
+
expect(toNumber("00",{ leadingZeros : false})).toEqual("00");
|
|
45
|
+
expect(toNumber("00.0",{ leadingZeros : false})).toEqual("00.0");
|
|
46
|
+
|
|
37
47
|
expect(toNumber("06")).toEqual(6);
|
|
38
48
|
expect(toNumber("06", { leadingZeros : true})).toEqual(6);
|
|
39
49
|
expect(toNumber("06", { leadingZeros : false})).toEqual("06");
|
|
@@ -51,11 +61,12 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
51
61
|
expect(toNumber("20.21.030") ).toEqual("20.21.030");
|
|
52
62
|
expect(toNumber("0.21.030") ).toEqual("0.21.030");
|
|
53
63
|
expect(toNumber("0.21.") ).toEqual("0.21.");
|
|
54
|
-
expect(toNumber("0.") ).toEqual("0.");
|
|
55
|
-
expect(toNumber("1.") ).toEqual("1.");
|
|
56
64
|
});
|
|
57
65
|
it("floating point and leading zeros", () => {
|
|
58
|
-
expect(toNumber("0.
|
|
66
|
+
expect(toNumber("0.")).toEqual(0);
|
|
67
|
+
expect(toNumber("+0.")).toEqual(0);
|
|
68
|
+
expect(toNumber("-0.")).toEqual(-0);
|
|
69
|
+
expect(toNumber("1.") ).toEqual(1);
|
|
59
70
|
expect(toNumber("00.00")).toEqual(0);
|
|
60
71
|
expect(toNumber("0.06")).toEqual(0.06);
|
|
61
72
|
expect(toNumber("00.6")).toEqual(0.6);
|
|
@@ -84,6 +95,7 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
84
95
|
expect(toNumber("-.006")).toEqual(-0.006);
|
|
85
96
|
expect(toNumber("-6.0")).toEqual(-6);
|
|
86
97
|
expect(toNumber("-06.0")).toEqual(-6);
|
|
98
|
+
expect(toNumber("+06.0")).toEqual(6);
|
|
87
99
|
|
|
88
100
|
expect(toNumber("-0.0" , { leadingZeros : false})).toEqual(-0);
|
|
89
101
|
expect(toNumber("-00.00", { leadingZeros : false})).toEqual("-00.00");
|
|
@@ -108,10 +120,13 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
108
120
|
|
|
109
121
|
expect(toNumber("-1.0e2") ).toEqual(-100);
|
|
110
122
|
expect(toNumber("1.0e-2")).toEqual(0.01);
|
|
111
|
-
|
|
123
|
+
|
|
112
124
|
expect(toNumber("420926189200190257681175017717") ).toEqual(4.209261892001902e+29);
|
|
113
125
|
expect(toNumber("420926189200190257681175017717" , { eNotation: false} )).toEqual("420926189200190257681175017717");
|
|
114
|
-
|
|
126
|
+
|
|
127
|
+
expect(toNumber("1e-2")).toEqual(0.01);
|
|
128
|
+
expect(toNumber("1e+2")).toEqual(100);
|
|
129
|
+
expect(toNumber("1.e+2")).toEqual(100);
|
|
115
130
|
});
|
|
116
131
|
|
|
117
132
|
it("scientific notation with upper E", () => {
|
|
@@ -123,9 +138,17 @@ describe("Should convert all the valid numeric strings to number", () => {
|
|
|
123
138
|
|
|
124
139
|
expect(toNumber("-1.0E2") ).toEqual(-100);
|
|
125
140
|
expect(toNumber("1.0E-2")).toEqual(0.01);
|
|
141
|
+
|
|
142
|
+
expect(toNumber("E-2")).toEqual("E-2");
|
|
143
|
+
expect(toNumber("E2")).toEqual("E2");
|
|
144
|
+
expect(toNumber("0E2")).toEqual(0);
|
|
145
|
+
expect(toNumber("-0E2")).toEqual(-0);
|
|
146
|
+
expect(toNumber("00E2")).toEqual("00E2");
|
|
147
|
+
expect(toNumber("00E2", { leadingZeros : false})).toEqual("00E2");
|
|
126
148
|
});
|
|
127
149
|
|
|
128
150
|
it("should skip matching pattern", () => {
|
|
151
|
+
expect(toNumber("0", { skipLike: /.*/ })).toEqual("0");
|
|
129
152
|
expect(toNumber("+12", { skipLike: /\+[0-9]{10}/} )).toEqual(12);
|
|
130
153
|
expect(toNumber("12+12", { skipLike: /\+[0-9]{10}/} )).toEqual("12+12");
|
|
131
154
|
expect(toNumber("12+1212121212", { skipLike: /\+[0-9]{10}/} )).toEqual("12+1212121212");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import toNumber from "./strnum.js";
|
|
2
|
+
|
|
3
|
+
describe("Should convert all the valid numeric strings to number", () => {
|
|
4
|
+
it("should return undefined, null, empty string, or non-numeric as it is", () => {
|
|
5
|
+
// expect(toNumber("+ 90")).toEqual("+ 90");
|
|
6
|
+
// expect(toNumber("- 90")).toEqual("- 90");
|
|
7
|
+
expect(toNumber("-10E2")).toEqual(100);
|
|
8
|
+
});
|
|
9
|
+
});
|
package/package.json
CHANGED
|
File without changes
|