Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make optional options optional in typings and add type tests #622

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .publishrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"confirm": true,
"publishCommand": "npm publish",
"publishTag": "latest",
"prePublishScript": "npm test",
"prePublishScript": "npm test && npm test-types",
"postPublishScript": false
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "./src/fxp.js",
"scripts": {
"test": "nyc --reporter=lcov --reporter=text jasmine spec/*spec.js",
"test-types": "tsc --noEmit spec/typings/typings-test.ts",
"unit": "jasmine",
"coverage": "nyc report --reporter html --reporter text -t .nyc_output --report-dir .nyc_output/summary",
"perf": "node ./benchmark/perfTest3.js",
Expand Down Expand Up @@ -46,6 +47,7 @@
"@babel/plugin-transform-runtime": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/register": "^7.13.8",
"@types/node": "20",
"babel-loader": "^8.2.2",
"cytorus": "^0.2.9",
"eslint": "^8.3.0",
Expand All @@ -54,6 +56,7 @@
"nyc": "^15.1.0",
"prettier": "^1.19.1",
"publish-please": "^5.5.2",
"typescript": "5",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
},
Expand Down
47 changes: 47 additions & 0 deletions spec/typings/typings-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {
XMLParser,
XMLBuilder,
XMLValidator,
type X2jOptions,
type XmlBuilderOptions,
type validationOptions,
} from '../../src/fxp';

const parseOpts: X2jOptions = {};

const XML = `
<?xml version="1.0"?>
<SomeElement name="parent">
<SomeNestedElement name="child"></SomeNestedElement>
</SomeElement>
`;

const parser = new XMLParser(parseOpts);
const parsed = parser.parse(XML);

console.log(!!parsed);

const buildOpts: XmlBuilderOptions = {};

const builder = new XMLBuilder(buildOpts);

const built = builder.build({
any_name: {
person: {
phone: [
15555551313,
15555551212
]
}
}
});

console.log(!!built);

const validateOpts: validationOptions = {};

const isValid = XMLValidator.validate(built, validateOpts);

console.log(!!isValid);