mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
Fix conflicts
This commit is contained in:
@@ -1,147 +0,0 @@
|
||||
const {get} = require('https')
|
||||
const {readdir, readFile, writeFile} = require('fs')
|
||||
const {join, extname, basename, dirname, relative} = require('path')
|
||||
|
||||
const token = process.env.GITHUB_ACCESS_TOKEN || ''
|
||||
|
||||
const toMixedCase = (name) => {
|
||||
let dist = name[0].toUpperCase()
|
||||
for (let i = 1; i < name.length; i++) {
|
||||
const c = name[i]
|
||||
if (c !== '-') {
|
||||
dist += c
|
||||
continue
|
||||
}
|
||||
i++
|
||||
dist += name[i].toUpperCase()
|
||||
}
|
||||
return dist
|
||||
}
|
||||
|
||||
const github = (path) => new Promise((resolve, reject) => {
|
||||
get({
|
||||
headers: {'user-agent': 'DefinitelyTyped/material-ui/generate'},
|
||||
host: 'api.github.com',
|
||||
path,
|
||||
}, (res) => {
|
||||
if ((res.statusCode / 100 >> 0) != 2) {
|
||||
reject(`GitHub response: ${res.statusCode} ${res.statusMessage}`)
|
||||
return
|
||||
}
|
||||
let data = '';
|
||||
res
|
||||
.on('data', (chunk) => data += chunk)
|
||||
.on('end', () => resolve(JSON.parse(data)))
|
||||
}).on('error', reject)
|
||||
})
|
||||
|
||||
const categories = () => github(`/repos/callemall/material-ui/contents/src/svg-icons?ref=master&access_token=${token}`)
|
||||
|
||||
const contents = (path) => github(`/repos/callemall/material-ui/contents/${path}?ref=master&access_token=${token}`)
|
||||
|
||||
const collator = new Intl.Collator()
|
||||
|
||||
const resolvePath = (filename) => join(__dirname, '../../types/material-ui', filename)
|
||||
|
||||
const readText = (filename) => new Promise((resolve, reject) => {
|
||||
readFile(resolvePath(filename), 'utf8', (err, data) => {
|
||||
if (err != null) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
resolve(data)
|
||||
})
|
||||
})
|
||||
|
||||
const writeText = (filename, text) => new Promise((resolve, reject) => {
|
||||
writeFile(resolvePath(filename), text, 'utf8', (err) => {
|
||||
if (err != null) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
|
||||
const inject = (content) => {
|
||||
content.category = this.name
|
||||
return content
|
||||
}
|
||||
|
||||
const rMark = /(\/{2} \{{3})[\s\S]*?(\/{2} \}{3})/g
|
||||
|
||||
categories()
|
||||
.then((cats) => Promise.all(Array.prototype.map.call(cats, (cat) => contents(cat.path)
|
||||
.then((cons) => Array.prototype.map.call(cons, (con) => {
|
||||
con.category = cat.name
|
||||
return con
|
||||
}))
|
||||
)))
|
||||
.then((contentsList) => Array.prototype.concat.apply([], contentsList)
|
||||
.map((content) => {
|
||||
const {path} = content
|
||||
const name = basename(path, extname(path))
|
||||
content.id = join(relative('src', dirname(path)), name)
|
||||
content.className = toMixedCase(content.category) + toMixedCase(name)
|
||||
return content
|
||||
})
|
||||
.sort((a, b) => collator.compare(a.id, b.id))
|
||||
.reduce((prev, content) => {
|
||||
const {dts, test} = prev
|
||||
dts.individuals.push(`declare module 'material-ui/${content.id}' {
|
||||
export import ${content.className} = __MaterialUI.SvgIcon;
|
||||
export default ${content.className};
|
||||
}`)
|
||||
dts.summarizeds.push(` export import ${content.className} = __MaterialUI.SvgIcon; // require('material-ui/${content.id}');`)
|
||||
|
||||
test.individuals.push(`import _${content.className} from 'material-ui/${content.id}';`)
|
||||
test.summarizeds.push(` ${content.className},`)
|
||||
return prev
|
||||
}, {
|
||||
dts: {individuals: [], summarizeds: []},
|
||||
test: {individuals: [], summarizeds: []},
|
||||
})
|
||||
)
|
||||
.then(({dts, test}) => {
|
||||
return Promise.all([
|
||||
(() => {
|
||||
const {individuals, summarizeds} = dts
|
||||
const file = 'index.d.ts'
|
||||
let index = 0
|
||||
return readText(file)
|
||||
.then((script) => writeText(file, script.replace(rMark, (_, p1, p2) => {
|
||||
let text = ''
|
||||
switch (index) {
|
||||
case 0:
|
||||
text = individuals.join('\n\n')
|
||||
break
|
||||
case 1:
|
||||
text = summarizeds.join('\n')
|
||||
break
|
||||
}
|
||||
index++
|
||||
return p1 + '\n' + text + '\n' + p2
|
||||
})))
|
||||
})(),
|
||||
(() => {
|
||||
const {individuals, summarizeds} = test
|
||||
const file = join('material-ui-tests.tsx')
|
||||
let index = 0
|
||||
return readText(file)
|
||||
.then((script) => writeText(file, script.replace(rMark, (_, p1, p2) => {
|
||||
let text = ''
|
||||
switch (index) {
|
||||
case 0:
|
||||
text = individuals.join('\n')
|
||||
break
|
||||
case 1:
|
||||
text = summarizeds.join('\n')
|
||||
break
|
||||
}
|
||||
index++
|
||||
return p1 + '\n' + text + '\n' + p2
|
||||
})))
|
||||
})(),
|
||||
])
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
+124
-158
@@ -1,25 +1,24 @@
|
||||
|
||||
// near copy of each of the tests from https://github.com/nodeca/argparse/tree/master/examples
|
||||
|
||||
import { ArgumentParser, RawDescriptionHelpFormatter } from 'argparse';
|
||||
var args: any;
|
||||
let args: any;
|
||||
|
||||
var simpleExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse example',
|
||||
const simpleExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse example',
|
||||
});
|
||||
simpleExample.addArgument(
|
||||
['-f', '--foo'],
|
||||
{
|
||||
help: 'foo bar',
|
||||
}
|
||||
['-f', '--foo'],
|
||||
{
|
||||
help: 'foo bar',
|
||||
}
|
||||
);
|
||||
simpleExample.addArgument(
|
||||
['-b', '--bar'],
|
||||
{
|
||||
help: 'bar foo',
|
||||
}
|
||||
['-b', '--bar'],
|
||||
{
|
||||
help: 'bar foo',
|
||||
}
|
||||
);
|
||||
|
||||
simpleExample.printHelp();
|
||||
@@ -35,13 +34,10 @@ args = simpleExample.parseArgs('--foo 5 --bar 6'.split(' '));
|
||||
console.dir(args);
|
||||
console.log('-----------');
|
||||
|
||||
|
||||
|
||||
|
||||
var choicesExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: choice'
|
||||
const choicesExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: choice'
|
||||
});
|
||||
|
||||
choicesExample.addArgument(['foo'], { choices: 'abc' });
|
||||
@@ -55,56 +51,53 @@ console.log('-----------');
|
||||
// choicesExample.parseArgs(['X']);
|
||||
// console.dir(args);
|
||||
|
||||
|
||||
|
||||
|
||||
var constantExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: constant'
|
||||
const constantExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: constant'
|
||||
});
|
||||
|
||||
constantExample.addArgument(
|
||||
['-a'],
|
||||
{
|
||||
action: 'storeConst',
|
||||
dest: 'answer',
|
||||
help: 'store constant',
|
||||
constant: 42
|
||||
}
|
||||
['-a'],
|
||||
{
|
||||
action: 'storeConst',
|
||||
dest: 'answer',
|
||||
help: 'store constant',
|
||||
constant: 42
|
||||
}
|
||||
);
|
||||
constantExample.addArgument(
|
||||
['--str'],
|
||||
{
|
||||
action: 'appendConst',
|
||||
dest: 'types',
|
||||
help: 'append constant "str" to types',
|
||||
constant: 'str'
|
||||
}
|
||||
['--str'],
|
||||
{
|
||||
action: 'appendConst',
|
||||
dest: 'types',
|
||||
help: 'append constant "str" to types',
|
||||
constant: 'str'
|
||||
}
|
||||
);
|
||||
constantExample.addArgument(
|
||||
['--int'],
|
||||
{
|
||||
action: 'appendConst',
|
||||
dest: 'types',
|
||||
help: 'append constant "int" to types',
|
||||
constant: 'int'
|
||||
}
|
||||
['--int'],
|
||||
{
|
||||
action: 'appendConst',
|
||||
dest: 'types',
|
||||
help: 'append constant "int" to types',
|
||||
constant: 'int'
|
||||
}
|
||||
);
|
||||
|
||||
constantExample.addArgument(
|
||||
['--true'],
|
||||
{
|
||||
action: 'storeTrue',
|
||||
help: 'store true constant'
|
||||
}
|
||||
['--true'],
|
||||
{
|
||||
action: 'storeTrue',
|
||||
help: 'store true constant'
|
||||
}
|
||||
);
|
||||
constantExample.addArgument(
|
||||
['--false'],
|
||||
{
|
||||
action: 'storeFalse',
|
||||
help: 'store false constant'
|
||||
}
|
||||
['--false'],
|
||||
{
|
||||
action: 'storeFalse',
|
||||
help: 'store false constant'
|
||||
}
|
||||
);
|
||||
|
||||
constantExample.printHelp();
|
||||
@@ -113,27 +106,24 @@ console.log('-----------');
|
||||
args = constantExample.parseArgs('-a --str --int --true'.split(' '));
|
||||
console.dir(args);
|
||||
|
||||
|
||||
|
||||
|
||||
var nargsExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: nargs'
|
||||
const nargsExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: nargs'
|
||||
});
|
||||
nargsExample.addArgument(
|
||||
['-f', '--foo'],
|
||||
{
|
||||
help: 'foo bar',
|
||||
nargs: 1
|
||||
}
|
||||
['-f', '--foo'],
|
||||
{
|
||||
help: 'foo bar',
|
||||
nargs: 1
|
||||
}
|
||||
);
|
||||
nargsExample.addArgument(
|
||||
['-b', '--bar'],
|
||||
{
|
||||
help: 'bar foo',
|
||||
nargs: '*'
|
||||
}
|
||||
['-b', '--bar'],
|
||||
{
|
||||
help: 'bar foo',
|
||||
nargs: '*'
|
||||
}
|
||||
);
|
||||
|
||||
nargsExample.printHelp();
|
||||
@@ -145,40 +135,34 @@ console.log('-----------');
|
||||
args = nargsExample.parseArgs('--bar b c f --foo a'.split(' '));
|
||||
console.dir(args);
|
||||
|
||||
|
||||
|
||||
|
||||
var parent_parser = new ArgumentParser({ addHelp: false });
|
||||
const parent_parser = new ArgumentParser({ addHelp: false });
|
||||
// note addHelp:false to prevent duplication of the -h option
|
||||
parent_parser.addArgument(
|
||||
['--parent'],
|
||||
{ type: 'int', help: 'parent' }
|
||||
['--parent'],
|
||||
{ type: 'int', help: 'parent' }
|
||||
);
|
||||
|
||||
var foo_parser = new ArgumentParser({
|
||||
parents: [parent_parser],
|
||||
description: 'child1'
|
||||
const foo_parser = new ArgumentParser({
|
||||
parents: [parent_parser],
|
||||
description: 'child1'
|
||||
});
|
||||
foo_parser.addArgument(['foo']);
|
||||
args = foo_parser.parseArgs(['--parent', '2', 'XXX']);
|
||||
console.log(args);
|
||||
|
||||
var bar_parser = new ArgumentParser({
|
||||
parents: [parent_parser],
|
||||
description: 'child2'
|
||||
const bar_parser = new ArgumentParser({
|
||||
parents: [parent_parser],
|
||||
description: 'child2'
|
||||
});
|
||||
bar_parser.addArgument(['--bar']);
|
||||
args = bar_parser.parseArgs(['--bar', 'YYY']);
|
||||
console.log(args);
|
||||
|
||||
|
||||
|
||||
|
||||
var prefixCharsExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: prefix_chars',
|
||||
prefixChars: '-+'
|
||||
const prefixCharsExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: prefix_chars',
|
||||
prefixChars: '-+'
|
||||
});
|
||||
prefixCharsExample.addArgument(['+f', '++foo']);
|
||||
prefixCharsExample.addArgument(['++bar'], { action: 'storeTrue' });
|
||||
@@ -193,39 +177,36 @@ console.dir(args);
|
||||
args = prefixCharsExample.parseArgs(['++foo', '2', '++bar']);
|
||||
console.dir(args);
|
||||
|
||||
|
||||
|
||||
|
||||
var subparserExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: sub-commands'
|
||||
const subparserExample = new ArgumentParser({
|
||||
version: '0.0.1',
|
||||
addHelp: true,
|
||||
description: 'Argparse examples: sub-commands'
|
||||
});
|
||||
|
||||
var subparsers = subparserExample.addSubparsers({
|
||||
title: 'subcommands',
|
||||
dest: "subcommand_name"
|
||||
const subparsers = subparserExample.addSubparsers({
|
||||
title: 'subcommands',
|
||||
dest: "subcommand_name"
|
||||
});
|
||||
|
||||
var bar = subparsers.addParser('c1', { addHelp: true, help: 'c1 help' });
|
||||
let bar = subparsers.addParser('c1', { addHelp: true, help: 'c1 help' });
|
||||
bar.addArgument(
|
||||
['-f', '--foo'],
|
||||
{
|
||||
action: 'store',
|
||||
help: 'foo3 bar3'
|
||||
}
|
||||
['-f', '--foo'],
|
||||
{
|
||||
action: 'store',
|
||||
help: 'foo3 bar3'
|
||||
}
|
||||
);
|
||||
var bar = subparsers.addParser(
|
||||
'c2',
|
||||
{ aliases: ['co'], addHelp: true, help: 'c2 help' }
|
||||
bar = subparsers.addParser(
|
||||
'c2',
|
||||
{ aliases: ['co'], addHelp: true, help: 'c2 help' }
|
||||
);
|
||||
bar.addArgument(
|
||||
['-b', '--bar'],
|
||||
{
|
||||
action: 'store',
|
||||
type: 'int',
|
||||
help: 'foo3 bar3'
|
||||
}
|
||||
['-b', '--bar'],
|
||||
{
|
||||
action: 'store',
|
||||
type: 'int',
|
||||
help: 'foo3 bar3'
|
||||
}
|
||||
);
|
||||
subparserExample.printHelp();
|
||||
console.log('-----------');
|
||||
@@ -241,66 +222,51 @@ console.dir(args);
|
||||
console.log('-----------');
|
||||
subparserExample.parseArgs(['c1', '-h']);
|
||||
|
||||
|
||||
|
||||
|
||||
var functionExample = new ArgumentParser({ description: 'Process some integers.' });
|
||||
const functionExample = new ArgumentParser({ description: 'Process some integers.' });
|
||||
function sum(arr: number[]) {
|
||||
return arr.reduce(function(a, b) {
|
||||
return a + b;
|
||||
}, 0);
|
||||
return arr.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
function max(arr: number[]) {
|
||||
return Math.max.apply(Math, arr);
|
||||
return Math.max.apply(Math, arr);
|
||||
}
|
||||
|
||||
|
||||
functionExample.addArgument(['integers'], {
|
||||
metavar: 'N',
|
||||
type: 'int',
|
||||
nargs: '+',
|
||||
help: 'an integer for the accumulator'
|
||||
metavar: 'N',
|
||||
type: 'int',
|
||||
nargs: '+',
|
||||
help: 'an integer for the accumulator'
|
||||
});
|
||||
functionExample.addArgument(['--sum'], {
|
||||
dest: 'accumulate',
|
||||
action: 'storeConst',
|
||||
constant: sum,
|
||||
defaultValue: max,
|
||||
help: 'sum the integers (default: find the max)'
|
||||
dest: 'accumulate',
|
||||
action: 'storeConst',
|
||||
constant: sum,
|
||||
defaultValue: max,
|
||||
help: 'sum the integers (default: find the max)'
|
||||
});
|
||||
|
||||
args = functionExample.parseArgs('--sum 1 2 -1'.split(' '));
|
||||
console.log(args.accumulate(args.integers));
|
||||
|
||||
|
||||
|
||||
|
||||
var formatterExample = new ArgumentParser({
|
||||
prog: 'PROG',
|
||||
formatterClass: RawDescriptionHelpFormatter,
|
||||
description: 'Keep the formatting\n' +
|
||||
' exactly as it is written\n' +
|
||||
'\n' +
|
||||
'here\n'
|
||||
const formatterExample = new ArgumentParser({
|
||||
prog: 'PROG',
|
||||
formatterClass: RawDescriptionHelpFormatter,
|
||||
description: `Keep the formatting\nexactly as it is written\n\nhere\n`,
|
||||
});
|
||||
|
||||
formatterExample.addArgument(['--foo'], {
|
||||
help: ' foo help should not\n' +
|
||||
' retain this odd formatting'
|
||||
help: `foo help should not\nretain this odd formatting`,
|
||||
});
|
||||
|
||||
formatterExample.addArgument(['spam'], {
|
||||
'help': 'spam help'
|
||||
help: 'spam help',
|
||||
});
|
||||
|
||||
var group = formatterExample.addArgumentGroup({
|
||||
title: 'title',
|
||||
description: ' This text\n' +
|
||||
' should be indented\n' +
|
||||
' exactly like it is here\n'
|
||||
const group = formatterExample.addArgumentGroup({
|
||||
title: 'title',
|
||||
description: `This text\nshould be indented\nexactly like it is here\n`,
|
||||
});
|
||||
|
||||
group.addArgument(['--bar'], {
|
||||
help: 'bar help'
|
||||
help: 'bar help'
|
||||
});
|
||||
formatterExample.printHelp();
|
||||
|
||||
Vendored
+28
-19
@@ -1,31 +1,39 @@
|
||||
// Type definitions for argparse v1.0.3
|
||||
// Type definitions for argparse 1.0
|
||||
// Project: https://github.com/nodeca/argparse
|
||||
// Definitions by: Andrew Schurman <https://github.com/arcticwaters>
|
||||
// Tomasz Łaziuk <https://github.com/tlaziuk>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
|
||||
export declare class ArgumentParser extends ArgumentGroup {
|
||||
export class ArgumentParser extends ArgumentGroup {
|
||||
constructor(options?: ArgumentParserOptions);
|
||||
|
||||
addSubparsers(options?: SubparserOptions): SubParser;
|
||||
parseArgs(args?: string[], ns?: Namespace | Object): any;
|
||||
parseArgs(args?: string[], ns?: Namespace | object): any;
|
||||
printUsage(): void;
|
||||
printHelp(): void;
|
||||
formatUsage(): string;
|
||||
formatHelp(): string;
|
||||
parseKnownArgs(args?: string[], ns?: Namespace | Object): any[];
|
||||
parseKnownArgs(args?: string[], ns?: Namespace | object): any[];
|
||||
convertArgLineToArg(argLine: string): string[];
|
||||
exit(status: number, message: string): void;
|
||||
error(err: string | Error): void;
|
||||
}
|
||||
|
||||
interface Namespace { }
|
||||
export class Namespace {
|
||||
constructor(options: object);
|
||||
get<K extends keyof this, D extends any>(key: K, defaultValue?: D): this[K] | D;
|
||||
isset<K extends keyof this>(key: K): boolean;
|
||||
set<K extends keyof this, V extends this[K]>(key: K, value: V): this;
|
||||
set<K extends string, V extends any>(key: K, value: V): this & Record<K, V>;
|
||||
set<K extends object>(obj: K): this & K;
|
||||
unset<K extends keyof this, D extends any>(key: K, defaultValue?: D): this[K] | D;
|
||||
}
|
||||
|
||||
declare class SubParser {
|
||||
export class SubParser {
|
||||
addParser(name: string, options?: SubArgumentParserOptions): ArgumentParser;
|
||||
}
|
||||
|
||||
declare class ArgumentGroup {
|
||||
export class ArgumentGroup {
|
||||
addArgument(args: string[], options?: ArgumentOptions): void;
|
||||
addArgumentGroup(options?: ArgumentGroupOptions): ArgumentGroup;
|
||||
addMutuallyExclusiveGroup(options?: { required: boolean }): ArgumentGroup;
|
||||
@@ -33,7 +41,7 @@ declare class ArgumentGroup {
|
||||
getDefault(dest: string): any;
|
||||
}
|
||||
|
||||
interface SubparserOptions {
|
||||
export interface SubparserOptions {
|
||||
title?: string;
|
||||
description?: string;
|
||||
prog?: string;
|
||||
@@ -44,12 +52,12 @@ interface SubparserOptions {
|
||||
metavar?: string;
|
||||
}
|
||||
|
||||
interface SubArgumentParserOptions extends ArgumentParserOptions {
|
||||
export interface SubArgumentParserOptions extends ArgumentParserOptions {
|
||||
aliases?: string[];
|
||||
help?: string;
|
||||
}
|
||||
|
||||
interface ArgumentParserOptions {
|
||||
export interface ArgumentParserOptions {
|
||||
description?: string;
|
||||
epilog?: string;
|
||||
addHelp?: boolean;
|
||||
@@ -62,26 +70,27 @@ interface ArgumentParserOptions {
|
||||
version?: string;
|
||||
}
|
||||
|
||||
interface ArgumentGroupOptions {
|
||||
export interface ArgumentGroupOptions {
|
||||
prefixChars?: string;
|
||||
argumentDefault?: any;
|
||||
title?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export declare class HelpFormatter { }
|
||||
export declare class ArgumentDefaultsHelpFormatter { }
|
||||
export declare class RawDescriptionHelpFormatter { }
|
||||
export declare class RawTextHelpFormatter { }
|
||||
export class HelpFormatter { }
|
||||
export class ArgumentDefaultsHelpFormatter { }
|
||||
export class RawDescriptionHelpFormatter { }
|
||||
export class RawTextHelpFormatter { }
|
||||
|
||||
interface ArgumentOptions {
|
||||
export interface ArgumentOptions {
|
||||
action?: string;
|
||||
optionStrings?: string[];
|
||||
dest?: string;
|
||||
nargs?: string | number;
|
||||
constant?: any;
|
||||
defaultValue?: any;
|
||||
type?: string | Function;
|
||||
// type may be a string (primitive) or a Function (constructor)
|
||||
type?: string | Function; // tslint:disable-line:ban-types
|
||||
choices?: string | string[];
|
||||
required?: boolean;
|
||||
help?: string;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Vendored
+1
-1
@@ -205,7 +205,7 @@ declare namespace autobahn {
|
||||
|
||||
type DeferFactory = () => When.Promise<any>;
|
||||
|
||||
type OnChallengeHandler = (session: Session, method: string, extra: any) => When.Promise<string>;
|
||||
type OnChallengeHandler = (session: Session, method: string, extra: any) => string;
|
||||
|
||||
interface IConnectionOptions {
|
||||
use_es6_promises?: boolean;
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,16 @@ chai.request(app)
|
||||
.get('/search')
|
||||
.query({ name: 'foo', limit: 10 });
|
||||
|
||||
chai.request(app)
|
||||
.get('/download')
|
||||
.buffer()
|
||||
.parse((res, cb) => {
|
||||
let data = '';
|
||||
res.setEncoding('binary');
|
||||
res.on('data', (chunk: any) => { data += chunk; });
|
||||
res.on('end', () => { cb(undefined, new Buffer(data, 'binary')); });
|
||||
});
|
||||
|
||||
chai.request(app)
|
||||
.put('/user/me')
|
||||
.send({ passsword: '123', confirmPassword: '123' })
|
||||
|
||||
Vendored
+3
@@ -49,6 +49,8 @@ declare global {
|
||||
type: string;
|
||||
status: number;
|
||||
text: string;
|
||||
setEncoding(encoding: string): void;
|
||||
on(event: string, fn: (...args: any[]) => void): void;
|
||||
}
|
||||
|
||||
interface Request extends FinishedRequest {
|
||||
@@ -59,6 +61,7 @@ declare global {
|
||||
auth(user: string, name: string): Request;
|
||||
field(name: string, val: string): Request;
|
||||
buffer(): Request;
|
||||
parse(fn: (res: Response, cb: (e?: Error, r?: any) => void) => void): Request;
|
||||
end(callback?: (err: any, res: Response) => void): FinishedRequest;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+21
-11
@@ -4,15 +4,14 @@
|
||||
// Fabien Lavocat <https://github.com/FabienLavocat>
|
||||
// KentarouTakeda <https://github.com/KentarouTakeda>
|
||||
// Larry Bahr <https://github.com/larrybahr>
|
||||
// Daniel Luz <https://github.com/mernen>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="jquery" />
|
||||
|
||||
declare class Chart {
|
||||
static readonly Chart: typeof Chart;
|
||||
constructor(
|
||||
context: string | JQuery | CanvasRenderingContext2D | HTMLCanvasElement | string[] | CanvasRenderingContext2D[] | HTMLCanvasElement[],
|
||||
context: string | CanvasRenderingContext2D | HTMLCanvasElement | ArrayLike<CanvasRenderingContext2D | HTMLCanvasElement>,
|
||||
options: Chart.ChartConfiguration
|
||||
);
|
||||
config: Chart.ChartConfiguration;
|
||||
@@ -83,6 +82,8 @@ declare namespace Chart {
|
||||
|
||||
type ScaleType = 'category' | 'linear' | 'logarithmic' | 'time' | 'radialLinear';
|
||||
|
||||
type PointStyle = 'circle' | 'cross' | 'crossRot' | 'dash' | 'line' | 'rect' | 'rectRounded' | 'rectRot' | 'star' | 'triangle';
|
||||
|
||||
type PositionType = 'left' | 'right' | 'top' | 'bottom';
|
||||
|
||||
interface ChartArea {
|
||||
@@ -175,7 +176,7 @@ declare namespace Chart {
|
||||
|
||||
interface ChartTitleOptions {
|
||||
display?: boolean;
|
||||
position?: string;
|
||||
position?: PositionType;
|
||||
fullWdith?: boolean;
|
||||
fontSize?: number;
|
||||
fontFamily?: string;
|
||||
@@ -187,10 +188,12 @@ declare namespace Chart {
|
||||
|
||||
interface ChartLegendOptions {
|
||||
display?: boolean;
|
||||
position?: string;
|
||||
position?: PositionType;
|
||||
fullWidth?: boolean;
|
||||
onClick?(event: any, legendItem: any): void;
|
||||
onClick?(event: MouseEvent, legendItem: ChartLegendItem): void;
|
||||
onHover?(event: MouseEvent, legendItem: ChartLegendItem): void;
|
||||
labels?: ChartLegendLabelOptions;
|
||||
reverse?: boolean;
|
||||
}
|
||||
|
||||
interface ChartLegendLabelOptions {
|
||||
@@ -293,7 +296,7 @@ declare namespace Chart {
|
||||
|
||||
interface ChartPointOptions {
|
||||
radius?: number;
|
||||
pointStyle?: string;
|
||||
pointStyle?: PointStyle;
|
||||
backgroundColor?: ChartColor;
|
||||
borderWidth?: number;
|
||||
borderColor?: ChartColor;
|
||||
@@ -332,6 +335,7 @@ declare namespace Chart {
|
||||
|
||||
interface TickOptions {
|
||||
autoSkip?: boolean;
|
||||
autoSkipPadding?: boolean;
|
||||
callback?(value: any, index: any, values: any): string|number;
|
||||
display?: boolean;
|
||||
fontColor?: ChartColor;
|
||||
@@ -386,7 +390,7 @@ declare namespace Chart {
|
||||
type ChartColor = string | CanvasGradient | CanvasPattern | string[];
|
||||
|
||||
interface ChartDataSets {
|
||||
cubicInterpolationMode?: string;
|
||||
cubicInterpolationMode?: 'default' | 'monotone';
|
||||
backgroundColor?: ChartColor | ChartColor[];
|
||||
borderWidth?: number;
|
||||
borderColor?: ChartColor;
|
||||
@@ -394,10 +398,15 @@ declare namespace Chart {
|
||||
borderDash?: number[];
|
||||
borderDashOffset?: number;
|
||||
borderJoinStyle?: string;
|
||||
borderSkipped?: PositionType;
|
||||
data?: number[] | ChartPoint[];
|
||||
fill?: boolean;
|
||||
fill?: boolean | number | string;
|
||||
hoverBackgroundColor?: string | string[];
|
||||
hoverBorderColor?: string | string[];
|
||||
hoverBorderWidth?: number | number[];
|
||||
label?: string;
|
||||
lineTension?: number;
|
||||
steppedLine?: 'before' | 'after' | boolean;
|
||||
pointBorderColor?: ChartColor | ChartColor[];
|
||||
pointBackgroundColor?: ChartColor | ChartColor[];
|
||||
pointBorderWidth?: number | number[];
|
||||
@@ -407,14 +416,15 @@ declare namespace Chart {
|
||||
pointHoverBackgroundColor?: ChartColor | ChartColor[];
|
||||
pointHoverBorderColor?: ChartColor | ChartColor[];
|
||||
pointHoverBorderWidth?: number | number[];
|
||||
pointStyle?: string | string[] | HTMLImageElement | HTMLImageElement[];
|
||||
pointStyle?: PointStyle | HTMLImageElement | Array<PointStyle | HTMLImageElement>;
|
||||
xAxisID?: string;
|
||||
yAxisID?: string;
|
||||
type?: string;
|
||||
hidden?: boolean;
|
||||
hideInLegendAndTooltip?: boolean;
|
||||
showLine?: boolean;
|
||||
stack?: string;
|
||||
spanGaps?: string;
|
||||
spanGaps?: boolean;
|
||||
}
|
||||
|
||||
interface ChartScales {
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"no-any-union": false
|
||||
"no-any-union": false,
|
||||
"rules": {
|
||||
"no-any-union": false,
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-any-union": false,
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -488,6 +488,7 @@ declare namespace Dockerode {
|
||||
CpusetCpus: string;
|
||||
CpusetMems: string;
|
||||
Devices?: any;
|
||||
DiskQuota: number;
|
||||
KernelMemory: number;
|
||||
Memory: number;
|
||||
MemoryReservation: number;
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ember-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strict": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -56,7 +56,7 @@ export interface CommonWrapper<P = {}, S = {}> {
|
||||
* Returns whether or not the current wrapper has a node anywhere in it's render tree that looks like the one passed in.
|
||||
* @param node
|
||||
*/
|
||||
contains(node: ReactElement<any>): boolean;
|
||||
contains(node: ReactElement<any> | string): boolean;
|
||||
|
||||
/**
|
||||
* Returns whether or not a given react element exists in the shallow render tree.
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+13
-8
@@ -105,6 +105,11 @@ declare namespace Ffmpeg {
|
||||
size?: string;
|
||||
}
|
||||
|
||||
interface AudioVideoFilter {
|
||||
filter: string;
|
||||
options: string | string[] | {};
|
||||
}
|
||||
|
||||
class FfmpegCommand extends events.EventEmitter {
|
||||
constructor(options?: FfmpegCommandOptions);
|
||||
constructor(input?: string | stream.Readable, options?: FfmpegCommandOptions);
|
||||
@@ -144,10 +149,10 @@ declare namespace Ffmpeg {
|
||||
audioFrequency(freq: number): FfmpegCommand;
|
||||
withAudioQuality(quality: number): FfmpegCommand;
|
||||
audioQuality(quality: number): FfmpegCommand;
|
||||
withAudioFilter(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
withAudioFilters(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
audioFilter(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
audioFilters(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
withAudioFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
withAudioFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
audioFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
audioFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
|
||||
// options/video;
|
||||
withNoVideo(): FfmpegCommand;
|
||||
@@ -156,10 +161,10 @@ declare namespace Ffmpeg {
|
||||
videoCodec(codec: string): FfmpegCommand;
|
||||
withVideoBitrate(bitrate: string | number): FfmpegCommand;
|
||||
videoBitrate(bitrate: string | number): FfmpegCommand;
|
||||
withVideoFilter(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
withVideoFilters(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
videoFilter(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
videoFilters(filters: { filter: string, options: any }): FfmpegCommand;
|
||||
withVideoFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
withVideoFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
videoFilter(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
videoFilters(filters: string | string[] | AudioVideoFilter[]): FfmpegCommand;
|
||||
withOutputFps(fps: number): FfmpegCommand;
|
||||
withOutputFPS(fps: number): FfmpegCommand;
|
||||
withFpsOutput(fps: number): FfmpegCommand;
|
||||
|
||||
@@ -14,7 +14,7 @@ const fd = 0;
|
||||
const modeNum = 0;
|
||||
const modeStr = "";
|
||||
const object = {};
|
||||
const errorCallback = (err: Error) => { };
|
||||
const errorCallback = (err: Error | null) => { };
|
||||
const readOptions: fs.ReadOptions = {
|
||||
reviver: {}
|
||||
};
|
||||
|
||||
Vendored
+74
-72
@@ -14,140 +14,141 @@ import { Stats } from "fs";
|
||||
export * from "fs";
|
||||
|
||||
export function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
||||
export function copy(src: string, dest: string, callback: (err: Error) => void): void;
|
||||
export function copy(src: string, dest: string, options: CopyOptions, callback: (err: Error) => void): void;
|
||||
export function copy(src: string, dest: string, callback: (err: Error | null) => void): void;
|
||||
export function copy(src: string, dest: string, options: CopyOptions, callback: (err: Error | null) => void): void;
|
||||
export function copySync(src: string, dest: string, options?: CopyOptions): void;
|
||||
|
||||
export function move(src: string, dest: string, options?: MoveOptions): Promise<void>;
|
||||
export function move(src: string, dest: string, callback: (err: Error) => void): void;
|
||||
export function move(src: string, dest: string, options: MoveOptions, callback: (err: Error) => void): void;
|
||||
export function move(src: string, dest: string, callback: (err: Error | null) => void): void;
|
||||
export function move(src: string, dest: string, options: MoveOptions, callback: (err: Error | null) => void): void;
|
||||
export function moveSync(src: string, dest: string, options?: MoveOptions): void;
|
||||
|
||||
export function createFile(file: string): Promise<void>;
|
||||
export function createFile(file: string, callback: (err: Error) => void): void;
|
||||
export function createFile(file: string, callback: (err: Error | null) => void): void;
|
||||
export function createFileSync(file: string): void;
|
||||
|
||||
export function ensureDir(path: string): Promise<void>;
|
||||
export function ensureDir(path: string, callback: (err: Error) => void): void;
|
||||
export function ensureDir(path: string, callback: (err: Error | null) => void): void;
|
||||
export function ensureDirSync(path: string): void;
|
||||
|
||||
export function mkdirs(dir: string): Promise<void>;
|
||||
export function mkdirs(dir: string, callback: (err: Error) => void): void;
|
||||
export function mkdirs(dir: string, callback: (err: Error | null) => void): void;
|
||||
export function mkdirp(dir: string): Promise<void>;
|
||||
export function mkdirp(dir: string, callback: (err: Error) => void): void;
|
||||
export function mkdirp(dir: string, callback: (err: Error | null) => void): void;
|
||||
export function mkdirsSync(dir: string): void;
|
||||
export function mkdirpSync(dir: string): void;
|
||||
|
||||
export function outputFile(file: string, data: any): Promise<void>;
|
||||
export function outputFile(file: string, data: any, callback: (err: Error) => void): void;
|
||||
export function outputFile(file: string, data: any, callback: (err: Error | null) => void): void;
|
||||
export function outputFileSync(file: string, data: any): void;
|
||||
|
||||
export function readJson(file: string, options?: ReadOptions): Promise<any>;
|
||||
export function readJson(file: string, callback: (err: Error, jsonObject: any) => void): void;
|
||||
export function readJson(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void;
|
||||
export function readJson(file: string, callback: (err: Error | null, jsonObject: any) => void): void;
|
||||
export function readJson(file: string, options: ReadOptions, callback: (err: Error | null, jsonObject: any) => void): void;
|
||||
export function readJSON(file: string, options?: ReadOptions): Promise<any>;
|
||||
export function readJSON(file: string, callback: (err: Error, jsonObject: any) => void): void;
|
||||
export function readJSON(file: string, options: ReadOptions, callback: (err: Error, jsonObject: any) => void): void;
|
||||
export function readJSON(file: string, callback: (err: Error | null, jsonObject: any) => void): void;
|
||||
export function readJSON(file: string, options: ReadOptions, callback: (err: Error | null, jsonObject: any) => void): void;
|
||||
|
||||
export function readJsonSync(file: string, options?: ReadOptions): any;
|
||||
export function readJSONSync(file: string, options?: ReadOptions): any;
|
||||
|
||||
export function remove(dir: string): Promise<void>;
|
||||
export function remove(dir: string, callback: (err: Error) => void): void;
|
||||
export function remove(dir: string, callback: (err: Error | null) => void): void;
|
||||
export function removeSync(dir: string): void;
|
||||
|
||||
export function outputJSON(file: string, data: any, options?: WriteOptions): Promise<void>;
|
||||
export function outputJSON(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void;
|
||||
export function outputJSON(file: string, data: any, callback: (err: Error) => void): void;
|
||||
export function outputJSON(file: string, data: any, options: WriteOptions, callback: (err: Error | null) => void): void;
|
||||
export function outputJSON(file: string, data: any, callback: (err: Error | null) => void): void;
|
||||
export function outputJson(file: string, data: any, options?: WriteOptions): Promise<void>;
|
||||
export function outputJson(file: string, data: any, options: WriteOptions, callback: (err: Error) => void): void;
|
||||
export function outputJson(file: string, data: any, callback: (err: Error) => void): void;
|
||||
export function outputJson(file: string, data: any, options: WriteOptions, callback: (err: Error | null) => void): void;
|
||||
export function outputJson(file: string, data: any, callback: (err: Error | null) => void): void;
|
||||
export function outputJsonSync(file: string, data: any, options?: WriteOptions): void;
|
||||
export function outputJSONSync(file: string, data: any, options?: WriteOptions): void;
|
||||
|
||||
export function writeJSON(file: string, object: any, options?: WriteOptions): Promise<void>;
|
||||
export function writeJSON(file: string, object: any, callback: (err: Error) => void): void;
|
||||
export function writeJSON(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void;
|
||||
export function writeJSON(file: string, object: any, callback: (err: Error | null) => void): void;
|
||||
export function writeJSON(file: string, object: any, options: WriteOptions, callback: (err: Error | null) => void): void;
|
||||
export function writeJson(file: string, object: any, options?: WriteOptions): Promise<void>;
|
||||
export function writeJson(file: string, object: any, callback: (err: Error) => void): void;
|
||||
export function writeJson(file: string, object: any, options: WriteOptions, callback: (err: Error) => void): void;
|
||||
export function writeJson(file: string, object: any, callback: (err: Error | null) => void): void;
|
||||
export function writeJson(file: string, object: any, options: WriteOptions, callback: (err: Error | null) => void): void;
|
||||
|
||||
export function writeJsonSync(file: string, object: any, options?: WriteOptions): void;
|
||||
export function writeJSONSync(file: string, object: any, options?: WriteOptions): void;
|
||||
|
||||
export function ensureFile(path: string): Promise<void>;
|
||||
export function ensureFile(path: string, callback: (err: Error) => void): void;
|
||||
export function ensureFile(path: string, callback: (err: Error | null) => void): void;
|
||||
export function ensureFileSync(path: string): void;
|
||||
|
||||
export function ensureLink(src: string, dest: string): Promise<void>;
|
||||
export function ensureLink(src: string, dest: string, callback: (err: Error) => void): void;
|
||||
export function ensureLink(src: string, dest: string, callback: (err: Error | null) => void): void;
|
||||
export function ensureLinkSync(src: string, dest: string): void;
|
||||
|
||||
export function ensureSymlink(src: string, dest: string, type?: SymlinkType): Promise<void>;
|
||||
export function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: (err: Error) => void): void;
|
||||
export function ensureSymlink(src: string, dest: string, callback: (err: Error) => void): void;
|
||||
export function ensureSymlink(src: string, dest: string, type: SymlinkType, callback: (err: Error | null) => void): void;
|
||||
export function ensureSymlink(src: string, dest: string, callback: (err: Error | null) => void): void;
|
||||
export function ensureSymlinkSync(src: string, dest: string, type?: SymlinkType): void;
|
||||
|
||||
export function emptyDir(path: string): Promise<void>;
|
||||
export function emptyDir(path: string, callback: (err: Error) => void): void;
|
||||
export function emptyDir(path: string, callback: (err: Error | null) => void): void;
|
||||
export function emptyDirSync(path: string): void;
|
||||
|
||||
export function pathExists(path: string): Promise<boolean>;
|
||||
export function pathExists(path: string, callback: (err: Error, exists: boolean) => void): void;
|
||||
export function pathExists(path: string, callback: (err: Error | null, exists: boolean) => void): void;
|
||||
export function pathExistsSync(path: string): boolean;
|
||||
|
||||
// fs async methods
|
||||
// copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node/v6/index.d.ts
|
||||
|
||||
/** Tests a user's permissions for the file specified by path. */
|
||||
export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void;
|
||||
export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException) => void): void;
|
||||
export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
export function access(path: string | Buffer, mode?: number): Promise<void>;
|
||||
|
||||
export function appendFile(file: string | Buffer | number, data: any, options: { encoding?: string; mode?: number | string; flag?: string; }, callback: (err: NodeJS.ErrnoException) => void): void;
|
||||
export function appendFile(file: string | Buffer | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
|
||||
export function appendFile(file: string | Buffer | number, data: any, options: { encoding?: string; mode?: number | string; flag?: string; },
|
||||
callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
export function appendFile(file: string | Buffer | number, data: any, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
export function appendFile(file: string | Buffer | number, data: any, options?: { encoding?: string; mode?: number | string; flag?: string; }): Promise<void>;
|
||||
|
||||
export function chmod(path: string | Buffer, mode: string | number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function chmod(path: string | Buffer, mode: string | number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function chmod(path: string | Buffer, mode: string | number): Promise<void>;
|
||||
|
||||
export function chown(path: string | Buffer, uid: number, gid: number): Promise<void>;
|
||||
export function chown(path: string | Buffer, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function chown(path: string | Buffer, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
|
||||
export function close(fd: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function close(fd: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function close(fd: number): Promise<void>;
|
||||
|
||||
export function fchmod(fd: number, mode: string | number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function fchmod(fd: number, mode: string | number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function fchmod(fd: number, mode: string | number): Promise<void>;
|
||||
|
||||
export function fchown(fd: number, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function fchown(fd: number, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function fchown(fd: number, uid: number, gid: number): Promise<void>;
|
||||
|
||||
export function fdatasync(fd: number, callback: () => void): void;
|
||||
export function fdatasync(fd: number): Promise<void>;
|
||||
|
||||
export function fstat(fd: number, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
|
||||
export function fstat(fd: number, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => any): void;
|
||||
export function fstat(fd: number): Promise<Stats>;
|
||||
|
||||
export function fsync(fd: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function fsync(fd: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function fsync(fd: number): Promise<void>;
|
||||
|
||||
export function ftruncate(fd: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function ftruncate(fd: number, len: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function ftruncate(fd: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function ftruncate(fd: number, len: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function ftruncate(fd: number, len?: number): Promise<void>;
|
||||
|
||||
export function futimes(fd: number, atime: number, mtime: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function futimes(fd: number, atime: Date, mtime: Date, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function futimes(fd: number, atime: number, mtime: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function futimes(fd: number, atime: Date, mtime: Date, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function futimes(fd: number, atime: number, mtime: number): Promise<void>;
|
||||
export function futimes(fd: number, atime: Date, mtime: Date): Promise<void>;
|
||||
|
||||
export function lchown(path: string | Buffer, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function lchown(path: string | Buffer, uid: number, gid: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function lchown(path: string | Buffer, uid: number, gid: number): Promise<void>;
|
||||
|
||||
export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function link(srcpath: string | Buffer, dstpath: string | Buffer): Promise<void>;
|
||||
|
||||
export function lstat(path: string | Buffer, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
|
||||
export function lstat(path: string | Buffer, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => any): void;
|
||||
export function lstat(path: string | Buffer): Promise<Stats>;
|
||||
|
||||
/**
|
||||
@@ -156,7 +157,7 @@ export function lstat(path: string | Buffer): Promise<Stats>;
|
||||
* @param path
|
||||
* @param callback No arguments other than a possible exception are given to the completion callback.
|
||||
*/
|
||||
export function mkdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function mkdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
/**
|
||||
* Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777.
|
||||
*
|
||||
@@ -164,35 +165,36 @@ export function mkdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoExcept
|
||||
* @param mode
|
||||
* @param callback No arguments other than a possible exception are given to the completion callback.
|
||||
*/
|
||||
export function mkdir(path: string | Buffer, mode: number | string, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function mkdir(path: string | Buffer, mode: number | string, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function mkdir(path: string | Buffer): Promise<void>;
|
||||
|
||||
export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
|
||||
export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void;
|
||||
export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
||||
export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException | null, fd: number) => void): void;
|
||||
export function open(path: string | Buffer, flags: string | number, mode?: number): Promise<number>;
|
||||
|
||||
export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void;
|
||||
export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null,
|
||||
callback: (err: NodeJS.ErrnoException | null, bytesRead: number, buffer: Buffer) => void): void;
|
||||
export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number | null): Promise<ReadResult>;
|
||||
|
||||
export function readFile(file: string | Buffer | number, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
|
||||
export function readFile(file: string | Buffer | number, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void;
|
||||
export function readFile(file: string | Buffer | number, callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void): void;
|
||||
export function readFile(file: string | Buffer | number, encoding: string, callback: (err: NodeJS.ErrnoException | null, data: string) => void): void;
|
||||
export function readFile(file: string | Buffer | number, options: { flag?: string; } | { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void;
|
||||
export function readFile(file: string | Buffer | number, options: { flag?: string; } | { encoding: string; flag?: string; }): Promise<string>;
|
||||
// tslint:disable-next-line:unified-signatures
|
||||
export function readFile(file: string | Buffer | number, encoding: string): Promise<string>;
|
||||
export function readFile(file: string | Buffer | number): Promise<Buffer>;
|
||||
|
||||
export function readdir(path: string | Buffer, callback: (err: NodeJS.ErrnoException, files: string[]) => void): void;
|
||||
export function readdir(path: string | Buffer, callback: (err: NodeJS.ErrnoException | null, files: string[]) => void): void;
|
||||
export function readdir(path: string | Buffer): Promise<string[]>;
|
||||
|
||||
export function readlink(path: string | Buffer, callback: (err: NodeJS.ErrnoException, linkString: string) => any): void;
|
||||
export function readlink(path: string | Buffer, callback: (err: NodeJS.ErrnoException | null, linkString: string) => any): void;
|
||||
export function readlink(path: string | Buffer): Promise<string>;
|
||||
|
||||
export function realpath(path: string | Buffer, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
|
||||
export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void;
|
||||
export function realpath(path: string | Buffer, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => any): void;
|
||||
export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException | null, resolvedPath: string) => any): void;
|
||||
export function realpath(path: string | Buffer, cache?: { [path: string]: string }): Promise<string>;
|
||||
|
||||
export function rename(oldPath: string, newPath: string, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function rename(oldPath: string, newPath: string, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function rename(oldPath: string, newPath: string): Promise<void>;
|
||||
|
||||
/**
|
||||
@@ -201,17 +203,17 @@ export function rename(oldPath: string, newPath: string): Promise<void>;
|
||||
* @param path
|
||||
* @param callback No arguments other than a possible exception are given to the completion callback.
|
||||
*/
|
||||
export function rmdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function rmdir(path: string | Buffer, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function rmdir(path: string | Buffer): Promise<void>;
|
||||
|
||||
export function stat(path: string | Buffer, callback: (err: NodeJS.ErrnoException, stats: Stats) => any): void;
|
||||
export function stat(path: string | Buffer, callback: (err: NodeJS.ErrnoException | null, stats: Stats) => any): void;
|
||||
export function stat(path: string | Buffer): Promise<Stats>;
|
||||
|
||||
export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type: string, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type: string, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: string): Promise<void>;
|
||||
|
||||
export function truncate(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function truncate(path: string | Buffer, len: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function truncate(path: string | Buffer, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function truncate(path: string | Buffer, len: number, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function truncate(path: string | Buffer, len?: number): Promise<void>;
|
||||
|
||||
/**
|
||||
@@ -220,25 +222,25 @@ export function truncate(path: string | Buffer, len?: number): Promise<void>;
|
||||
* @param path
|
||||
* @param callback No arguments other than a possible exception are given to the completion callback.
|
||||
*/
|
||||
export function unlink(path: string | Buffer, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function unlink(path: string | Buffer, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function unlink(path: string | Buffer): Promise<void>;
|
||||
|
||||
export function utimes(path: string | Buffer, atime: number, mtime: number, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback: (err?: NodeJS.ErrnoException) => void): void;
|
||||
export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback: (err?: NodeJS.ErrnoException | null) => void): void;
|
||||
export function utimes(path: string | Buffer, atime: number, mtime: number): Promise<void>;
|
||||
export function utimes(path: string | Buffer, atime: Date, mtime: Date): Promise<void>;
|
||||
|
||||
export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number | null, callback: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
|
||||
export function write(fd: number, buffer: Buffer, offset: number, length: number, callback: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void;
|
||||
export function write(fd: number, data: any, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
|
||||
export function write(fd: number, data: any, offset: number, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
|
||||
export function write(fd: number, data: any, offset: number, encoding: string, callback: (err: NodeJS.ErrnoException, written: number, str: string) => void): void;
|
||||
export function write(fd: number, buffer: Buffer, offset: number, length: number, callback: (err: NodeJS.ErrnoException | null, written: number, buffer: Buffer) => void): void;
|
||||
export function write(fd: number, data: any, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
||||
export function write(fd: number, data: any, offset: number, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
||||
export function write(fd: number, data: any, offset: number, encoding: string, callback: (err: NodeJS.ErrnoException | null, written: number, str: string) => void): void;
|
||||
export function write(fd: number, buffer: Buffer, offset: number, length: number, position?: number | null): Promise<WriteResult>;
|
||||
export function write(fd: number, data: any, offset: number, encoding?: string): Promise<WriteResult>;
|
||||
|
||||
export function writeFile(file: string | Buffer | number, data: any, callback: (err: NodeJS.ErrnoException) => void): void;
|
||||
export function writeFile(file: string | Buffer | number, data: any, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
export function writeFile(file: string | Buffer | number, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): Promise<void>;
|
||||
export function writeFile(file: string | Buffer | number, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback: (err: NodeJS.ErrnoException) => void): void;
|
||||
export function writeFile(file: string | Buffer | number, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
|
||||
/**
|
||||
* Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory.
|
||||
@@ -247,7 +249,7 @@ export function writeFile(file: string | Buffer | number, data: any, options: {
|
||||
* @param callback The created folder path is passed as a string to the callback's second parameter.
|
||||
*/
|
||||
export function mkdtemp(prefix: string): Promise<string>;
|
||||
export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException, folder: string) => void): void;
|
||||
export function mkdtemp(prefix: string, callback: (err: NodeJS.ErrnoException | null, folder: string) => void): void;
|
||||
|
||||
export interface PathEntry {
|
||||
path: string;
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -7,6 +7,7 @@
|
||||
// Kepennar <https://github.com/kepennar>
|
||||
// Mikhail Novikov <https://github.com/freiksenet>
|
||||
// Ivan Goncharov <https://github.com/IvanGoncharov>
|
||||
// Hagai Cohen <https://github.com/DxCx>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ export function subscribe(
|
||||
operationName?: string,
|
||||
fieldResolver?: GraphQLFieldResolver<any, any>,
|
||||
subscribeFieldResolver?: GraphQLFieldResolver<any, any>
|
||||
): AsyncIterator<ExecutionResult>;
|
||||
): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
|
||||
|
||||
export function createSourceEventStream(
|
||||
schema: GraphQLSchema,
|
||||
@@ -26,4 +26,4 @@ export function createSourceEventStream(
|
||||
},
|
||||
operationName?: string,
|
||||
fieldResolver?: GraphQLFieldResolver<any, any>
|
||||
): AsyncIterable<any>;
|
||||
): Promise<AsyncIterable<any>>;
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,991 @@
|
||||
import fs = require('hexo-fs');
|
||||
import path = require('path');
|
||||
import mocha = require('mocha');
|
||||
import chai = require('chai');
|
||||
import Promise = require('bluebird');
|
||||
|
||||
const should = chai.should();
|
||||
const { join } = path;
|
||||
|
||||
function createDummyFolder(path: string) {
|
||||
return Promise.all([
|
||||
// Normal files in a hidden folder
|
||||
fs.writeFile(join(path, '.hidden', 'a.txt'), 'a'),
|
||||
fs.writeFile(join(path, '.hidden', 'b.js'), 'b'),
|
||||
// Normal folder in a hidden folder
|
||||
fs.writeFile(join(path, '.hidden', 'c', 'd'), 'd'),
|
||||
// Top-class files
|
||||
fs.writeFile(join(path, 'e.txt'), 'e'),
|
||||
fs.writeFile(join(path, 'f.js'), 'f'),
|
||||
// A hidden file
|
||||
fs.writeFile(join(path, '.g'), 'g'),
|
||||
// Files in a normal folder
|
||||
fs.writeFile(join(path, 'folder', 'h.txt'), 'h'),
|
||||
fs.writeFile(join(path, 'folder', 'i.js'), 'i'),
|
||||
// A hidden files in a normal folder
|
||||
fs.writeFile(join(path, 'folder', '.j'), 'j')
|
||||
]);
|
||||
}
|
||||
|
||||
const tmpDir = join(__dirname, 'fs_tmp');
|
||||
|
||||
before(() => fs.mkdirs(tmpDir));
|
||||
|
||||
after((done) => {
|
||||
fs.rmdir(tmpDir);
|
||||
done();
|
||||
});
|
||||
|
||||
it('exists()', () => {
|
||||
return fs.exists(tmpDir).then((exist) => {
|
||||
exist.should.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
it('exists() - callback', (callback) => {
|
||||
fs.exists(tmpDir, (exist) => {
|
||||
exist.should.be.true;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
it('mkdirs()', () => {
|
||||
const target = join(tmpDir, 'a', 'b', 'c');
|
||||
|
||||
return fs.mkdirs(target).then(() => {
|
||||
return fs.exists(target);
|
||||
}).then((exist) => {
|
||||
exist.should.be.true;
|
||||
return fs.rmdir(join(tmpDir, 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
it('mkdirs() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'a', 'b', 'c');
|
||||
|
||||
fs.mkdirs(target, (err) => {
|
||||
should.not.exist(err);
|
||||
|
||||
fs.exists(target, (exist) => {
|
||||
exist.should.be.true;
|
||||
fs.rmdir(join(tmpDir, 'a'), callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('mkdirsSync()', () => {
|
||||
const target = join(tmpDir, 'a', 'b', 'c');
|
||||
|
||||
fs.mkdirsSync(target);
|
||||
|
||||
return fs.exists(target).then((exist) => {
|
||||
exist.should.be.true;
|
||||
return fs.rmdir(join(tmpDir, 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
it('writeFile()', () => {
|
||||
const target = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
return fs.readFile(target);
|
||||
}).then((content) => {
|
||||
content.should.eql(body);
|
||||
return fs.rmdir(join(tmpDir, 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
it('writeFile() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
|
||||
fs.writeFile(target, body, (err) => {
|
||||
should.not.exist(err);
|
||||
|
||||
fs.readFile(target, (_, content) => {
|
||||
content!.should.eql(body);
|
||||
fs.rmdir(join(tmpDir, 'a'), callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('writeFileSync()', () => {
|
||||
const target = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
|
||||
fs.writeFileSync(target, body);
|
||||
|
||||
return fs.readFile(target).then((content) => {
|
||||
content.should.eql(body);
|
||||
return fs.rmdir(join(tmpDir, 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
it('appendFile()', () => {
|
||||
const target = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
const body2 = 'bar';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
return fs.appendFile(target, body2);
|
||||
}).then(() => {
|
||||
return fs.readFile(target);
|
||||
}).then((content) => {
|
||||
content.should.eql(body + body2);
|
||||
return fs.rmdir(join(tmpDir, 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
it('appendFile() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
const body2 = 'bar';
|
||||
|
||||
fs.writeFile(target, body, () => {
|
||||
fs.appendFile(target, body2, (err) => {
|
||||
should.not.exist(err);
|
||||
|
||||
fs.readFile(target, (_, content) => {
|
||||
content!.should.eql(body + body2);
|
||||
fs.rmdir(join(tmpDir, 'a'), callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('appendFileSync()', () => {
|
||||
const target = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
const body2 = 'bar';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
fs.appendFileSync(target, body2);
|
||||
return fs.readFile(target);
|
||||
}).then((content) => {
|
||||
content.should.eql(body + body2);
|
||||
return fs.rmdir(join(tmpDir, 'a'));
|
||||
});
|
||||
});
|
||||
|
||||
it('copyFile()', () => {
|
||||
const src = join(tmpDir, 'test.txt');
|
||||
const dest = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
|
||||
return fs.writeFile(src, body).then(() => {
|
||||
return fs.copyFile(src, dest);
|
||||
}).then(() => {
|
||||
return fs.readFile(dest);
|
||||
}).then((content) => {
|
||||
content.should.eql(body);
|
||||
|
||||
return Promise.all([
|
||||
fs.unlink(src),
|
||||
fs.rmdir(join(tmpDir, 'a'))
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('copyFile() - callback', (callback) => {
|
||||
const src = join(tmpDir, 'test.txt');
|
||||
const dest = join(tmpDir, 'a', 'b', 'test.txt');
|
||||
const body = 'foo';
|
||||
|
||||
fs.writeFile(src, body, (err) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
fs.copyFile(src, dest, (err) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
fs.readFile(dest, (err, content) => {
|
||||
if (err) return callback(err);
|
||||
content!.should.eql(body);
|
||||
|
||||
Promise.all([
|
||||
fs.unlink(src),
|
||||
fs.rmdir(join(tmpDir, 'a'))
|
||||
]).asCallback(callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('copyDir()', () => {
|
||||
const src = join(tmpDir, 'a');
|
||||
const dest = join(tmpDir, 'b');
|
||||
|
||||
return createDummyFolder(src).then(() => {
|
||||
return fs.copyDir(src, dest);
|
||||
}).then((files) => {
|
||||
files.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
return Promise.all([
|
||||
fs.readFile(join(dest, 'e.txt')),
|
||||
fs.readFile(join(dest, 'f.js')),
|
||||
fs.readFile(join(dest, 'folder', 'h.txt')),
|
||||
fs.readFile(join(dest, 'folder', 'i.js'))
|
||||
]);
|
||||
}).then((result) => {
|
||||
result.should.eql(['e', 'f', 'h', 'i']);
|
||||
}).then(() => {
|
||||
return Promise.all([
|
||||
fs.rmdir(src),
|
||||
fs.rmdir(dest)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('copyDir() - callback', (callback) => {
|
||||
const src = join(tmpDir, 'a');
|
||||
const dest = join(tmpDir, 'b');
|
||||
|
||||
createDummyFolder(src).then(() => {
|
||||
fs.copyDir(src, dest, (err, files) => {
|
||||
should.not.exist(err);
|
||||
files!.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
Promise.all([
|
||||
fs.readFile(join(dest, 'e.txt')),
|
||||
fs.readFile(join(dest, 'f.js')),
|
||||
fs.readFile(join(dest, 'folder', 'h.txt')),
|
||||
fs.readFile(join(dest, 'folder', 'i.js'))
|
||||
]).then((result) => {
|
||||
result.should.eql(['e', 'f', 'h', 'i']);
|
||||
}).then(() => {
|
||||
return Promise.all([
|
||||
fs.rmdir(src),
|
||||
fs.rmdir(dest)
|
||||
]);
|
||||
}).asCallback(callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('copyDir() - ignoreHidden off', () => {
|
||||
const src = join(tmpDir, 'a');
|
||||
const dest = join(tmpDir, 'b');
|
||||
|
||||
return createDummyFolder(src).then(() => {
|
||||
return fs.copyDir(src, dest, { ignoreHidden: false });
|
||||
}).then((files) => {
|
||||
files.should.have.members([
|
||||
join('.hidden', 'a.txt'),
|
||||
join('.hidden', 'b.js'),
|
||||
join('.hidden', 'c', 'd'),
|
||||
'e.txt',
|
||||
'f.js',
|
||||
'.g',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js'),
|
||||
join('folder', '.j')
|
||||
]);
|
||||
|
||||
return Promise.all([
|
||||
fs.readFile(join(dest, '.hidden', 'a.txt')),
|
||||
fs.readFile(join(dest, '.hidden', 'b.js')),
|
||||
fs.readFile(join(dest, '.hidden', 'c', 'd')),
|
||||
fs.readFile(join(dest, 'e.txt')),
|
||||
fs.readFile(join(dest, 'f.js')),
|
||||
fs.readFile(join(dest, '.g')),
|
||||
fs.readFile(join(dest, 'folder', 'h.txt')),
|
||||
fs.readFile(join(dest, 'folder', 'i.js')),
|
||||
fs.readFile(join(dest, 'folder', '.j'))
|
||||
]);
|
||||
}).then((result) => {
|
||||
result.should.eql(['a', 'b', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);
|
||||
}).then(() => {
|
||||
return Promise.all([
|
||||
fs.rmdir(src),
|
||||
fs.rmdir(dest)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('copyDir() - ignorePattern', () => {
|
||||
const src = join(tmpDir, 'a');
|
||||
const dest = join(tmpDir, 'b');
|
||||
|
||||
return createDummyFolder(src).then(() => {
|
||||
return fs.copyDir(src, dest, { ignorePattern: /\.js/ });
|
||||
}).then((files) => {
|
||||
files.should.have.members(['e.txt', join('folder', 'h.txt')]);
|
||||
|
||||
return Promise.all([
|
||||
fs.readFile(join(dest, 'e.txt')),
|
||||
fs.readFile(join(dest, 'folder', 'h.txt'))
|
||||
]);
|
||||
}).then((result) => {
|
||||
result.should.eql(['e', 'h']);
|
||||
}).then(() => {
|
||||
return Promise.all([
|
||||
fs.rmdir(src),
|
||||
fs.rmdir(dest)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('listDir()', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.listDir(target);
|
||||
}).then((files) => {
|
||||
files.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('listDir() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
createDummyFolder(target).then(() => {
|
||||
fs.listDir(target, (err, files) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
files!.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
fs.rmdir(target, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('listDir() - ignoreHidden off', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.listDir(target, { ignoreHidden: false });
|
||||
}).then((files) => {
|
||||
files.should.have.members([
|
||||
join('.hidden', 'a.txt'),
|
||||
join('.hidden', 'b.js'),
|
||||
join('.hidden', 'c', 'd'),
|
||||
'e.txt',
|
||||
'f.js',
|
||||
'.g',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js'),
|
||||
join('folder', '.j')
|
||||
]);
|
||||
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('listDir() - ignorePattern', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.listDir(target, { ignorePattern: /\.js/ });
|
||||
}).then((files) => {
|
||||
files.should.have.members(['e.txt', join('folder', 'h.txt')]);
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('listDirSync()', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
const files = fs.listDirSync(target);
|
||||
files.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('listDirSync() - ignoreHidden off', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
const files = fs.listDirSync(target, { ignoreHidden: false });
|
||||
files.should.have.members([
|
||||
join('.hidden', 'a.txt'),
|
||||
join('.hidden', 'b.js'),
|
||||
join('.hidden', 'c', 'd'),
|
||||
'e.txt',
|
||||
'f.js',
|
||||
'.g',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js'),
|
||||
join('folder', '.j')
|
||||
]);
|
||||
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('listDirSync() - ignorePattern', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
const files = fs.listDirSync(target, { ignorePattern: /\.js/ });
|
||||
files.should.have.members(['e.txt', join('folder', 'h.txt')]);
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('readFile()', () => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = 'test';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
return fs.readFile(target);
|
||||
}).then((content) => {
|
||||
content.should.eql(body);
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('readFile() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = 'test';
|
||||
|
||||
fs.writeFile(target, body, (err) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
fs.readFile(target, (err, content) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
content!.should.eql(body);
|
||||
|
||||
fs.unlink(target).asCallback(callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('readFile() - escape BOM', () => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = '\ufefffoo';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
return fs.readFile(target);
|
||||
}).then((content) => {
|
||||
content.should.eql('foo');
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('readFile() - escape Windows line ending', () => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = 'foo\r\nbar';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
return fs.readFile(target);
|
||||
}).then((content) => {
|
||||
content.should.eql('foo\nbar');
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('readFileSync()', () => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = 'test';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
fs.readFileSync(target).should.eql(body);
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('readFileSync() - escape BOM', () => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = '\ufefffoo';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
fs.readFileSync(target).should.eql('foo');
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('readFileSync() - escape Windows line ending', () => {
|
||||
const target = join(tmpDir, 'test.txt');
|
||||
const body = 'foo\r\nbar';
|
||||
|
||||
return fs.writeFile(target, body).then(() => {
|
||||
fs.readFileSync(target).should.eql('foo\nbar');
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('unlink()', () => {
|
||||
const target = join(tmpDir, 'test-unlink');
|
||||
|
||||
return fs.writeFile(target, '').then(() => {
|
||||
return fs.exists(target);
|
||||
}).then((exist) => {
|
||||
exist.should.eql(true);
|
||||
return fs.unlink(target);
|
||||
}).then(() => {
|
||||
return fs.exists(target);
|
||||
}).then((exist) => {
|
||||
exist.should.eql(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDir()', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.emptyDir(target);
|
||||
}).then<Array<[string, boolean]>>((files) => {
|
||||
files.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), false],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDir() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
createDummyFolder(target).then(() => {
|
||||
fs.emptyDir(target, (err, files) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
files!.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
Promise.map<[string, boolean], void>([
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), false],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
], (data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
}).asCallback(callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDir() - ignoreHidden off', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.emptyDir(target, { ignoreHidden: false });
|
||||
}).then<Array<[string, boolean]>>((files) => {
|
||||
files.should.have.members([
|
||||
join('.hidden', 'a.txt'),
|
||||
join('.hidden', 'b.js'),
|
||||
join('.hidden', 'c', 'd'),
|
||||
'e.txt',
|
||||
'f.js',
|
||||
'.g',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js'),
|
||||
join('folder', '.j')
|
||||
]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), false],
|
||||
[join(target, '.hidden', 'b.js'), false],
|
||||
[join(target, '.hidden', 'c', 'd'), false],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), false],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), false],
|
||||
[join(target, 'folder', '.j'), false]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDir() - ignorePattern', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.emptyDir(target, { ignorePattern: /\.js/ });
|
||||
}).then<Array<[string, boolean]>>((files) => {
|
||||
files.should.have.members(['e.txt', join('folder', 'h.txt')]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), true],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), true],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDir() - exclude', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.emptyDir(target, { exclude: ['e.txt', join('folder', 'i.js')] });
|
||||
}).then<Array<[string, boolean]>>((files) => {
|
||||
files.should.have.members(['f.js', join('folder', 'h.txt')]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), true],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), true],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDirSync()', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then<Array<[string, boolean]>>(() => {
|
||||
const files = fs.emptyDirSync(target);
|
||||
files.should.have.members([
|
||||
'e.txt',
|
||||
'f.js',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js')
|
||||
]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), false],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDirSync() - ignoreHidden off', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then<Array<[string, boolean]>>(() => {
|
||||
const files = fs.emptyDirSync(target, { ignoreHidden: false });
|
||||
files.should.have.members([
|
||||
join('.hidden', 'a.txt'),
|
||||
join('.hidden', 'b.js'),
|
||||
join('.hidden', 'c', 'd'),
|
||||
'e.txt',
|
||||
'f.js',
|
||||
'.g',
|
||||
join('folder', 'h.txt'),
|
||||
join('folder', 'i.js'),
|
||||
join('folder', '.j')
|
||||
]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), false],
|
||||
[join(target, '.hidden', 'b.js'), false],
|
||||
[join(target, '.hidden', 'c', 'd'), false],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), false],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), false],
|
||||
[join(target, 'folder', '.j'), false]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDirSync() - ignorePattern', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then<Array<[string, boolean]>>(() => {
|
||||
const files = fs.emptyDirSync(target, { ignorePattern: /\.js/ });
|
||||
files.should.have.members(['e.txt', join('folder', 'h.txt')]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), false],
|
||||
[join(target, 'f.js'), true],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), true],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('emptyDirSync() - exclude', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then<Array<[string, boolean]>>(() => {
|
||||
const files = fs.emptyDirSync(target, { exclude: ['e.txt', join('folder', 'i.js')] });
|
||||
files.should.have.members(['f.js', join('folder', 'h.txt')]);
|
||||
|
||||
return [
|
||||
[join(target, '.hidden', 'a.txt'), true],
|
||||
[join(target, '.hidden', 'b.js'), true],
|
||||
[join(target, '.hidden', 'c', 'd'), true],
|
||||
[join(target, 'e.txt'), true],
|
||||
[join(target, 'f.js'), false],
|
||||
[join(target, '.g'), true],
|
||||
[join(target, 'folder', 'h.txt'), false],
|
||||
[join(target, 'folder', 'i.js'), true],
|
||||
[join(target, 'folder', '.j'), true]
|
||||
];
|
||||
}).map((data: [string, boolean]) => {
|
||||
return fs.exists(data[0]).then((exist) => {
|
||||
exist.should.eql(data[1]);
|
||||
});
|
||||
}).then(() => {
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('rmdir()', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
return fs.rmdir(target);
|
||||
}).then(() => {
|
||||
return fs.exists(target);
|
||||
}).then((exist) => {
|
||||
exist.should.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
it('rmdir() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
createDummyFolder(target).then(() => {
|
||||
fs.rmdir(target, (err) => {
|
||||
should.not.exist(err);
|
||||
|
||||
fs.exists(target, (exist) => {
|
||||
exist.should.be.false;
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('rmdirSync()', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return createDummyFolder(target).then(() => {
|
||||
fs.rmdirSync(target);
|
||||
return fs.exists(target);
|
||||
}).then((exist) => {
|
||||
exist.should.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
import { FSWatcher } from 'chokidar';
|
||||
|
||||
it('watch()', () => {
|
||||
let watcher: FSWatcher;
|
||||
|
||||
return fs.watch(tmpDir).then((watcher_) => {
|
||||
watcher = watcher_;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const path = join(tmpDir, 'test.txt');
|
||||
|
||||
watcher.on('add', (path_) => {
|
||||
path_.should.eql(path);
|
||||
resolve();
|
||||
});
|
||||
|
||||
fs.writeFile(path, 'test').catch(reject);
|
||||
});
|
||||
}).finally(() => {
|
||||
if (watcher) watcher.close();
|
||||
});
|
||||
});
|
||||
|
||||
it('ensurePath() - file exists', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return Promise.all([
|
||||
fs.writeFile(join(target, 'foo.txt'), ''),
|
||||
fs.writeFile(join(target, 'foo-1.txt'), ''),
|
||||
fs.writeFile(join(target, 'foo-2.md'), ''),
|
||||
fs.writeFile(join(target, 'bar.txt'), '')
|
||||
]).then(() => {
|
||||
return fs.ensurePath(join(target, 'foo.txt'));
|
||||
}).then((path) => {
|
||||
path.should.eql(join(target, 'foo-2.txt'));
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('ensurePath() - file not exist', () => {
|
||||
const target = join(tmpDir, 'foo.txt');
|
||||
|
||||
return fs.ensurePath(target).then((path) => {
|
||||
path.should.eql(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('ensurePath() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
Promise.all([
|
||||
fs.writeFile(join(target, 'foo.txt'), ''),
|
||||
fs.writeFile(join(target, 'foo-1.txt'), ''),
|
||||
fs.writeFile(join(target, 'foo-2.md'), ''),
|
||||
fs.writeFile(join(target, 'bar.txt'), '')
|
||||
]).then(() => {
|
||||
fs.ensurePath(join(target, 'foo.txt'), (err, path) => {
|
||||
should.not.exist(err);
|
||||
path!.should.eql(join(target, 'foo-2.txt'));
|
||||
fs.rmdir(target, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('ensurePathSync() - file exists', () => {
|
||||
const target = join(tmpDir, 'test');
|
||||
|
||||
return Promise.all([
|
||||
fs.writeFile(join(target, 'foo.txt'), ''),
|
||||
fs.writeFile(join(target, 'foo-1.txt'), ''),
|
||||
fs.writeFile(join(target, 'foo-2.md'), ''),
|
||||
fs.writeFile(join(target, 'bar.txt'), '')
|
||||
]).then(() => {
|
||||
const path = fs.ensurePathSync(join(target, 'foo.txt'));
|
||||
path.should.eql(join(target, 'foo-2.txt'));
|
||||
|
||||
return fs.rmdir(target);
|
||||
});
|
||||
});
|
||||
|
||||
it('ensurePathSync() - file not exist', () => {
|
||||
const target = join(tmpDir, 'foo.txt');
|
||||
const path = fs.ensurePathSync(target);
|
||||
|
||||
path.should.eql(target);
|
||||
});
|
||||
|
||||
it('ensureWriteStream()', () => {
|
||||
const target = join(tmpDir, 'foo', 'bar.txt');
|
||||
|
||||
return fs.ensureWriteStream(target).then((stream) => {
|
||||
stream.path.should.eql(target);
|
||||
stream.on('finish', () => {
|
||||
return fs.unlink(target);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('ensureWriteStream() - callback', (callback) => {
|
||||
const target = join(tmpDir, 'foo', 'bar.txt');
|
||||
|
||||
fs.ensureWriteStream(target, (err, stream) => {
|
||||
should.not.exist(err);
|
||||
stream!.path.should.eql(target);
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
it('ensureWriteStreamSync()', () => {
|
||||
const target = join(tmpDir, 'foo', 'bar.txt');
|
||||
const stream = fs.ensureWriteStreamSync(target);
|
||||
|
||||
stream.path.should.eql(target);
|
||||
stream.on('finish', () => {
|
||||
return fs.rmdir(path.dirname(target));
|
||||
});
|
||||
});
|
||||
Vendored
+436
@@ -0,0 +1,436 @@
|
||||
// Type definitions for hexo-fs 0.2
|
||||
// Project: http://hexo.io/
|
||||
// Definitions by: segayuu <https://github.com/segayuu>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import Promise = require('bluebird');
|
||||
import {
|
||||
PathLike,
|
||||
Stats,
|
||||
ReadStream,
|
||||
WriteStream,
|
||||
// chmod,
|
||||
chmodSync,
|
||||
// fchmod,
|
||||
fchmodSync,
|
||||
// lchmod,
|
||||
lchmodSync,
|
||||
// chown,
|
||||
chownSync,
|
||||
// fchown,
|
||||
fchownSync,
|
||||
// lchown,
|
||||
lchownSync,
|
||||
// close,
|
||||
closeSync,
|
||||
createReadStream,
|
||||
createWriteStream,
|
||||
// fsync,
|
||||
fsyncSync,
|
||||
// link,
|
||||
linkSync,
|
||||
// mkdir,
|
||||
mkdirSync,
|
||||
// open,
|
||||
openSync,
|
||||
// symlink,
|
||||
symlinkSync,
|
||||
// read,
|
||||
readSync,
|
||||
// readdir,
|
||||
readdirSync,
|
||||
// readlink,
|
||||
readlinkSync,
|
||||
// realpath,
|
||||
realpathSync,
|
||||
// rename,
|
||||
renameSync,
|
||||
// stat,
|
||||
statSync,
|
||||
// fstat,
|
||||
fstatSync,
|
||||
// lstat,
|
||||
lstatSync,
|
||||
// truncate,
|
||||
truncateSync,
|
||||
// ftruncate,
|
||||
ftruncateSync,
|
||||
// unlink,
|
||||
unlinkSync,
|
||||
// utimes,
|
||||
utimesSync,
|
||||
// futimes,
|
||||
futimesSync,
|
||||
watchFile,
|
||||
unwatchFile,
|
||||
// write,
|
||||
writeSync
|
||||
} from 'graceful-fs';
|
||||
|
||||
export interface DirectoryOptions {
|
||||
ignoreHidden?: boolean;
|
||||
ignorePattern?: RegExp;
|
||||
}
|
||||
|
||||
export interface AppendFileOptions {
|
||||
encoding?: string | null;
|
||||
mode?: string | number;
|
||||
flag?: string;
|
||||
}
|
||||
|
||||
// access
|
||||
export let F_OK: number | undefined;
|
||||
export let R_OK: number | undefined;
|
||||
export let W_OK: number | undefined;
|
||||
export let X_OK: number | undefined;
|
||||
|
||||
export let access: ((path: PathLike, mode?: number) => Promise<void>) | undefined; // promisify
|
||||
export let accessSync: ((path: PathLike, mode?: number) => void) | undefined; // promisify
|
||||
|
||||
// appendFile
|
||||
/**
|
||||
* Appends data to a file.
|
||||
* @param path
|
||||
* @param data
|
||||
* @param callback
|
||||
*/
|
||||
export function appendFile(path: string, data: any, callback?: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Appends data to a file.
|
||||
* @param path
|
||||
* @param data
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function appendFile(path: string, data: any, options: string | AppendFileOptions, callback?: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Synchronous version of fs.appendFile.
|
||||
* @param path
|
||||
* @param data
|
||||
* @param options
|
||||
*/
|
||||
export function appendFileSync(path: string, data: any, options?: string | AppendFileOptions): void;
|
||||
|
||||
// chmod
|
||||
export function chmod(path: PathLike, mode: string | number): Promise<void>; // promisify
|
||||
export function fchmod(fd: number, mode: string | number): Promise<void>; // promisify
|
||||
export function lchmod(path: PathLike, mode: string | number): Promise<void>; // promisify
|
||||
export { chmodSync, fchmodSync, lchmodSync };
|
||||
|
||||
// chown
|
||||
export function chown(path: PathLike, uid: number, gid: number): Promise<void>; // promisify
|
||||
export function fchown(fd: number, uid: number, gid: number): Promise<void>; // promisify
|
||||
export function lchown(path: PathLike, uid: number, gid: number): Promise<void>; // promisify
|
||||
export { chownSync, fchownSync, lchownSync };
|
||||
|
||||
// close
|
||||
export function close(fd: number): Promise<void>; // promisify
|
||||
export { closeSync };
|
||||
|
||||
// copy
|
||||
/**
|
||||
* Copies a directory from src to dest. It returns an array of copied files.
|
||||
* @param src
|
||||
* @param dest
|
||||
* @param callback
|
||||
*/
|
||||
export function copyDir(src: string, dest: string, callback?: (err: any, value?: string[]) => void): Promise<string[]>;
|
||||
/**
|
||||
* Copies a directory from src to dest. It returns an array of copied files.
|
||||
* @param dest
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function copyDir(src: string, dest: string, options?: DirectoryOptions, callback?: (err: any, value?: string[]) => void): Promise<string[]>;
|
||||
/**
|
||||
* Copies a file from src to dest.
|
||||
* @param src
|
||||
* @param dest
|
||||
* @param callback
|
||||
*/
|
||||
export function copyFile(src: PathLike, dest: string, callback?: (err: any) => void): Promise<void>;
|
||||
|
||||
// createStream
|
||||
export { createReadStream, createWriteStream };
|
||||
|
||||
// emptyDir
|
||||
/**
|
||||
* Deletes all files in a directory. It returns an array of deleted files.
|
||||
* @param path
|
||||
* @param callback
|
||||
*/
|
||||
export function emptyDir(path: string, callback?: (err: any, value?: string | string[]) => void): Promise<string | string[]>;
|
||||
export function emptyDir(
|
||||
path: string,
|
||||
options?: DirectoryOptions & { exclude?: string[] },
|
||||
callback?: (err: any, value?: string | string[]) => void
|
||||
): Promise<string | string[]>;
|
||||
export function emptyDirSync(path: string, options?: DirectoryOptions & { exclude?: string[] }, parent?: string): string | string[];
|
||||
|
||||
// ensurePath
|
||||
/**
|
||||
* Ensures the given path is available to use or appends a number to the path.
|
||||
* @param path
|
||||
* @param callback
|
||||
*/
|
||||
export function ensurePath(path: string, callback?: (err: any, value?: string) => void): Promise<string>;
|
||||
/**
|
||||
* Synchronous version of `fs.ensurePath`.
|
||||
* @param path
|
||||
*/
|
||||
export function ensurePathSync(path: string): string;
|
||||
|
||||
// ensureWriteStream
|
||||
/**
|
||||
* Creates the parent directories if they does not exist and returns a writable stream.
|
||||
* @param path
|
||||
* @param callback
|
||||
*/
|
||||
export function ensureWriteStream(path: string, callback?: (err: any, value?: WriteStream) => void): Promise<WriteStream>;
|
||||
/**
|
||||
* Creates the parent directories if they does not exist and returns a writable stream.
|
||||
* @param path
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function ensureWriteStream(
|
||||
path: string,
|
||||
options?: string | {
|
||||
flags?: string;
|
||||
defaultEncoding?: string;
|
||||
fd?: number;
|
||||
mode?: number;
|
||||
autoClose?: boolean;
|
||||
start?: number;
|
||||
},
|
||||
callback?: (err: any, value?: WriteStream) => void
|
||||
): Promise<WriteStream>;
|
||||
/**
|
||||
* Synchronous version of fs.ensureWriteStream.
|
||||
* @param path
|
||||
* @param options
|
||||
*/
|
||||
export function ensureWriteStreamSync(path: string, options?: string | {
|
||||
flags?: string;
|
||||
defaultEncoding?: string;
|
||||
fd?: number;
|
||||
mode?: number;
|
||||
autoClose?: boolean;
|
||||
start?: number;
|
||||
}): WriteStream;
|
||||
|
||||
// exists
|
||||
/**
|
||||
* Test whether or not the given `path` exists by checking with the file system.
|
||||
* @param path checking if exists.
|
||||
* @param callback
|
||||
*/
|
||||
export function exists(path: PathLike, callback?: (exist: boolean) => void): Promise<boolean>;
|
||||
/**
|
||||
* Synchronous version of `fs.exists`.
|
||||
* @param path
|
||||
*/
|
||||
export function existsSync(path: PathLike): boolean;
|
||||
|
||||
// fsync
|
||||
export function fsync(fd: number): Promise<void>; // promisify
|
||||
export { fsyncSync };
|
||||
|
||||
// link
|
||||
export function link(existingPath: PathLike, newPath: PathLike): Promise<void>; // promisify
|
||||
export { linkSync };
|
||||
|
||||
// listDir
|
||||
/**
|
||||
* Lists files in a directory.
|
||||
* @param path
|
||||
* @param callback
|
||||
*/
|
||||
export function listDir(path: string, callback?: (err: any, value?: string[]) => void): Promise<string[]>;
|
||||
/**
|
||||
* Lists files in a directory.
|
||||
* @param path
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function listDir(path: string, options?: DirectoryOptions, callback?: (err: any, value?: string[]) => void): Promise<string[]>;
|
||||
/**
|
||||
* Synchronous version of `fs.listDir`.
|
||||
* @param path
|
||||
* @param options
|
||||
* @param parent
|
||||
*/
|
||||
export function listDirSync(path: string, options?: DirectoryOptions, parent?: string): string | string[];
|
||||
|
||||
// mkdir
|
||||
export function mkdir(path: PathLike, mode?: string | number): Promise<void>; // promisify
|
||||
export { mkdirSync };
|
||||
|
||||
// mkdirs
|
||||
/**
|
||||
* Creates a directory and its parent directories if they does not exist.
|
||||
* @param path
|
||||
* @param callback
|
||||
*/
|
||||
export function mkdirs(path: PathLike, callback?: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Synchronous version of `fs.mkdirs`.
|
||||
* @param path
|
||||
*/
|
||||
export function mkdirsSync(path: string): void;
|
||||
|
||||
// open
|
||||
export function open(path: PathLike, flags: string | number, mode?: string | number | null): Promise<number>; // promisify
|
||||
export { openSync };
|
||||
|
||||
// symlink
|
||||
export function symlink(target: PathLike, path: PathLike, type?: string | null): Promise<void>; // promisify
|
||||
export { symlinkSync };
|
||||
|
||||
// read
|
||||
export function read<TBuffer extends Buffer | Uint8Array>(
|
||||
fd: number,
|
||||
buffer: TBuffer,
|
||||
offset: number,
|
||||
length: number,
|
||||
position: number | null
|
||||
): Promise<{ bytesRead: number, buffer: TBuffer }>; // promisify
|
||||
export { readSync };
|
||||
|
||||
// readdir
|
||||
export function readdir(path: PathLike, options?: { encoding: BufferEncoding | null } | BufferEncoding | null): Promise<string[]>; // promisify
|
||||
export function readdir(path: PathLike, options: "buffer" | { encoding: "buffer" }): Promise<Buffer[]>; // promisify
|
||||
export function readdir(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<Array<string | Buffer>>; // promisify
|
||||
export { readdirSync };
|
||||
|
||||
// readFile
|
||||
/**
|
||||
* Reads the entire contents of a file.
|
||||
* @param path
|
||||
* @param callback
|
||||
*/
|
||||
export function readFile(path: PathLike | number, callback?: (err: any, value?: string) => void): Promise<string>;
|
||||
/**
|
||||
* Reads the entire contents of a file.
|
||||
* @param path
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function readFile(
|
||||
path: PathLike | number,
|
||||
options?: { encoding?: string; flag?: string; escape?: boolean; },
|
||||
callback?: (err: any, value?: string) => void
|
||||
): Promise<string>;
|
||||
/**
|
||||
* Synchronous version of `fs.readFile`.
|
||||
* @param path
|
||||
* @param options
|
||||
*/
|
||||
export function readFileSync(path: PathLike | number, options?: { encoding?: string; flag?: string; escape?: boolean; }): string;
|
||||
|
||||
// readlink
|
||||
export function readlink(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>; // promisify
|
||||
export function readlink(path: PathLike, options: { encoding: 'buffer' } | 'buffer'): Promise<Buffer>; // promisify
|
||||
export function readlink(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>; // promisify
|
||||
export { readlinkSync };
|
||||
|
||||
// realpath
|
||||
export function realpath(path: PathLike, options?: { encoding?: BufferEncoding | null } | BufferEncoding | null): Promise<string>; // promisify
|
||||
export function realpath(path: PathLike, options: { encoding: 'buffer' } | 'buffer'): Promise<Buffer>; // promisify
|
||||
export function realpath(path: PathLike, options?: { encoding?: string | null } | string | null): Promise<string | Buffer>; // promisify
|
||||
export { realpathSync };
|
||||
|
||||
// rename
|
||||
export function rename(oldPath: PathLike, newPath: PathLike): Promise<void>; // promisify
|
||||
export { renameSync };
|
||||
|
||||
// rmdir
|
||||
export function rmdir(path: string, callback?: (err: any) => void): Promise<void>;
|
||||
export function rmdirSync(path: string): void;
|
||||
|
||||
// stat
|
||||
export function stat(path: PathLike): Promise<Stats>; // promisify
|
||||
export function fstat(fd: number): Promise<Stats>; // promisify
|
||||
export function lstat(path: PathLike): Promise<Stats>; // promisify
|
||||
export { statSync, fstatSync, lstatSync };
|
||||
|
||||
// truncate
|
||||
export function truncate(path: PathLike, len?: number | null): Promise<void>; // promisify
|
||||
export function ftruncate(fd: number, len?: number | null): Promise<void>; // promisify
|
||||
export { truncateSync, ftruncateSync };
|
||||
|
||||
// unlink
|
||||
export function unlink(path: PathLike): Promise<void>; // promisify
|
||||
export { unlinkSync };
|
||||
|
||||
// utimes
|
||||
export function utimes(path: PathLike, atime: string | number | Date, mtime: string | number | Date): Promise<void>; // promisify
|
||||
export function futimes(fd: number, atime: string | number | Date, mtime: string | number | Date): Promise<void>; // promisify
|
||||
export { utimesSync, futimesSync };
|
||||
|
||||
// watch
|
||||
import { FSWatcher, WatchOptions } from 'chokidar';
|
||||
/**
|
||||
* Watches changes of a file or a directory.
|
||||
*
|
||||
* See Chokidar API for more info.
|
||||
* @param path
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function watch(path: string | string[], options?: WatchOptions, callback?: (err: any, value?: FSWatcher) => void): Promise<FSWatcher>;
|
||||
export { watchFile, unwatchFile };
|
||||
|
||||
// write
|
||||
export function write<TBuffer extends Buffer | Uint8Array>(
|
||||
fd: number,
|
||||
buffer?: TBuffer,
|
||||
offset?: number,
|
||||
length?: number,
|
||||
position?: number | null
|
||||
): Promise<{ bytesWritten: number, buffer: TBuffer }>; // promisify
|
||||
export function write(
|
||||
fd: number,
|
||||
string: any,
|
||||
position?: number | null,
|
||||
encoding?: string | null
|
||||
): Promise<{ bytesWritten: number, buffer: string }>; // promisify
|
||||
export { writeSync };
|
||||
|
||||
// writeFile
|
||||
/**
|
||||
* Writes data to a file.
|
||||
* @param path
|
||||
* @param data
|
||||
* @param callback
|
||||
*/
|
||||
export function writeFile(path: string, data: any, callback?: (err: any) => void): Promise<void>;
|
||||
/**
|
||||
* Writes data to a file.
|
||||
* @param path
|
||||
* @param data
|
||||
* @param options
|
||||
* @param callback
|
||||
*/
|
||||
export function writeFile(
|
||||
path: string,
|
||||
data: any,
|
||||
options?: string | { encoding?: string | null; mode?: string | number; flag?: string },
|
||||
callback?: (err: any) => void
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Synchronous version of `fs.writeFile`.
|
||||
* @param path
|
||||
* @param data
|
||||
* @param options
|
||||
*/
|
||||
export function writeFileSync(path: string, data: any, options?: string | { encoding?: string | null; mode?: string | number; flag?: string }): void;
|
||||
|
||||
// Static classes
|
||||
export let Stats: Stats;
|
||||
export let ReadStream: ReadStream;
|
||||
export let WriteStream: WriteStream;
|
||||
|
||||
// util
|
||||
export function escapeEOL(str: string): string;
|
||||
export function escapeBOM(str: string): string;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"hexo-fs-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// Type definitions for jpeg-js 0.3
|
||||
// Project: https://github.com/eugeneware/jpeg-js#readme
|
||||
// Definitions by: Daniel Rosenwasser <https://github.com/DanielRosenwasser>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
export interface RawImageData<D extends Uint8Array> {
|
||||
data: D;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
export function decode(jpegData: ArrayLike<number> | Iterable<number> | ArrayBuffer, useTypedArray: true): RawImageData<Uint8Array>;
|
||||
export function decode(jpegData: ArrayLike<number> | Iterable<number> | ArrayBuffer, useTypedArray?: false): RawImageData<Buffer>;
|
||||
export function decode(jpegData: ArrayLike<number> | Iterable<number> | ArrayBuffer, useTypedArray: boolean): RawImageData<Uint8Array | Buffer>;
|
||||
|
||||
export function encode(imgData: RawImageData<Uint8Array | Buffer>, qu?: number): RawImageData<Buffer>;
|
||||
@@ -0,0 +1,15 @@
|
||||
import jpeg = require("jpeg-js");
|
||||
import fs = require("fs");
|
||||
|
||||
const x = fs.readFileSync("hello.jpg");
|
||||
const decoded = jpeg.decode(x, true);
|
||||
|
||||
const { width, height } = decoded;
|
||||
|
||||
width; // $ExpectType number
|
||||
height; // $ExpectType number
|
||||
decoded.data; // $ExpectType Uint8Array
|
||||
|
||||
fs.writeFileSync("re-encoded.jpg", jpeg.encode({
|
||||
width, height, data: decoded.data
|
||||
}, 50));
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es2015"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"jpeg-js-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+1
-1
@@ -69,4 +69,4 @@ declare namespace Qty {
|
||||
type UnitSource = Qty | string;
|
||||
}
|
||||
|
||||
export default Qty;
|
||||
export = Qty;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Qty from "js-quantities";
|
||||
import Qty = require("js-quantities");
|
||||
|
||||
declare function describe(desc: string, fn: () => void): void;
|
||||
declare function it(desc: string, fn: () => void): void;
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -14,6 +14,7 @@ interface MarkdownItStatic {
|
||||
|
||||
declare var MarkdownIt: MarkdownItStatic;
|
||||
export = MarkdownIt;
|
||||
export as namespace markdownit;
|
||||
|
||||
declare module MarkdownIt {
|
||||
interface MarkdownIt {
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
// Usage: ts-node generate.ts
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import {get} from 'https';
|
||||
import {readdir, readFile, writeFile} from 'fs';
|
||||
import {join, extname, basename, dirname, relative} from 'path';
|
||||
|
||||
const token = process.env.GITHUB_ACCESS_TOKEN || ''
|
||||
|
||||
const toMixedCase = (name) => {
|
||||
let dist = name[0].toUpperCase()
|
||||
for (let i = 1; i < name.length; i++) {
|
||||
const c = name[i]
|
||||
if (c !== '-') {
|
||||
dist += c
|
||||
continue
|
||||
}
|
||||
i++
|
||||
dist += name[i].toUpperCase()
|
||||
}
|
||||
return dist
|
||||
}
|
||||
|
||||
const github = (path) => new Promise((resolve, reject) => {
|
||||
get({
|
||||
headers: {'user-agent': 'DefinitelyTyped/material-ui/generate'},
|
||||
host: 'api.github.com',
|
||||
path,
|
||||
}, (res) => {
|
||||
if ((res.statusCode / 100 >> 0) != 2) {
|
||||
reject(`GitHub response: ${res.statusCode} ${res.statusMessage}`)
|
||||
return
|
||||
}
|
||||
let data = '';
|
||||
res
|
||||
.on('data', (chunk) => data += chunk)
|
||||
.on('end', () => resolve(JSON.parse(data)))
|
||||
}).on('error', reject)
|
||||
})
|
||||
|
||||
const categories = () => github(`/repos/callemall/material-ui/contents/src/svg-icons?ref=master&access_token=${token}`)
|
||||
|
||||
const contents = (path) => github(`/repos/callemall/material-ui/contents/${path}?ref=master&access_token=${token}`)
|
||||
|
||||
const collator = new Intl.Collator()
|
||||
|
||||
const resolvePath = (filename) => join(__dirname, '..', filename)
|
||||
|
||||
const readText = (filename) => new Promise<string>((resolve, reject) => {
|
||||
readFile(resolvePath(filename), 'utf8', (err, data) => {
|
||||
if (err != null) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
resolve(data)
|
||||
})
|
||||
})
|
||||
|
||||
const writeText = (filename, text) => new Promise((resolve, reject) => {
|
||||
writeFile(resolvePath(filename), text, 'utf8', (err) => {
|
||||
if (err != null) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
|
||||
const inject = (content) => {
|
||||
content.category = this.name
|
||||
return content
|
||||
}
|
||||
|
||||
const rMark = /(\/{2} \{{3})[\s\S]*?(\/{2} \}{3})/g
|
||||
|
||||
main().catch((err) => console.error(err));
|
||||
|
||||
async function main() {
|
||||
const cats = await categories();
|
||||
const contentsList = await Promise.all(Array.prototype.map.call(cats, (cat) => contents(cat.path)
|
||||
.then((cons) => Array.prototype.map.call(cons, (con) => {
|
||||
con.category = cat.name
|
||||
return con
|
||||
}))
|
||||
));
|
||||
const { dts, test } = await Array.prototype.concat.apply([], contentsList)
|
||||
.map((content) => {
|
||||
const {path} = content
|
||||
const name = basename(path, extname(path))
|
||||
content.id = join(relative('src', dirname(path)), name)
|
||||
content.className = toMixedCase(content.category) + toMixedCase(name)
|
||||
return content
|
||||
})
|
||||
.sort((a, b) => collator.compare(a.id, b.id))
|
||||
.reduce((prev, content) => {
|
||||
const {dts, test} = prev
|
||||
dts.individuals.push(`declare module 'material-ui/${content.id}' {
|
||||
export import ${content.className} = __MaterialUI.SvgIcon;
|
||||
export default ${content.className};
|
||||
}`)
|
||||
dts.summarizeds.push(` export import ${content.className} = __MaterialUI.SvgIcon; // require('material-ui/${content.id}');`)
|
||||
|
||||
test.individuals.push(`import _${content.className} from 'material-ui/${content.id}';`)
|
||||
test.summarizeds.push(` ${content.className},`)
|
||||
return prev
|
||||
}, {
|
||||
dts: {individuals: [], summarizeds: []},
|
||||
test: {individuals: [], summarizeds: []},
|
||||
});
|
||||
|
||||
{
|
||||
const {individuals, summarizeds} = dts
|
||||
const file = 'index.d.ts'
|
||||
let index = 0
|
||||
const script = await readText(file)
|
||||
await writeText(file, script.replace(rMark, (_, p1, p2) => {
|
||||
let text = ''
|
||||
switch (index) {
|
||||
case 0:
|
||||
text = individuals.join('\n\n')
|
||||
break
|
||||
case 1:
|
||||
text = summarizeds.join('\n')
|
||||
break
|
||||
}
|
||||
index++
|
||||
return p1 + '\n' + text + '\n' + p2
|
||||
}))
|
||||
}
|
||||
|
||||
{
|
||||
const {individuals, summarizeds} = test
|
||||
const file = 'material-ui-tests.tsx'
|
||||
let index = 0
|
||||
const script = await readText(file)
|
||||
await writeText(file, script.replace(rMark, (_, p1, p2) => {
|
||||
let text = ''
|
||||
switch (index) {
|
||||
case 0:
|
||||
text = individuals.join('\n')
|
||||
break
|
||||
case 1:
|
||||
text = summarizeds.join('\n')
|
||||
break
|
||||
}
|
||||
index++
|
||||
return p1 + '\n' + text + '\n' + p2
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"baseUrl": "../..",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": []
|
||||
}
|
||||
}
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+4
-4
@@ -5,10 +5,10 @@ interface EJSONableCustomType {
|
||||
typeName(): string;
|
||||
}
|
||||
interface EJSONable {
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[] | Date | Uint8Array | EJSONableCustomType;
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[] | Date | Uint8Array | EJSONableCustomType | undefined | null;
|
||||
}
|
||||
interface JSONable {
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[];
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[] | undefined | null;
|
||||
}
|
||||
interface EJSON extends EJSONable { }
|
||||
|
||||
@@ -44,10 +44,10 @@ declare module "meteor/ejson" {
|
||||
typeName(): string;
|
||||
}
|
||||
interface EJSONable {
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[] | Date | Uint8Array | EJSONableCustomType;
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[] | Date | Uint8Array | EJSONableCustomType | undefined | null;
|
||||
}
|
||||
interface JSONable {
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[];
|
||||
[key: string]: number | string | boolean | Object | number[] | string[] | Object[] | undefined | null;
|
||||
}
|
||||
interface EJSON extends EJSONable { }
|
||||
|
||||
|
||||
Vendored
+4
-1
@@ -214,7 +214,10 @@ declare module "meteor/mongo" {
|
||||
interface ObjectIDStatic {
|
||||
new (hexString?: string): ObjectID;
|
||||
}
|
||||
interface ObjectID { }
|
||||
interface ObjectID {
|
||||
toHexString(): string;
|
||||
equals(otherID: ObjectID): boolean;
|
||||
}
|
||||
|
||||
function setConnectionOptions(options: any): void;
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+876
-90
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,5 @@
|
||||
import * as nano from "nano";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as nano from "nano";
|
||||
|
||||
/*
|
||||
* Instantiate with configuration object
|
||||
@@ -67,10 +66,15 @@ db.replicate("a", "b", (error: any) => {});
|
||||
/*
|
||||
* Document Scope
|
||||
*/
|
||||
const mydb: nano.DocumentScope = instance.use("mydb");
|
||||
interface SomeDocument {
|
||||
name: string;
|
||||
}
|
||||
|
||||
mydb.insert({ foo: "baz" }, null, (err, response) => {});
|
||||
mydb.insert({ foo: "baz" }, "foobar", (error, foo) => {});
|
||||
const mydb: nano.DocumentScope<SomeDocument> = instance.use("mydb");
|
||||
|
||||
mydb.insert({ name: "baz" }, null, (err, response) => {});
|
||||
mydb.insert({ name: "baz" }, "foobar", (error, foo) => {});
|
||||
mydb.insert({ name: "baz" }, { new_edits: true }, (error, foo) => {});
|
||||
mydb.get("foobaz", { revs_info: true }, (error, foobaz) => {});
|
||||
mydb.head("foobaz", (error, body, headers) => {});
|
||||
mydb.copy(
|
||||
@@ -129,7 +133,7 @@ mydb.attachment.get("new_string", "att", (error: any, helloWorld: any) => {});
|
||||
/*
|
||||
* Multipart
|
||||
*/
|
||||
mydb.multipart.insert({ foo: "baz" }, [{}], "foobaz", (error, foo) => {});
|
||||
mydb.multipart.insert({ name: "baz" }, [{}], "foobaz", (error, foo) => {});
|
||||
mydb.multipart.get("foobaz", (error: any, foobaz: any, headers: any) => {});
|
||||
|
||||
/*
|
||||
|
||||
Vendored
+8
@@ -347,6 +347,10 @@ export class StateContext {
|
||||
* Gets the NavigationData for the last displayed State
|
||||
*/
|
||||
oldData: any;
|
||||
/**
|
||||
* Gets the Url for the last displayed State
|
||||
*/
|
||||
oldUrl: string;
|
||||
/**
|
||||
* Gets the State of the last Crumb in the crumb trail
|
||||
*/
|
||||
@@ -355,6 +359,10 @@ export class StateContext {
|
||||
* Gets the NavigationData of the last Crumb in the crumb trail
|
||||
*/
|
||||
previousData: any;
|
||||
/**
|
||||
* Gets the Url of the last Crumb in the crumb trail
|
||||
*/
|
||||
previousUrl: string;
|
||||
/**
|
||||
* Gets the current State
|
||||
*/
|
||||
|
||||
@@ -83,12 +83,14 @@ link = stateNavigator.fluent()
|
||||
|
||||
// State Context
|
||||
let state: State = stateNavigator.stateContext.state;
|
||||
const url: string = stateNavigator.stateContext.url;
|
||||
let url: string = stateNavigator.stateContext.url;
|
||||
const title: string = stateNavigator.stateContext.title;
|
||||
let page: number = stateNavigator.stateContext.data.page;
|
||||
state = stateNavigator.stateContext.oldState;
|
||||
url = stateNavigator.stateContext.oldUrl;
|
||||
page = stateNavigator.stateContext.oldData.page;
|
||||
state = stateNavigator.stateContext.previousState;
|
||||
url = stateNavigator.stateContext.previousUrl;
|
||||
page = stateNavigator.stateContext.previousData.page;
|
||||
|
||||
// Navigation Data
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -91,7 +91,7 @@ declare module nes {
|
||||
id: string;
|
||||
app: Object;
|
||||
auth: nes.SocketAuthObject;
|
||||
disconect(callback?: () => void): void;
|
||||
disconnect(callback?: () => void): void;
|
||||
send(message: any, callback?: (err?: any) => void): void;
|
||||
publish(path: string, message: any, callback?: (err?: any) => void): void;
|
||||
revoke(path: string, message: any, callback?: (err?: any) => void): void;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// from https://github.com/hapijs/nes/blob/v6.4.3/lib/socket.js
|
||||
|
||||
import Nes = require('nes');
|
||||
|
||||
const socket: Nes.Socket = undefined;
|
||||
|
||||
const cb = () => { };
|
||||
socket.disconnect(cb);
|
||||
const s: string = socket.id;
|
||||
const o: Object = socket.app;
|
||||
const auth: Nes.SocketAuthObject = socket.auth;
|
||||
|
||||
const cb2 = (err?: any) => { };
|
||||
socket.send('message', (err?: any) => { });
|
||||
socket.publish('path', 'message', cb2);
|
||||
socket.revoke('path', 'message', cb2);
|
||||
@@ -26,9 +26,10 @@
|
||||
"test/route-authentication-server.ts",
|
||||
"test/route-invocation-client.ts",
|
||||
"test/route-invocation-server.ts",
|
||||
"test/socket.ts",
|
||||
"test/subscription-filter-client.ts",
|
||||
"test/subscription-filter-server.ts",
|
||||
"test/subscriptions-client.ts",
|
||||
"test/subscriptions-server.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+37
-1
@@ -93,10 +93,17 @@ interface NodeRequireFunction {
|
||||
interface NodeRequire extends NodeRequireFunction {
|
||||
resolve(id: string): string;
|
||||
cache: any;
|
||||
extensions: any;
|
||||
extensions: NodeExtensions;
|
||||
main: NodeModule | undefined;
|
||||
}
|
||||
|
||||
interface NodeExtensions {
|
||||
'.js': (m: NodeModule, filename: string) => any;
|
||||
'.json': (m: NodeModule, filename: string) => any;
|
||||
'.node': (m: NodeModule, filename: string) => any;
|
||||
[ext: string]: (m: NodeModule, filename: string) => any;
|
||||
}
|
||||
|
||||
declare var require: NodeRequire;
|
||||
|
||||
interface NodeModule {
|
||||
@@ -1632,6 +1639,9 @@ declare module "repl" {
|
||||
|
||||
export interface REPLServer extends readline.ReadLine {
|
||||
context: any;
|
||||
inputStream: NodeJS.ReadableStream;
|
||||
outputStream: NodeJS.WritableStream;
|
||||
|
||||
defineCommand(keyword: string, cmd: Function | { help: string, action: Function }): void;
|
||||
displayPrompt(preserveCursor?: boolean): void;
|
||||
|
||||
@@ -1667,6 +1677,12 @@ declare module "repl" {
|
||||
}
|
||||
|
||||
export function start(options?: string | ReplOptions): REPLServer;
|
||||
|
||||
export class Recoverable extends SyntaxError {
|
||||
err: Error;
|
||||
|
||||
constructor(err: Error);
|
||||
}
|
||||
}
|
||||
|
||||
declare module "readline" {
|
||||
@@ -5592,6 +5608,26 @@ declare module "constants" {
|
||||
export var ALPN_ENABLED: number;
|
||||
}
|
||||
|
||||
declare module "module" {
|
||||
class Module implements NodeModule {
|
||||
static runMain(): void;
|
||||
static wrap(code: string): string;
|
||||
|
||||
exports: any;
|
||||
require: NodeRequireFunction;
|
||||
id: string;
|
||||
filename: string;
|
||||
loaded: boolean;
|
||||
parent: NodeModule | null;
|
||||
children: NodeModule[];
|
||||
paths: string[];
|
||||
|
||||
constructor(id: string, parent?: Module);
|
||||
}
|
||||
|
||||
export = Module;
|
||||
}
|
||||
|
||||
declare module "process" {
|
||||
export = process;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import * as v8 from "v8";
|
||||
import * as dns from "dns";
|
||||
import * as async_hooks from "async_hooks";
|
||||
import * as http2 from "http2";
|
||||
import Module = require("module");
|
||||
|
||||
// Specifically test buffer module regression.
|
||||
import { Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer } from "buffer";
|
||||
@@ -2532,6 +2533,11 @@ namespace repl_tests {
|
||||
|
||||
_server = _server.prependOnceListener("exit", () => { });
|
||||
_server = _server.prependOnceListener("reset", () => { });
|
||||
|
||||
_server.outputStream.write("test");
|
||||
let line = _server.inputStream.read();
|
||||
|
||||
throw new repl.Recoverable(new Error("test"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3380,3 +3386,16 @@ namespace http2_tests {
|
||||
str = constants.HTTP2_METHOD_VERSION_CONTROL;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
/// module tests : http://nodejs.org/api/modules.html
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
namespace module_tests {
|
||||
require.extensions[".ts"] = () => "";
|
||||
|
||||
Module.runMain();
|
||||
Module.wrap("some code");
|
||||
|
||||
const m1 = new Module("moduleId");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"no-namespace": false,
|
||||
"no-padding": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-var-keyword": false,
|
||||
"object-literal-shorthand": false,
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+8
-2
@@ -12578,11 +12578,15 @@ declare module olx {
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{duration: (number|undefined),
|
||||
* @typedef {{constrainResolution: (boolean|undefined),
|
||||
* duration: (number|undefined),
|
||||
* timeout: (number|undefined),
|
||||
* useAnchor: (boolean|undefined)}}
|
||||
*/
|
||||
interface MouseWheelZoomOptions {
|
||||
constrainResolution?: boolean;
|
||||
duration?: number;
|
||||
timeout?: number;
|
||||
useAnchor?: boolean;
|
||||
}
|
||||
|
||||
@@ -12598,9 +12602,11 @@ declare module olx {
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{duration: (number|undefined)}}
|
||||
* @typedef {{constrainResolution: (boolean|undefined)
|
||||
* duration: (number|undefined)}}
|
||||
*/
|
||||
interface PinchZoomOptions {
|
||||
constrainResolution?: boolean;
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -717,6 +717,17 @@ const select: ol.interaction.Select = new ol.interaction.Select({
|
||||
layers: (layer: ol.layer.Layer) => true,
|
||||
});
|
||||
|
||||
let pinchZoom: ol.interaction.PinchZoom = new ol.interaction.PinchZoom({
|
||||
constrainResolution: booleanValue,
|
||||
duration: numberValue
|
||||
});
|
||||
|
||||
let mouseWheelZoom: ol.interaction.MouseWheelZoom = new ol.interaction.MouseWheelZoom({
|
||||
constrainResolution: booleanValue,
|
||||
duration: numberValue,
|
||||
timeout: numberValue,
|
||||
useAnchor: booleanValue
|
||||
});
|
||||
//
|
||||
// ol.style.RegularShape
|
||||
//
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ const options: QueryStream.Options = {
|
||||
|
||||
const query = new QueryStream('SELECT * FROM generate_series(0, $1) num', [1000000], options);
|
||||
|
||||
pg.connect('', (err, client, done) => {
|
||||
const pool = new pg.Pool();
|
||||
pool.connect((err, client, done) => {
|
||||
const stream = client.query(query);
|
||||
stream.on('end', () => {
|
||||
client.end();
|
||||
@@ -17,3 +18,4 @@ pg.connect('', (err, client, done) => {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
pool.end();
|
||||
|
||||
Vendored
+37
-24
@@ -1,6 +1,6 @@
|
||||
// Type definitions for pg 6.1
|
||||
// Type definitions for pg 7.1
|
||||
// Project: https://github.com/brianc/node-postgres
|
||||
// Definitions by: Phips Peter <http://pspeter3.com>
|
||||
// Definitions by: Phips Peter <https://github.com/pspeter3>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
@@ -9,16 +9,13 @@ import events = require("events");
|
||||
import stream = require("stream");
|
||||
import pgTypes = require("pg-types");
|
||||
|
||||
export declare function connect(connection: string, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
|
||||
export declare function connect(config: ClientConfig, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
|
||||
export declare function end(): void;
|
||||
|
||||
export interface ConnectionConfig {
|
||||
user?: string;
|
||||
database?: string;
|
||||
password?: string;
|
||||
port?: number;
|
||||
host?: string;
|
||||
connectionString?: string;
|
||||
}
|
||||
|
||||
export interface Defaults extends ConnectionConfig {
|
||||
@@ -39,10 +36,9 @@ export interface PoolConfig extends ClientConfig {
|
||||
// properties from module 'node-pool'
|
||||
max?: number;
|
||||
min?: number;
|
||||
refreshIdle?: boolean;
|
||||
connectionTimeoutMillis?: number;
|
||||
idleTimeoutMillis?: number;
|
||||
reapIntervalMillis?: number;
|
||||
returnToHead?: boolean;
|
||||
|
||||
application_name?: string;
|
||||
Promise?: PromiseConstructorLike;
|
||||
}
|
||||
@@ -60,25 +56,35 @@ export interface QueryResult {
|
||||
rows: any[];
|
||||
}
|
||||
|
||||
export interface Notification {
|
||||
processId: number;
|
||||
channel: string;
|
||||
payload?: string;
|
||||
}
|
||||
|
||||
export interface ResultBuilder extends QueryResult {
|
||||
addRow(row: any): void;
|
||||
}
|
||||
|
||||
export declare class Pool extends events.EventEmitter {
|
||||
export class Pool extends events.EventEmitter {
|
||||
// `new Pool('pg://user@localhost/mydb')` is not allowed.
|
||||
// But it passes type check because of issue:
|
||||
// https://github.com/Microsoft/TypeScript/issues/7485
|
||||
constructor(config?: PoolConfig);
|
||||
|
||||
readonly totalCount: number;
|
||||
readonly idleCount: number;
|
||||
readonly waitingCount: number;
|
||||
|
||||
connect(): Promise<Client>;
|
||||
connect(callback: (err: Error, client: Client, done: () => void) => void): void;
|
||||
|
||||
end(callback?: () => void): Promise<void>;
|
||||
end(): Promise<void>;
|
||||
end(callback: () => void): void;
|
||||
|
||||
query(queryStream: QueryConfig & stream.Readable): stream.Readable;
|
||||
query(queryTextOrConfig: string | QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values: any[]): Promise<QueryResult>;
|
||||
|
||||
query(queryConfig: QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values?: any[]): Promise<QueryResult>;
|
||||
query(queryTextOrConfig: string | QueryConfig, callback: (err: Error, result: QueryResult) => void): Query;
|
||||
query(queryText: string, values: any[], callback: (err: Error, result: QueryResult) => void): Query;
|
||||
|
||||
@@ -86,18 +92,20 @@ export declare class Pool extends events.EventEmitter {
|
||||
on(event: "connect" | "acquire", listener: (client: Client) => void): this;
|
||||
}
|
||||
|
||||
export declare class Client extends events.EventEmitter {
|
||||
constructor(connection: string);
|
||||
export class Client extends events.EventEmitter {
|
||||
constructor(config: ClientConfig);
|
||||
|
||||
connect(callback?: (err: Error) => void): void;
|
||||
end(callback?: (err: Error) => void): void;
|
||||
connect(): Promise<Client>;
|
||||
connect(callback: (err: Error) => void): void;
|
||||
|
||||
end(): Promise<void>;
|
||||
end(callback: (err: Error) => void): void;
|
||||
|
||||
release(err?: Error): void;
|
||||
|
||||
query(queryStream: QueryConfig & stream.Readable): stream.Readable;
|
||||
query(queryTextOrConfig: string | QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values: any[]): Promise<QueryResult>;
|
||||
|
||||
query(queryConfig: QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values?: any[]): Promise<QueryResult>;
|
||||
query(queryTextOrConfig: string | QueryConfig, callback: (err: Error, result: QueryResult) => void): Query;
|
||||
query(queryText: string, values: any[], callback: (err: Error, result: QueryResult) => void): Query;
|
||||
|
||||
@@ -109,20 +117,25 @@ export declare class Client extends events.EventEmitter {
|
||||
|
||||
on(event: "drain", listener: () => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "notification" | "notice", listener: (message: any) => void): this;
|
||||
on(event: "notification" | "notice", listener: (message: Notification) => void): this;
|
||||
// tslint:disable-next-line unified-signatures
|
||||
on(event: "end", listener: () => void): this;
|
||||
}
|
||||
|
||||
export declare class Query extends events.EventEmitter {
|
||||
export class Query extends events.EventEmitter {
|
||||
on(event: "row", listener: (row: any, result?: ResultBuilder) => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "end", listener: (result: ResultBuilder) => void): this;
|
||||
}
|
||||
|
||||
export declare class Events extends events.EventEmitter {
|
||||
export class Events extends events.EventEmitter {
|
||||
on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
}
|
||||
|
||||
export const types: typeof pgTypes;
|
||||
|
||||
export const defaults: Defaults & ClientConfig;
|
||||
|
||||
import * as Pg from 'pg';
|
||||
|
||||
export const native: typeof Pg | null;
|
||||
|
||||
+100
-45
@@ -1,39 +1,24 @@
|
||||
import * as pg from "pg";
|
||||
|
||||
var conString = "postgres://username:password@localhost/database";
|
||||
|
||||
// https://github.com/brianc/node-pg-types
|
||||
// tslint:disable-next-line no-unnecessary-callback-wrapper
|
||||
pg.types.setTypeParser(20, val => Number(val));
|
||||
|
||||
// Client pooling
|
||||
pg.defaults.ssl = true;
|
||||
pg.connect(conString, (err, client, done) => {
|
||||
if (err) {
|
||||
return console.error("Error fetching client from pool", err);
|
||||
}
|
||||
client.query("SELECT $1::int AS number", ["1"], (err, result) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
return console.error("Error running query", err);
|
||||
}
|
||||
else {
|
||||
done();
|
||||
}
|
||||
console.log(result.rows[0]["number"]);
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
const client = new pg.Client({
|
||||
host: 'my.database-server.com',
|
||||
port: 5334,
|
||||
user: 'database-user',
|
||||
password: 'secretpassword!!',
|
||||
});
|
||||
|
||||
// Simple
|
||||
var client = new pg.Client(conString);
|
||||
client.connect(err => {
|
||||
if (err) {
|
||||
return console.error("Could not connect to postgres", err);
|
||||
console.error("Could not connect to postgres", err);
|
||||
return;
|
||||
}
|
||||
client.query("SELECT NOW() AS 'theTime'", (err, result) => {
|
||||
if (err) {
|
||||
return console.error("Error running query", err);
|
||||
console.error("Error running query", err);
|
||||
return;
|
||||
}
|
||||
console.log(result.rowCount);
|
||||
console.log(result.rows[0]["theTime"]);
|
||||
@@ -44,38 +29,108 @@ client.connect(err => {
|
||||
});
|
||||
client.on('end', () => console.log("Client was disconnected."));
|
||||
|
||||
// client pooling
|
||||
client.connect()
|
||||
.then(() => console.log('connected'))
|
||||
.catch(e => console.error('connection error', e.stack));
|
||||
|
||||
var config = {
|
||||
user: 'foo', //env var: PGUSER
|
||||
database: 'my_db', //env var: PGDATABASE
|
||||
password: 'secret', //env var: PGPASSWORD
|
||||
port: 5432, //env var: PGPORT
|
||||
max: 10, // max number of clients in the pool
|
||||
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
|
||||
Promise,
|
||||
client.query('SELECT NOW()', (err, res) => {
|
||||
if (err) throw err;
|
||||
console.log(res);
|
||||
client.end();
|
||||
});
|
||||
|
||||
client.query('SELECT $1::text as name', ['brianc'], (err, res) => {
|
||||
if (err) throw err;
|
||||
console.log(res);
|
||||
client.end();
|
||||
});
|
||||
|
||||
const query = {
|
||||
name: 'get-name',
|
||||
text: 'SELECT $1::text',
|
||||
values: ['brianc'],
|
||||
rowMode: 'array'
|
||||
};
|
||||
var pool = new pg.Pool(config);
|
||||
client.query(query, (err, res) => {
|
||||
if (err) {
|
||||
console.error(err.stack);
|
||||
} else {
|
||||
console.log(res.rows);
|
||||
}
|
||||
});
|
||||
client.query(query)
|
||||
.then(res => {
|
||||
console.log(res.rows);
|
||||
})
|
||||
.catch(e => {
|
||||
console.error(e.stack);
|
||||
});
|
||||
|
||||
client.end((err) => {
|
||||
console.log('client has disconnected');
|
||||
if (err) {
|
||||
console.log('error during disconnection', err.stack);
|
||||
}
|
||||
});
|
||||
|
||||
client.end()
|
||||
.then(() => console.log('client has disconnected'))
|
||||
.catch(err => console.error('error during disconnection', err.stack));
|
||||
|
||||
const poolOne = new pg.Pool({
|
||||
connectionString: 'postgresql://dbuser:secretpassword@database.server.com:3211/mydb'
|
||||
});
|
||||
|
||||
const pool = new pg.Pool({
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
user: 'database-user',
|
||||
database: 'my_db',
|
||||
max: 20,
|
||||
idleTimeoutMillis: 30000,
|
||||
connectionTimeoutMillis: 2000,
|
||||
});
|
||||
console.log(pool.totalCount);
|
||||
pool.connect((err, client, done) => {
|
||||
if(err) {
|
||||
return console.error('error fetching client from pool', err);
|
||||
if (err) {
|
||||
console.error('error fetching client from pool', err);
|
||||
return;
|
||||
}
|
||||
client.query('SELECT $1::int AS number', ['1'], (err, result) => {
|
||||
done();
|
||||
|
||||
if(err) {
|
||||
return console.error('error running query', err);
|
||||
if (err) {
|
||||
console.error('error running query', err);
|
||||
return;
|
||||
}
|
||||
console.log(result.rows[0].number);
|
||||
});
|
||||
});
|
||||
|
||||
pool.on('error', (err, client) => {
|
||||
console.error('idle client error', err.message, err.stack)
|
||||
})
|
||||
|
||||
pool.end();
|
||||
pool.end(() => {
|
||||
console.log("pool is closed");
|
||||
console.error('idle client error', err.message, err.stack);
|
||||
});
|
||||
|
||||
pool.query('SELECT $1::text as name', ['brianc'], (err, result) => {
|
||||
if (err) {
|
||||
console.error('Error executing query', err.stack);
|
||||
return;
|
||||
}
|
||||
console.log(result.rows[0].name);
|
||||
});
|
||||
|
||||
pool.query('SELECT $1::text as name', ['brianc'])
|
||||
.then((res) => console.log(res.rows[0].name))
|
||||
.catch(err => console.error('Error executing query', err.stack));
|
||||
|
||||
pool.end(() => {
|
||||
console.log('pool has ended');
|
||||
});
|
||||
|
||||
pool.end().then(() => console.log('pool has ended'));
|
||||
|
||||
(async () => {
|
||||
const client = await pool.connect();
|
||||
await client.query('SELECT NOW()');
|
||||
client.release();
|
||||
})();
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
@@ -19,4 +20,4 @@
|
||||
"index.d.ts",
|
||||
"pg-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
}
|
||||
}
|
||||
Vendored
+128
@@ -0,0 +1,128 @@
|
||||
// Type definitions for pg 6.1
|
||||
// Project: https://github.com/brianc/node-postgres
|
||||
// Definitions by: Phips Peter <https://github.com/pspeter3>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import events = require("events");
|
||||
import stream = require("stream");
|
||||
import pgTypes = require("pg-types");
|
||||
|
||||
export declare function connect(connection: string, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
|
||||
export declare function connect(config: ClientConfig, callback: (err: Error, client: Client, done: (err?: any) => void) => void): void;
|
||||
export declare function end(): void;
|
||||
|
||||
export interface ConnectionConfig {
|
||||
user?: string;
|
||||
database?: string;
|
||||
password?: string;
|
||||
port?: number;
|
||||
host?: string;
|
||||
}
|
||||
|
||||
export interface Defaults extends ConnectionConfig {
|
||||
poolSize?: number;
|
||||
poolIdleTimeout?: number;
|
||||
reapIntervalMillis?: number;
|
||||
binary?: boolean;
|
||||
parseInt8?: boolean;
|
||||
}
|
||||
|
||||
import { TlsOptions } from "tls";
|
||||
|
||||
export interface ClientConfig extends ConnectionConfig {
|
||||
ssl?: boolean | TlsOptions;
|
||||
}
|
||||
|
||||
export interface PoolConfig extends ClientConfig {
|
||||
// properties from module 'node-pool'
|
||||
max?: number;
|
||||
min?: number;
|
||||
refreshIdle?: boolean;
|
||||
idleTimeoutMillis?: number;
|
||||
reapIntervalMillis?: number;
|
||||
returnToHead?: boolean;
|
||||
application_name?: string;
|
||||
Promise?: PromiseConstructorLike;
|
||||
}
|
||||
|
||||
export interface QueryConfig {
|
||||
name?: string;
|
||||
text: string;
|
||||
values?: any[];
|
||||
}
|
||||
|
||||
export interface QueryResult {
|
||||
command: string;
|
||||
rowCount: number;
|
||||
oid: number;
|
||||
rows: any[];
|
||||
}
|
||||
|
||||
export interface ResultBuilder extends QueryResult {
|
||||
addRow(row: any): void;
|
||||
}
|
||||
|
||||
export declare class Pool extends events.EventEmitter {
|
||||
// `new Pool('pg://user@localhost/mydb')` is not allowed.
|
||||
// But it passes type check because of issue:
|
||||
// https://github.com/Microsoft/TypeScript/issues/7485
|
||||
constructor(config?: PoolConfig);
|
||||
|
||||
connect(): Promise<Client>;
|
||||
connect(callback: (err: Error, client: Client, done: () => void) => void): void;
|
||||
|
||||
end(callback?: () => void): Promise<void>;
|
||||
|
||||
query(queryStream: QueryConfig & stream.Readable): stream.Readable;
|
||||
query(queryTextOrConfig: string | QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values: any[]): Promise<QueryResult>;
|
||||
|
||||
query(queryTextOrConfig: string | QueryConfig, callback: (err: Error, result: QueryResult) => void): Query;
|
||||
query(queryText: string, values: any[], callback: (err: Error, result: QueryResult) => void): Query;
|
||||
|
||||
on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
on(event: "connect" | "acquire", listener: (client: Client) => void): this;
|
||||
}
|
||||
|
||||
export declare class Client extends events.EventEmitter {
|
||||
constructor(connection: string);
|
||||
constructor(config: ClientConfig);
|
||||
|
||||
connect(callback?: (err: Error) => void): void;
|
||||
end(callback?: (err: Error) => void): void;
|
||||
release(err?: Error): void;
|
||||
|
||||
query(queryStream: QueryConfig & stream.Readable): stream.Readable;
|
||||
query(queryTextOrConfig: string | QueryConfig): Promise<QueryResult>;
|
||||
query(queryText: string, values: any[]): Promise<QueryResult>;
|
||||
|
||||
query(queryTextOrConfig: string | QueryConfig, callback: (err: Error, result: QueryResult) => void): Query;
|
||||
query(queryText: string, values: any[], callback: (err: Error, result: QueryResult) => void): Query;
|
||||
|
||||
copyFrom(queryText: string): stream.Writable;
|
||||
copyTo(queryText: string): stream.Readable;
|
||||
|
||||
pauseDrain(): void;
|
||||
resumeDrain(): void;
|
||||
|
||||
on(event: "drain", listener: () => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "notification" | "notice", listener: (message: any) => void): this;
|
||||
on(event: "end", listener: () => void): this;
|
||||
}
|
||||
|
||||
export declare class Query extends events.EventEmitter {
|
||||
on(event: "row", listener: (row: any, result?: ResultBuilder) => void): this;
|
||||
on(event: "error", listener: (err: Error) => void): this;
|
||||
on(event: "end", listener: (result: ResultBuilder) => void): this;
|
||||
}
|
||||
|
||||
export declare class Events extends events.EventEmitter {
|
||||
on(event: "error", listener: (err: Error, client: Client) => void): this;
|
||||
}
|
||||
|
||||
export const types: typeof pgTypes;
|
||||
|
||||
export const defaults: Defaults & ClientConfig;
|
||||
@@ -0,0 +1,81 @@
|
||||
import * as pg from "pg";
|
||||
|
||||
var conString = "postgres://username:password@localhost/database";
|
||||
|
||||
// https://github.com/brianc/node-pg-types
|
||||
pg.types.setTypeParser(20, val => Number(val));
|
||||
|
||||
// Client pooling
|
||||
pg.defaults.ssl = true;
|
||||
pg.connect(conString, (err, client, done) => {
|
||||
if (err) {
|
||||
return console.error("Error fetching client from pool", err);
|
||||
}
|
||||
client.query("SELECT $1::int AS number", ["1"], (err, result) => {
|
||||
if (err) {
|
||||
done(err);
|
||||
return console.error("Error running query", err);
|
||||
}
|
||||
else {
|
||||
done();
|
||||
}
|
||||
console.log(result.rows[0]["number"]);
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
|
||||
// Simple
|
||||
var client = new pg.Client(conString);
|
||||
client.connect(err => {
|
||||
if (err) {
|
||||
return console.error("Could not connect to postgres", err);
|
||||
}
|
||||
client.query("SELECT NOW() AS 'theTime'", (err, result) => {
|
||||
if (err) {
|
||||
return console.error("Error running query", err);
|
||||
}
|
||||
console.log(result.rowCount);
|
||||
console.log(result.rows[0]["theTime"]);
|
||||
client.end();
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
client.on('end', () => console.log("Client was disconnected."));
|
||||
|
||||
// client pooling
|
||||
|
||||
var config = {
|
||||
user: 'foo', //env var: PGUSER
|
||||
database: 'my_db', //env var: PGDATABASE
|
||||
password: 'secret', //env var: PGPASSWORD
|
||||
port: 5432, //env var: PGPORT
|
||||
max: 10, // max number of clients in the pool
|
||||
idleTimeoutMillis: 30000, // how long a client is allowed to remain idle before being closed
|
||||
Promise,
|
||||
};
|
||||
var pool = new pg.Pool(config);
|
||||
|
||||
pool.connect((err, client, done) => {
|
||||
if(err) {
|
||||
return console.error('error fetching client from pool', err);
|
||||
}
|
||||
client.query('SELECT $1::int AS number', ['1'], (err, result) => {
|
||||
done();
|
||||
|
||||
if(err) {
|
||||
return console.error('error running query', err);
|
||||
}
|
||||
console.log(result.rows[0].number);
|
||||
});
|
||||
});
|
||||
|
||||
pool.on('error', (err, client) => {
|
||||
console.error('idle client error', err.message, err.stack)
|
||||
})
|
||||
|
||||
pool.end();
|
||||
pool.end(() => {
|
||||
console.log("pool is closed");
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"pg": [ "pg/v6" ]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"pg-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -115,6 +115,9 @@ export interface ResolveConfigOptions {
|
||||
* The promise will be rejected if there was an error parsing the configuration file.
|
||||
*/
|
||||
export function resolveConfig(filePath?: string, options?: ResolveConfigOptions): Promise<null | Options>;
|
||||
export namespace resolveConfig {
|
||||
function sync(filePath?: string, options?: ResolveConfigOptions): null | Options;
|
||||
}
|
||||
|
||||
/**
|
||||
* As you repeatedly call `resolveConfig`, the file system structure will be cached for performance. This function will clear the cache.
|
||||
|
||||
@@ -24,4 +24,9 @@ prettier.resolveConfig('path/to/somewhere').then(options => {
|
||||
}
|
||||
});
|
||||
|
||||
const options = prettier.resolveConfig.sync('path/to/somewhere');
|
||||
if (options !== null) {
|
||||
const formatted = prettier.format('hello world', options);
|
||||
}
|
||||
|
||||
prettier.clearConfigCache();
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user