Updated documentation on clean-css type definitions

Change Array<string> to string[] as part of P&P update
Removed empty constructor as existing constructor meets requirement
Removed unneeded testing file
This commit is contained in:
Andrew Potter 2019-01-24 10:25:08 -07:00
parent ec27f386ec
commit 284308ed72
3 changed files with 17 additions and 67 deletions

View File

@ -1,54 +0,0 @@
import * as CleanCSS from 'clean-css';
var source = 'a{font-weight:bold;}';
var minified = new CleanCSS().minify(source).styles;
var source = '@import url(http://path/to/remote/styles);';
new CleanCSS().minify(source, function (error, minified) {
console.log(minified.styles);
});
const pathToOutputDirectory = 'path';
new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory })
.minify(source, function (error, minified) {
// access minified.sourceMap for SourceMapGenerator object
// see https://github.com/mozilla/source-map/#sourcemapgenerator for more details
// see https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L114 on how it's used in clean-css' CLI
console.log(minified.sourceMap);
});
const inputSourceMapAsString = 'input';
new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory })
.minify(source, inputSourceMapAsString, function (error, minified) {
// access minified.sourceMap to access SourceMapGenerator object
// see https://github.com/mozilla/source-map/#sourcemapgenerator for more details
// see https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L114 on how it's used in clean-css' CLI
console.log();
});
new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }).minify({
'path/to/source/1': {
styles: '...styles...',
sourceMap: '...source-map...'
},
'path/to/source/2': {
styles: '...styles...',
sourceMap: '...source-map...'
}
}, function (error, minified) {
// access minified.sourceMap as above
console.log(minified.sourceMap);
});
new CleanCSS().minify(['path/to/file/one', 'path/to/file/two']);
new CleanCSS().minify({
'path/to/file/one': {
styles: 'contents of file one'
},
'path/to/file/two': {
styles: 'contents of file two'
}
});

View File

@ -13,17 +13,19 @@ declare namespace CleanCSS {
*/
interface Options {
/**
* Controls compatibility mode used; defaults to ie10+ using `'*'`
* Controls compatibility mode used; defaults to ie10+ using `'*'`.
* Compatibility hash exposes the following properties: `colors`, `properties`, `selectors`, and `units`
*/
compatibility?: "*" | "ie9" | "ie8" | "ie7" | CompatibilityOptions;
/**
* Controls a function for handling remote requests; Defaults to the build in `loadRemoteResource` function
*/
fetch?: (uri: string, inlineRequest: HttpRequestOptions | HttpsRequestOptions, inlineTimeout: number, callback: FetchCallback) => void;
fetch?: (uri: string, inlineRequest: HttpRequestOptions | HttpsRequestOptions, inlineTimeout: number, done: (message: string | number, body: string) => void) => void;
/**
* Controls output CSS formatting; defaults to `false`
* Controls output CSS formatting; defaults to `false`.
* Format hash exposes the following properties: `breaks`, `breakWith`, `indentBy`, `indentWith`, `spaces`, and `wrapAt`.
*/
format?: "beautify" | "keep-breaks" | Format | false;
@ -50,7 +52,8 @@ declare namespace CleanCSS {
inlineTimeout?: number;
/**
* Controls optimization level used; defaults to `1`
* Controls optimization level used; defaults to `1`.
* Level hash exposes `1`, and `2`.
*/
level?: 0 | 1 | 2 | optimizationsOptions;
@ -98,12 +101,12 @@ declare namespace CleanCSS {
/**
* A list of errors raised
*/
errors: Array<string>;
errors: string[];
/**
* A list of warnings raised
*/
warnings: Array<string>;
warnings: string[];
/**
* Contains statistics on the minify process
@ -516,7 +519,7 @@ declare namespace CleanCSS {
/**
* Defines a callback for fine-grained property optimization; defaults to no-op
*/
transform?: (propertyName: string, propertyValue: string, selector: string) => string;
transform?: (propertyName: string, propertyValue: string, selector?: string) => string;
},
2?: {
/**
@ -602,7 +605,7 @@ declare namespace CleanCSS {
type FetchCallback = (message: string | number, body: string) => void;
/**
*
* Interface exposed when a new CleanCSS option is created
*/
interface Function<T extends (Output | Promise<Output>)> {
minify(sources: string | Array<string> | Object, callback?: (error: any, output: T) => void): T;
@ -610,15 +613,17 @@ declare namespace CleanCSS {
minify(sources: string | Array<string> | Object, inputSourceMap?: string, callback?: (error: any, output: T) => void): T;
}
/**
* Constructor interface for CleanCSS
*/
interface Constructor {
new(options: CleanCSS.Options & { returnPromise?: false }): Function<Output>;
new(options: CleanCSS.Options & { returnPromise: true }): Function<Promise<Output>>;
new(): Function<Output>;
new(options?: CleanCSS.Options): Function<Output>;
}
}
/**
*
* Creates a new CleanCSS object
*/
declare const CleanCSS: CleanCSS.Constructor;

View File

@ -18,7 +18,6 @@
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"clean-css-tests.ts"
"index.d.ts"
]
}