Skip to content

Commit

Permalink
Add files
Browse files Browse the repository at this point in the history
  • Loading branch information
microshine committed Sep 30, 2018
1 parent e93b686 commit 67d1bab
Show file tree
Hide file tree
Showing 24 changed files with 2,993 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,41 @@
version: 2
jobs:
build:
working_directory: ~/mern-starter # directory where steps will run
docker: # run the steps with Docker
- image: circleci/node:8.11.3
steps:
- checkout
- run:
name: update-npm
command: 'sudo npm install -g npm@latest'
- run:
name: install-typescript
command: sudo npm install -g typescript@latest
- run:
name: install-tslint
command: sudo npm install -g tslint@latest
- run:
name: install-coveralls
command: sudo npm install -g coveralls@latest
- run:
name: install-nyc
command: sudo npm install -g nyc@latest
- restore_cache: # special step to restore the dependency cache
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: install-deps
command: npm install
- save_cache: # special step to save the dependency cache
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run: # run tslint
name: test-code-coverage
command: npm run lint
- run: # run tests with code coverage
name: test-code-coverage
command: npm run coverage
- run: # run coveralls report
name: test-report-coveralls
command: npm run coveralls
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
.vscode/
build/
node_modules/

# coverage
.nyc_output/
coverage/

# Mac
.DS_Store
15 changes: 15 additions & 0 deletions .npmignore
@@ -0,0 +1,15 @@
.vscode/
test/
src/

# config files
rollup.config.js
tsconfig.json
tslint.json

# coverage
.nyc_output/
coverage/

# ci
.circleci/
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -17,7 +17,7 @@ This is important because validating input data before its use is important to d
Installation is handled via `npm`:

```
$ npm install xml-schema
$ npm install @pv/xml-schema
```

## Examples
Expand Down
93 changes: 93 additions & 0 deletions index.d.ts
@@ -0,0 +1,93 @@
declare namespace XmlSchema {

interface IEmptyConstructor<T> {
new(): T;
}

type XmlParseType = Document | Element;

interface IXmlConverter<Type, XmlType = any> {
fromXML(value: XmlType, target: any): Type;
toXML(value: Type, target: any): XmlType;
}

type IXmlAttributeConverter<T = any> = IXmlConverter<T, string>;
type IXmlContentConverter<T = any> = IXmlConverter<T, string | null>;
type IXmlItemConverter<T = any> = IXmlConverter<T, string | null>;

interface IXmlConvertible {
fromXML(xml: Element): this;
toXML(): Element;
}

interface IXmlNamespaces {
[prefix: string]: string;
}

interface IXmlSerializerOptions {
name?: string;
prefix?: string;
namespaces?: IXmlNamespaces;
}

class XmlParser {
public static parse<T>(data: string, schema: IEmptyConstructor<T>): T;
public static fromXML<T>(target: XmlParseType, targetSchema: IEmptyConstructor<T>): T;
}

class XmlSerializer {
public static serialize(obj: any, options?: IXmlSerializerOptions): string;
public static toXML(obj: any, options?: IXmlSerializerOptions): Element;
}

interface IXmlElementOptions {
/**
* type of child element
* - if value is empty, then child element is simple, use textContent from it
* - if type is not empty, then use it's schema
*/
type?: IEmptyConstructor<any>;
optional?: boolean;
defaultValue?: any;
converter?: IXmlConverter<any, any>;
repeated?: boolean;
name?: string;
prefix?: string;
namespace?: string;
}

interface IXmlAttributeOptions {
optional?: boolean;
defaultValue?: any;
converter?: IXmlAttributeConverter;
name?: string;
prefix?: string;
namespace?: string;
}

interface IXmlTypeOptions {
name?: string;
prefix?: string;
namespace?: string;
}

interface IXmlContentOptions {
converter?: IXmlConverter<any, any>;
}

const XmlType: (options?: IXmlTypeOptions) => ClassDecorator;
const XmlAttribute: (options?: IXmlAttributeOptions) => PropertyDecorator;
const XmlElement: (options?: IXmlElementOptions) => PropertyDecorator;
const XmlContent: (options?: IXmlContentOptions) => PropertyDecorator;

const XmlStringConverter: IXmlConverter<string, string>;
const XmlBooleanConverter: IXmlConverter<boolean, string>;
const XmlHexBinaryConverter: IXmlConverter<ArrayBuffer, string>;
const XmlBase64Converter: IXmlConverter<ArrayBuffer, string>;
const XmlIntegerNumberConverter: IXmlConverter<number, string>;
const XmlFloatNumberConverter: IXmlConverter<number, string>;
const XmlDateTimeConverter: IXmlConverter<Date, string>;

}

export = XmlSchema;

0 comments on commit 67d1bab

Please sign in to comment.