diff --git a/node-sass/node-sass-tests.ts b/node-sass/node-sass-tests.ts new file mode 100644 index 0000000000..a7c1477cb9 --- /dev/null +++ b/node-sass/node-sass-tests.ts @@ -0,0 +1,71 @@ +/// +import sass = require('node-sass'); +sass.render({ + file: '/path/to/myFile.scss', + data: 'body{background:blue; a{color:black;}}', + importer: function(url, prev, done) { + // url is the path in import as is, which libsass encountered. + // prev is the previously resolved path. + // done is an optional callback, either consume it or return value synchronously. + // this.options contains this options hash, this.callback contains the node-style callback + someAsyncFunction(url, prev, function(result) { + done({ + file: result.path, // only one of them is required, see section Sepcial Behaviours. + contents: result.data + }); + }); + // OR + var result = someSyncFunction(url, prev); + return { file: result.path, contents: result.data }; + }, + includePaths: ['lib/', 'mod/'], + outputStyle: 'compressed' +}, function(error, result) { // node-style callback from v3.0.0 onwards + if (error) { + console.log(error.status); // used to be "code" in v2x and below + console.log(error.column); + console.log(error.message); + console.log(error.line); + } + else { + console.log(result.css.toString()); + + console.log(result.stats); + + console.log(result.map.toString()); + // or better + console.log(JSON.stringify(result.map)); // note, JSON.stringify accepts Buffer too + } +}); +// OR +var result = sass.renderSync({ + file: '/path/to/file.scss', + data: 'body{background:blue; a{color:black;}}', + outputStyle: 'compressed', + outFile: '/to/my/output.css', + sourceMap: true, // or an absolute or relative (to outFile) path + importer: function(url, prev, done) { + // url is the path in import as is, which libsass encountered. + // prev is the previously resolved path. + // done is an optional callback, either consume it or return value synchronously. + // this.options contains this options hash + someAsyncFunction(url, prev, function(result) { + done({ + file: result.path, // only one of them is required, see section Sepcial Behaviours. + contents: result.data + }); + }); + // OR + var result = someSyncFunction(url, prev); + return { file: result.path, contents: result.data }; + }, +}); + +console.log(result.css); +console.log(result.map); +console.log(result.stats); + +function someAsyncFunction(url: string, prev: string, callback: (result: { path: string; data: string }) => void): void {} +function someSyncFunction(url: string, prev: string): { path: string; data: string} { + return null; +} diff --git a/node-sass/node-sass.d.ts b/node-sass/node-sass.d.ts new file mode 100644 index 0000000000..09ea71d4e0 --- /dev/null +++ b/node-sass/node-sass.d.ts @@ -0,0 +1,56 @@ +// Type definitions for Node Sass +// Project: https://github.com/sass/node-sass +// Definitions by: Asana +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "node-sass" { + interface Importer { + (url: string, prev: string, done: (data: { file: string; contents: string; }) => void): void; + } + + interface Options { + file?: string; + data?: string; + importer?: Importer | Importer[]; + functions?: { [key: string]: Function }; + includePaths?: string[]; + indentedSyntax?: boolean; + indentType?: string; + indentWidth?: number; + linefeed?: string; + omitSourceMapUrl?: boolean; + outFile?: string; + outputStyle?: string; + precision?: number; + sourceComments?: boolean; + sourceMap?: boolean | string; + sourceMapContents?: boolean; + sourceMapEmbed?: boolean; + sourceMapRoot?: boolean; + } + + interface SassError extends Error { + message: string; + line: number; + column: number; + status: number; + file: string; + } + + interface Result { + css: Buffer; + map: Buffer; + stats: { + entry: string; + start: number; + end: number; + duration: number; + includedFiles: string[]; + } + } + + export function render(options: Options, callback: (err: SassError, result: Result) => any): void; + export function renderSync(options: Options): Result; +}