Skip to content

Commit 124f854

Browse files
committed
feat(typescript): added ts and move to jest
1 parent 8eb306a commit 124f854

26 files changed

+4280
-964
lines changed

.vscode/settings.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"files.associations": {
33
"*.twig": "twig",
44
"ios": "cpp",
5-
"vector": "cpp"
6-
}
7-
}
5+
"vector": "cpp",
6+
"iostream": "cpp"
7+
},
8+
"C_Cpp.errorSquiggles": "disabled"
9+
}

index.d.ts

Lines changed: 161 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,170 @@
1-
export enum XmlErrorLevel{
2-
/* No error */
3-
XML_ERR_NONE = 0,
4-
/* A simple warning */
5-
XML_ERR_WARNING = 1,
6-
/* A recoverable error */
7-
XML_ERR_ERROR = 2,
8-
/* A fatal error */
9-
XML_ERR_FATAL = 3
1+
export enum XmlErrorLevel {
2+
/* No error */
3+
XML_ERR_NONE = 0,
4+
/* A simple warning */
5+
XML_ERR_WARNING = 1,
6+
/* A recoverable error */
7+
XML_ERR_ERROR = 2,
8+
/* A fatal error */
9+
XML_ERR_FATAL = 3,
1010
}
1111

1212
export interface XmlError {
13-
message: string;
14-
level: XmlErrorLevel;
15-
column: number;
16-
file: string;
17-
line: number;
18-
int1: number;
13+
message: string;
14+
level: XmlErrorLevel;
15+
column: number;
16+
file: string;
17+
line: number;
18+
int1: number;
1919
}
2020

2121
export interface XmlDtdResult {
22-
name: string;
23-
externalId: string;
24-
systemId: string;
22+
name: string;
23+
externalId: string;
24+
systemId: string;
2525
}
2626

27-
declare class Libxml {
28-
/**
29-
* Loads an XML from a given URL which is generally a filepath
30-
* @param url The file to load from
31-
* @returns True if the load was successful and false otherwise. If failed than a property ```wellformedErrors``` appears
32-
* on the Libxml object and contains the errors. In case of success the property do not presented on the Libxml
33-
* object after this call.
34-
*/
35-
loadXml(url: string): boolean;
36-
37-
/**
38-
* Loads an XML from a string.
39-
* @param content The content of an XML
40-
* @returns True if the load was successful and false otherwise. If failed than a property ```wellformedErrors``` appears
41-
* on the Libxml object and contains the errors. In case of success the property do not presented on the Libxml
42-
* object after this call.
43-
*/
44-
loadXmlFromString(content: string): boolean;
45-
46-
/**
47-
* Loads DTDs. Silently drops elements from input array which are not strings
48-
* @param dtds The array which contains DTDs
49-
* @returns It has no return value but in case there were any error with any of the given DTDs than a property with name
50-
* ```dtdsLoadedErrors``` appears on the Libxml object. If load was successful than no such property presented
51-
* REMARKS:
52-
* * Can call multiple time and all correct will be stored.
53-
* * Can load same DTD multiple time but has no good use just increase memory consumption.
54-
*/
55-
loadDtds(dtds: string[]): void;
56-
57-
/**
58-
* Loads schemas. Silently drops elements from input array which are not strings
59-
* @param schemas The schemas to load
60-
* @returns It has no return value but in case there were any error with any of the given schemas than a property with name
61-
* ```schemasLoadedErrors``` appears on the Libxml object. There will be no such property presented on successful load.
62-
*/
63-
loadSchemas(schemas: string[]): void;
64-
65-
/**
66-
* Validate loaded XML against loaded DTDs
67-
* @param maxErrorNumber The maximum number of errors that should collected and returned on a dtd per basis.
68-
* @returns
69-
* * ```null``` if not any DTDs loaded correctly at all. (No load at all or all of it was wrong)
70-
* * A string which is the name of the DTD if it has any name
71-
* * True if the DTD against which it is matched has no name. (No SystemID presented)
72-
* * False otherwise and a property with name ```validationDtdErrors``` appears on Libxml object
73-
*
74-
* REMARKS:
75-
* * In case of successful load (When return with a string or true) no property with name ```validationDtdErrors```
76-
* will be presented on the Libxml object
77-
* * In case of ```null``` return value ```validationDtdErrors``` property will remain as it was
78-
*/
79-
validateAgainstDtds(maxErrorNumber?: number): null | boolean | string;
80-
81-
/**
82-
* Validate loaded XML against loaded schemas
83-
* @param maxErrorNumber The maximum number of errors that should collected and returned on a schema per basis.
84-
* @returns
85-
* * ```null``` if not any schemas loaded correctly at all. (No load at all or all of it was wrong)
86-
* * A string which is the name of the schema if it has any name
87-
* * True if the schema against which it is matched has no name. (No URL presented in doc)
88-
* * False otherwise and a property with name ```validationSchemaErrors``` appears on Libxml object
89-
*
90-
* REMARKS:
91-
* * In case of successful load (When return with a string or true) no property with name ```validationSchemaErrors```
92-
* will be presented on the Libxml object
93-
* * In case of ```null``` return value ```validationSchemaErrors``` property will remain as it was
94-
*/
95-
validateAgainstSchemas(maxErrorNumber?: number): null | boolean | string;
96-
97-
/**
98-
* Evaluate an xPath on a previously loaded XML.
99-
* @param selector The xPath selector
100-
* @returns
101-
* * ```null``` if no match found
102-
* * boolean OR string OR number value if matched.
103-
* @throws
104-
* * If not given any param
105-
* * If exception happens during evaluation
106-
*/
107-
xpathSelect(selector: string): null | boolean | number | string;
108-
109-
/**
110-
* Get data from the loaded XML
111-
* @returns
112-
* * ```null``` if no XML loaded or it has no such data
113-
* * An object if valid XML loaded. Although it could has all property value ```null```
114-
*/
115-
getDtd(): null | XmlDtdResult;
116-
117-
/**
118-
* Drops memory correlated with the loaded XML.
119-
*
120-
* Also delete property ```wellformedErrors``` from Libxml object
121-
*/
122-
freeXml(): void;
123-
124-
/**
125-
* Drop memory correlated with loaded DTDs.
126-
*
127-
* Also delete property ```dtdsLoadedErrors``` and ```validationDtdErrors``` from the Libxml object
128-
*/
129-
freeDtds(): void;
130-
131-
/**
132-
* Drop memory correlated with loaded schemas.
133-
*
134-
* Also delete property ```schemasLoadedErrors``` and ```validationSchemasErrors``` from the Libxml object
135-
*/
136-
freeSchemas(): void;
137-
138-
/**
139-
* Free up all memory used by the lib.
140-
*
141-
* Also drops all properties of the Libxml object
142-
* * ```wellformedErrors```
143-
* * ```dtdsLoadedErrors``` and ```validationDtdErrors```
144-
* * ```schemasLoadedErrors``` and ```validationSchemasErrors```
145-
*/
146-
clearAll(): void;
147-
148-
/**
149-
* @returns The maximum number of error which will be stores
150-
*/
151-
getMaxErrorNumber(): number;
152-
153-
/**
154-
* Sets the maximum number of error which wil be stored.
155-
*
156-
* The default value is 100
157-
*
158-
* @param max The desired max number
159-
* @returns The actual number set.
160-
* In case if it was not a number or if it is too big maybe you got other result as expected.
161-
* If param was not a number or non positive than max number will not change.
162-
*/
163-
setMaxErrorNumber(max: number): number;
164-
165-
wellformedErrors?: (XmlError)[];
166-
dtdsLoadedErrors?: (string | XmlError)[];
167-
schemasLoadedErrors?: (string | XmlError)[];
168-
validationDtdErrors?: Record<string/*SystemId*/, XmlError[]>;
169-
validationSchemaErrors?: Record<string/*SchemaName*/, XmlError[]>;
27+
export class Libxml {
28+
/**
29+
* Loads an XML from a given URL which is generally a filepath
30+
* @param url The file to load from
31+
* @returns True if the load was successful and false otherwise. If failed than a property ```wellformedErrors``` appears
32+
* on the Libxml object and contains the errors. In case of success the property do not presented on the Libxml
33+
* object after this call.
34+
*/
35+
loadXml(url: string): boolean;
36+
37+
/**
38+
* Loads an XML from a string.
39+
* @param content The content of an XML
40+
* @returns True if the load was successful and false otherwise. If failed than a property ```wellformedErrors``` appears
41+
* on the Libxml object and contains the errors. In case of success the property do not presented on the Libxml
42+
* object after this call.
43+
*/
44+
loadXmlFromString(content: string): boolean;
45+
46+
/**
47+
* Loads DTDs. Silently drops elements from input array which are not strings
48+
* @param dtds The array which contains DTDs
49+
* @returns It has no return value but in case there were any error with any of the given DTDs than a property with name
50+
* ```dtdsLoadedErrors``` appears on the Libxml object. If load was successful than no such property presented
51+
* REMARKS:
52+
* * Can call multiple time and all correct will be stored.
53+
* * Can load same DTD multiple time but has no good use just increase memory consumption.
54+
*/
55+
loadDtds(dtds: string[]): void;
56+
57+
/**
58+
* Loads schemas. Silently drops elements from input array which are not strings
59+
* @param schemas The schemas to load
60+
* @returns It has no return value but in case there were any error with any of the given schemas than a property with name
61+
* ```schemasLoadedErrors``` appears on the Libxml object. There will be no such property presented on successful load.
62+
*/
63+
loadSchemas(schemas: string[]): void;
64+
65+
/**
66+
* Validate loaded XML against loaded DTDs
67+
* @param maxErrorNumber The maximum number of errors that should collected and returned on a dtd per basis.
68+
* @returns
69+
* * ```null``` if not any DTDs loaded correctly at all. (No load at all or all of it was wrong)
70+
* * A string which is the name of the DTD if it has any name
71+
* * True if the DTD against which it is matched has no name. (No SystemID presented)
72+
* * False otherwise and a property with name ```validationDtdErrors``` appears on Libxml object
73+
*
74+
* REMARKS:
75+
* * In case of successful load (When return with a string or true) no property with name ```validationDtdErrors```
76+
* will be presented on the Libxml object
77+
* * In case of ```null``` return value ```validationDtdErrors``` property will remain as it was
78+
*/
79+
validateAgainstDtds(maxErrorNumber?: number): null | boolean | string;
80+
81+
/**
82+
* Validate loaded XML against loaded schemas
83+
* @param maxErrorNumber The maximum number of errors that should collected and returned on a schema per basis.
84+
* @returns
85+
* * ```null``` if not any schemas loaded correctly at all. (No load at all or all of it was wrong)
86+
* * A string which is the name of the schema if it has any name
87+
* * True if the schema against which it is matched has no name. (No URL presented in doc)
88+
* * False otherwise and a property with name ```validationSchemaErrors``` appears on Libxml object
89+
*
90+
* REMARKS:
91+
* * In case of successful load (When return with a string or true) no property with name ```validationSchemaErrors```
92+
* will be presented on the Libxml object
93+
* * In case of ```null``` return value ```validationSchemaErrors``` property will remain as it was
94+
*/
95+
validateAgainstSchemas(maxErrorNumber?: number): null | boolean | string;
96+
97+
/**
98+
* Evaluate an xPath on a previously loaded XML.
99+
* @param selector The xPath selector
100+
* @returns
101+
* * ```null``` if no match found
102+
* * boolean OR string OR number value if matched.
103+
* @throws
104+
* * If not given any param
105+
* * If exception happens during evaluation
106+
*/
107+
xpathSelect(selector: string): null | boolean | number | string;
108+
109+
/**
110+
* Get data from the loaded XML
111+
* @returns
112+
* * ```null``` if no XML loaded or it has no such data
113+
* * An object if valid XML loaded. Although it could has all property value ```null```
114+
*/
115+
getDtd(): null | XmlDtdResult;
116+
117+
/**
118+
* Drops memory correlated with the loaded XML.
119+
*
120+
* Also delete property ```wellformedErrors``` from Libxml object
121+
*/
122+
freeXml(): void;
123+
124+
/**
125+
* Drop memory correlated with loaded DTDs.
126+
*
127+
* Also delete property ```dtdsLoadedErrors``` and ```validationDtdErrors``` from the Libxml object
128+
*/
129+
freeDtds(): void;
130+
131+
/**
132+
* Drop memory correlated with loaded schemas.
133+
*
134+
* Also delete property ```schemasLoadedErrors``` and ```validationSchemasErrors``` from the Libxml object
135+
*/
136+
freeSchemas(): void;
137+
138+
/**
139+
* Free up all memory used by the lib.
140+
*
141+
* Also drops all properties of the Libxml object
142+
* * ```wellformedErrors```
143+
* * ```dtdsLoadedErrors``` and ```validationDtdErrors```
144+
* * ```schemasLoadedErrors``` and ```validationSchemasErrors```
145+
*/
146+
clearAll(): void;
147+
148+
/**
149+
* @returns The maximum number of error which will be stores
150+
*/
151+
getMaxErrorNumber(): number;
152+
153+
/**
154+
* Sets the maximum number of error which wil be stored.
155+
*
156+
* The default value is 100
157+
*
158+
* @param max The desired max number
159+
* @returns The actual number set.
160+
* In case if it was not a number or if it is too big maybe you got other result as expected.
161+
* If param was not a number or non positive than max number will not change.
162+
*/
163+
setMaxErrorNumber(max: number): number;
164+
165+
wellformedErrors?: XmlError[];
166+
dtdsLoadedErrors?: (string | XmlError)[];
167+
schemasLoadedErrors?: (string | XmlError)[];
168+
validationDtdErrors?: Record<string /*SystemId*/, XmlError[]>;
169+
validationSchemaErrors?: Record<string /*SchemaName*/, XmlError[]>;
170170
}
171-
172-
export = Libxml;

index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ts-expect-error
2+
import binding from "node-gyp-build";
3+
export const Libxml = binding(__dirname).Libxml;

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)