From 651153e509713f812544e482ca0dfdc6c3151303 Mon Sep 17 00:00:00 2001 From: Bart van der Schoor Date: Tue, 1 Apr 2014 00:21:49 +0200 Subject: [PATCH] added definitions for js-yaml --- README.md | 1 + js-yaml/js-yaml-tests.ts | 84 ++++++++++++++++++++++++++++++++++++++++ js-yaml/js-yaml.d.ts | 48 +++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 js-yaml/js-yaml-tests.ts create mode 100644 js-yaml/js-yaml.d.ts diff --git a/README.md b/README.md index b2149c5cb..02fa53fba 100755 --- a/README.md +++ b/README.md @@ -166,6 +166,7 @@ List of Definitions * [jQuery.Watermark](http://jquery-watermark.googlecode.com) (by [Anwar Javed](https://github.com/anwarjaved)) * [jQuery.base64](https://github.com/yatt/jquery.base64) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) * [js-git](https://github.com/creationix/js-git) (by [Bart van der Schoor](https://github.com/Bartvds)) +* [js-yaml](https://github.com/nodeca/js-yaml) (by [Bart van der Schoor](https://github.com/Bartvds/)) * [jScrollPane](http://jscrollpane.kelvinluck.com) (by [Dániel Tar](https://github.com/qcz)) * [JSDeferred](http://cho45.stfuawsc.com/jsdeferred/) (by [Daisuke Mino](https://github.com/minodisk)) * [JSONEditorOnline](https://github.com/josdejong/jsoneditoronline) (by [Vincent Bortone](https://github.com/vbortone/)) diff --git a/js-yaml/js-yaml-tests.ts b/js-yaml/js-yaml-tests.ts new file mode 100644 index 000000000..91596b756 --- /dev/null +++ b/js-yaml/js-yaml-tests.ts @@ -0,0 +1,84 @@ +/// + +import yaml = require('js-yaml'); +import LoadOptions = yaml.LoadOptions; +import DumpOptions = yaml.DumpOptions; + +var bool: boolean; +var num: number; +var str: string; +var obj: Object; +var value: any; + +var loadOpts: LoadOptions; +var dumpOpts: DumpOptions; + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +yaml.FAILSAFE_SCHEMA; +yaml.JSON_SCHEMA; +yaml.CORE_SCHEMA; +yaml.DEFAULT_SAFE_SCHEMA; +yaml.DEFAULT_FULL_SCHEMA; + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +loadOpts = { + filename: str +}; +loadOpts = { + strict: bool +}; +loadOpts = { + schema: bool +}; + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +dumpOpts = { + indent: num +}; +dumpOpts = { + skipInvalid: bool +}; +dumpOpts = { + flowLevel: num +}; +dumpOpts = { + styles: obj +}; +dumpOpts = { + schema: value +}; + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +value = yaml.safeLoad(str); +value = yaml.safeLoad(str, loadOpts); + +value = yaml.load(str); +value = yaml.load(str, loadOpts); + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +value = yaml.safeLoadAll(str, (doc) => { + value = doc; +}); +value = yaml.safeLoadAll(str, (doc) => { + value = doc; +}, loadOpts); + +value = yaml.loadAll(str, (doc) => { + value = doc; +}); +value = yaml.loadAll(str, (doc) => { + value = doc; +}, loadOpts); + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +value = yaml.safeDump(str); +value = yaml.safeDump(str, dumpOpts); + +value = yaml.dump(str); +value = yaml.dump(str, dumpOpts); diff --git a/js-yaml/js-yaml.d.ts b/js-yaml/js-yaml.d.ts new file mode 100644 index 000000000..0607b4891 --- /dev/null +++ b/js-yaml/js-yaml.d.ts @@ -0,0 +1,48 @@ +// Type definitions for js-yaml 3.0.2 +// Project: https://github.com/nodeca/js-yaml +// Definitions by: Bart van der Schoor +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module 'js-yaml' { + export function safeLoad(str: string, opts?: LoadOptions): any; + export function load(str: string, opts?: LoadOptions): any; + + export function safeLoadAll(str: string, iterator: (doc: any) => void, opts?: LoadOptions): any; + export function loadAll(str: string, iterator: (doc: any) => void, opts?: LoadOptions): any; + + export function safeDump(obj: any, opts?: DumpOptions): string; + export function dump(obj: any, opts?: DumpOptions): string + + export interface LoadOptions { + // string to be used as a file path in error/warning messages. + filename?: string; + // makes the loader to throw errors instead of warnings. + strict?: boolean; + // specifies a schema to use. + schema?: any; + } + + export interface DumpOptions { + // indentation width to use (in spaces). + indent?: number; + // do not throw on invalid types (like function in the safe schema) and skip pairs and single values with such types. + skipInvalid?: boolean; + // specifies level of nesting, when to switch from block to flow style for collections. -1 means block style everwhere + flowLevel?: number; + // Each tag may have own set of styles. - "tag" => "style" map. + styles?: Object; + // specifies a schema to use. + schema?: any; + } + + // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 + export var FAILSAFE_SCHEMA: any; + // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 + export var JSON_SCHEMA: any; + // same as JSON_SCHEMA: http://www.yaml.org/spec/1.2/spec.html#id2804923 + export var CORE_SCHEMA: any; + // all supported YAML types, without unsafe ones (!!js/undefined, !!js/regexp and !!js/function): http://yaml.org/type/ + export var DEFAULT_SAFE_SCHEMA: any; + // all supported YAML types. + export var DEFAULT_FULL_SCHEMA: any; +}