mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Adding type definitions for node-sass
This commit is contained in:
parent
8bc91d57f6
commit
cfc0247741
71
node-sass/node-sass-tests.ts
Normal file
71
node-sass/node-sass-tests.ts
Normal file
@ -0,0 +1,71 @@
|
||||
/// <reference path="node-sass.d.ts" />
|
||||
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;
|
||||
}
|
||||
56
node-sass/node-sass.d.ts
vendored
Normal file
56
node-sass/node-sass.d.ts
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
// Type definitions for Node Sass
|
||||
// Project: https://github.com/sass/node-sass
|
||||
// Definitions by: Asana <https://asana.com>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user