diff --git a/types/argparse/argparse-tests.ts b/types/argparse/argparse-tests.ts index ed714ada95..942e2bb4f2 100644 --- a/types/argparse/argparse-tests.ts +++ b/types/argparse/argparse-tests.ts @@ -1,6 +1,12 @@ // near copy of each of the tests from https://github.com/nodeca/argparse/tree/master/examples -import { ArgumentParser, RawDescriptionHelpFormatter } from 'argparse'; +import { + ArgumentParser, + RawDescriptionHelpFormatter, + Action, + ActionConstructorOptions, + Namespace, +} from 'argparse'; let args: any; const simpleExample = new ArgumentParser({ @@ -276,3 +282,26 @@ group.addArgument(['--bar'], { help: 'bar help' }); formatterExample.printHelp(); + +class CustomAction1 extends Action { + constructor(options: ActionConstructorOptions) { + super(options); + } + call(parser: ArgumentParser, namespace: Namespace, values: string | string[], optionString: string | null) { + console.log('custom action 1'); + } +} + +class CustomAction2 extends Action { + call(parser: ArgumentParser, namespace: Namespace, values: string | string[], optionString: string | null) { + console.log('custom action 2'); + } +} + +const customActionExample = new ArgumentParser({ addHelp: false }); +customActionExample.addArgument('--abc', { + action: CustomAction1, +}); +customActionExample.addArgument('--def', { + action: CustomAction2, +}); diff --git a/types/argparse/index.d.ts b/types/argparse/index.d.ts index 3330055b1f..a229b6bc49 100644 --- a/types/argparse/index.d.ts +++ b/types/argparse/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Andrew Schurman // Tomasz Łaziuk // Sebastian Silbermann +// Kannan Goundan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -79,13 +80,24 @@ export interface ArgumentGroupOptions { description?: string; } +export abstract class Action { + protected dest: string; + constructor(options: ActionConstructorOptions); + abstract call(parser: ArgumentParser, namespace: Namespace, values: string | string[], optionString: string | null): void; +} + +// Passed to the Action constructor. Subclasses are just expected to relay this to +// the super() constructor, so using an "opaque type" pattern is probably fine. +// Someone may want to fill this out in the future. +export type ActionConstructorOptions = number & {_: 'ActionConstructorOptions'}; + export class HelpFormatter { } export class ArgumentDefaultsHelpFormatter { } export class RawDescriptionHelpFormatter { } export class RawTextHelpFormatter { } export interface ArgumentOptions { - action?: string; + action?: string | { new(options: ActionConstructorOptions): Action }; optionStrings?: string[]; dest?: string; nargs?: string | number; diff --git a/types/argparse/tsconfig.json b/types/argparse/tsconfig.json index 49e7b03ca8..9248f1d078 100644 --- a/types/argparse/tsconfig.json +++ b/types/argparse/tsconfig.json @@ -21,4 +21,4 @@ "index.d.ts", "argparse-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/bit-twiddle/bit-twiddle-tests.ts b/types/bit-twiddle/bit-twiddle-tests.ts new file mode 100644 index 0000000000..6f2f155c3b --- /dev/null +++ b/types/bit-twiddle/bit-twiddle-tests.ts @@ -0,0 +1,23 @@ +import * as bitTwiddle from "bit-twiddle"; + +bitTwiddle.INT_BITS; +bitTwiddle.INT_MAX; +bitTwiddle.INT_MIN; + +bitTwiddle.sign(5); +bitTwiddle.abs(-5); +bitTwiddle.min(1, 6); +bitTwiddle.max(6, 1); +bitTwiddle.isPow2(3); +bitTwiddle.log2(3); +bitTwiddle.log10(3); +bitTwiddle.popCount(4); +bitTwiddle.countTrailingZeros(3.0000003); +bitTwiddle.nextPow2(31.315); +bitTwiddle.prevPow2(31.315); +bitTwiddle.parity(123); +bitTwiddle.interleave2(12, 24); +bitTwiddle.deinterleave2(24, 12); +bitTwiddle.interleave3(24, 12, 6); +bitTwiddle.deinterleave3(24, 12); +bitTwiddle.nextCombination(41.935); diff --git a/types/bit-twiddle/index.d.ts b/types/bit-twiddle/index.d.ts new file mode 100644 index 0000000000..e89e9500b0 --- /dev/null +++ b/types/bit-twiddle/index.d.ts @@ -0,0 +1,101 @@ +// Type definitions for bit-twiddle 1.0 +// Project: https://github.com/mikolalysenko/bit-twiddle +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.3 + +export const INT_BITS: number; +export const INT_MAX: number; +export const INT_MIN: number; + +/** + * Computes the sign of the integer. + */ +export function sign(value: number): number; + +/** + * Returns the absolute value of the integer. + */ +export function abs(value: number): number; + +/** + * Computes the minimum of integers x and y. + */ +export function min(x: number, y: number): number; + +/** + * Computes the maximum of integers x and y. + */ +export function max(x: number, y: number): number; + +/** + * Returns true if value is a power of 2, otherwise false. + */ +export function isPow2(value: number): boolean; + +/** + * Returns an integer approximation of the log-base 2 of value. + */ +export function log2(value: number): number; + +/** + * Returns an integer approximation of the log-base 10 of value. + */ +export function log10(value: number): number; + +/** + * Counts the number of bits set in value. + */ +export function popCount(value: number): number; + +/** + * Counts the number of trailing zeros. + */ +export function countTrailingZeros(value: number): number; + +/** + * Rounds value up to the next power of 2. + */ +export function nextPow2(value: number): number; + +/** + * Rounds value down to the previous power of 2. + */ +export function prevPow2(value: number): number; + +/** + * Computes the parity of the bits in value. + */ +export function parity(value: number): number; + +/** + * Reverses the bits of value. + */ +export function reverse(value: number): number; + +/** + * Interleaves a pair of 16 bit integers. Useful for fast quadtree style indexing. + * @see http://en.wikipedia.org/wiki/Z-order_curve + */ +export function interleave2(x: number, y: number): number; + +/** + * Deinterleaves the bits of value, returns the nth part. + * If both x and y are 16 bit. + */ +export function deinterleave2(x: number, y: number): number; + +/** + * Interleaves a triple of 10 bit integers. Useful for fast octree indexing. + */ +export function interleave3(x: number, y: number, z: number): number; + +/** + * Same deal as deinterleave2, only for triples instead of pairs. + */ +export function deinterleave3(x: number, y: number): number; + +/** + * Returns next combination ordered colexicographically. + */ +export function nextCombination(x: number): number; diff --git a/types/bit-twiddle/tsconfig.json b/types/bit-twiddle/tsconfig.json new file mode 100644 index 0000000000..f1b094fd42 --- /dev/null +++ b/types/bit-twiddle/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "bit-twiddle-tests.ts" + ] +} diff --git a/types/bit-twiddle/tslint.json b/types/bit-twiddle/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/bit-twiddle/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file diff --git a/types/emojione/index.d.ts b/types/emojione/index.d.ts index 92399fdf9a..21d4726c2f 100644 --- a/types/emojione/index.d.ts +++ b/types/emojione/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for emojione 2.2 -// Project: https://github.com/Ranks/emojione, http://www.emojione.com +// Project: https://github.com/Ranks/emojione, https://www.emojione.com // Definitions by: Danilo Bargen // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/expo/expo-tests.tsx b/types/expo/expo-tests.tsx index 10045e57e6..f2ce8d8197 100644 --- a/types/expo/expo-tests.tsx +++ b/types/expo/expo-tests.tsx @@ -412,6 +412,7 @@ async () => { { resize: { width: 300 } }, { resize: { height: 300 } }, { resize: { height: 300, width: 300 } }, + { crop: { originX: 0, originY: 0, height: 300, width: 300 } } ], { compress: 0.75 }); diff --git a/types/expo/index.d.ts b/types/expo/index.d.ts index 8b488f9b59..7e75c1b7d6 100644 --- a/types/expo/index.d.ts +++ b/types/expo/index.d.ts @@ -1952,14 +1952,16 @@ export namespace ImageManipulator { } interface Flip { - flip?: { vertical?: boolean; horizontal?: boolean }; + flip: { vertical?: boolean; horizontal?: boolean }; } interface Crop { - originX: number; - originY: number; - width: number; - height: number; + crop: { + originX: number; + originY: number; + width: number; + height: number; + }; } interface ImageResult { diff --git a/types/hexo/package.json b/types/hexo/package.json new file mode 100644 index 0000000000..f06689a6b9 --- /dev/null +++ b/types/hexo/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "moment": "^2.19.4" + } +} diff --git a/types/is-blank/index.d.ts b/types/is-blank/index.d.ts new file mode 100644 index 0000000000..eedfa5bd6d --- /dev/null +++ b/types/is-blank/index.d.ts @@ -0,0 +1,7 @@ +// Type definitions for is-blank 2.1 +// Project: https://github.com/johnotander/is-blank#readme +// Definitions by: Christian Gambardella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function isBlank(input: any): boolean; +export = isBlank; diff --git a/types/is-blank/is-blank-tests.ts b/types/is-blank/is-blank-tests.ts new file mode 100644 index 0000000000..367571922a --- /dev/null +++ b/types/is-blank/is-blank-tests.ts @@ -0,0 +1,17 @@ +import isBlank = require('is-blank'); + +isBlank([]); // => true +isBlank({}); // => true +isBlank(0); // => true +isBlank(() => {}); // => true +isBlank(null); // => true +isBlank(undefined); // => true +isBlank(''); // => true +isBlank(' '); // => true +isBlank('\r\t\n '); // => true + +isBlank(['a', 'b']); // => false +isBlank({ a: 'b' }); // => false +isBlank('string'); // => false +isBlank(42); // => false +isBlank((a: number, b: number) => a + b); diff --git a/types/is-blank/tsconfig.json b/types/is-blank/tsconfig.json new file mode 100644 index 0000000000..58f358a499 --- /dev/null +++ b/types/is-blank/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "is-blank-tests.ts" + ] +} diff --git a/types/is-blank/tslint.json b/types/is-blank/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/is-blank/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/mongoose/index.d.ts b/types/mongoose/index.d.ts index 2a01b58a95..fde5e91372 100644 --- a/types/mongoose/index.d.ts +++ b/types/mongoose/index.d.ts @@ -1722,6 +1722,9 @@ declare module "mongoose" { * If later in the query chain a method returns Query, we will need to know type T. * So we save this type as the second type parameter in DocumentQuery. Since people have * been using Query, we set it as an alias of DocumentQuery. + * + * Furthermore, Query is used for function that has an option { rawResult: true }. + * for instance findOneAndUpdate. */ class Query extends DocumentQuery { } class DocumentQuery extends mquery { @@ -1864,7 +1867,7 @@ declare module "mongoose" { equals(val: T): this; /** Executes the query */ - exec(callback?: (err: any, res: T) => void): Promise; + exec(callback?: (err: NativeError, res: T) => void): Promise; exec(operation: string | Function, callback?: (err: any, res: T) => void): Promise; /** Specifies an $exists condition */ @@ -1895,10 +1898,16 @@ declare module "mongoose" { * Issues a mongodb findAndModify remove command. * Finds a matching document, removes it, passing the found document (if any) to the * callback. Executes immediately if callback is passed. + * + * If mongoose option 'useFindAndModify': set to false it uses native findOneAndUpdate() rather than deprecated findAndModify(). + * https://mongoosejs.com/docs/api.html#mongoose_Mongoose-set */ findOneAndRemove(callback?: (error: any, doc: DocType | null, result: any) => void): DocumentQuery & QueryHelpers; findOneAndRemove(conditions: any, callback?: (error: any, doc: DocType | null, result: any) => void): DocumentQuery & QueryHelpers; + findOneAndRemove(conditions: any, options: { rawResult: true } & QueryFindOneAndRemoveOptions, + callback?: (error: any, doc: mongodb.FindAndModifyWriteOpResultObject, result: any) => void) + : Query> & QueryHelpers; findOneAndRemove(conditions: any, options: QueryFindOneAndRemoveOptions, callback?: (error: any, doc: DocType | null, result: any) => void): DocumentQuery & QueryHelpers; @@ -1906,6 +1915,9 @@ declare module "mongoose" { * Issues a mongodb findAndModify update command. * Finds a matching document, updates it according to the update arg, passing any options, and returns * the found document (if any) to the callback. The query executes immediately if callback is passed. + * + * If mongoose option 'useFindAndModify': set to false it uses native findOneAndUpdate() rather than deprecated findAndModify(). + * https://mongoosejs.com/docs/api.html#mongoose_Mongoose-set */ findOneAndUpdate(callback?: (err: any, doc: DocType | null) => void): DocumentQuery & QueryHelpers; findOneAndUpdate(update: any, @@ -1913,8 +1925,15 @@ declare module "mongoose" { findOneAndUpdate(query: any, update: any, callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery & QueryHelpers; findOneAndUpdate(query: any, update: any, - options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions, - callback?: (err: any, doc: DocType, res: any) => void): DocumentQuery & QueryHelpers; + options: { rawResult: true } & { upsert: true } & { new: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject, res: any) => void) + : Query> & QueryHelpers; + findOneAndUpdate(query: any, update: any, + options: { upsert: true } & { new: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: DocType, res: any) => void): DocumentQuery & QueryHelpers; + findOneAndUpdate(query: any, update: any, options: { rawResult: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject, res: any) => void) + : Query> & QueryHelpers; findOneAndUpdate(query: any, update: any, options: QueryFindOneAndUpdateOptions, callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery & QueryHelpers; @@ -2238,12 +2257,21 @@ declare module "mongoose" { class mquery { } interface QueryFindOneAndRemoveOptions { - /** if multiple docs are found by the conditions, sets the sort order to choose which doc to update */ + /** + * if multiple docs are found by the conditions, sets the sort order to choose + * which doc to update + */ sort?: any; /** puts a time limit on the query - requires mongodb >= 2.6.0 */ maxTimeMS?: number; - /** if true, passes the raw result from the MongoDB driver as the third callback parameter */ + /** sets the document fields to return */ + select?: any; + /** like select, it determines which fields to return */ + projection?: any; + /** if true, returns the raw result from the MongoDB driver */ rawResult?: boolean; + /** overwrites the schema's strict mode option for this update */ + strict?: boolean|string; } interface QueryFindOneAndUpdateOptions extends QueryFindOneAndRemoveOptions { @@ -2251,8 +2279,6 @@ declare module "mongoose" { new?: boolean; /** creates the object if it doesn't exist. defaults to false. */ upsert?: boolean; - /** Field selection. Equivalent to .select(fields).findOneAndUpdate() */ - fields?: any | string; /** if true, runs update validators on this command. Update validators validate the update operation against the model's schema. */ runValidators?: boolean; /** @@ -2270,6 +2296,8 @@ declare module "mongoose" { * Turn on this option to aggregate all the cast errors. */ multipleCastError?: boolean; + /** Field selection. Equivalent to .select(fields).findOneAndUpdate() */ + fields?: any | string; } interface QueryUpdateOptions extends ModelUpdateOptions { @@ -2998,17 +3026,21 @@ declare module "mongoose" { * findByIdAndRemove(id, ...) is equivalent to findOneAndRemove({ _id: id }, ...). * Finds a matching document, removes it, passing the found document (if any) to the callback. * Executes immediately if callback is passed, else a Query object is returned. + * + * If mongoose option 'useFindAndModify': set to false it uses native findOneAndUpdate() rather than deprecated findAndModify(). + * https://mongoosejs.com/docs/api.html#mongoose_Mongoose-set + * + * Note: same signatures as findByIdAndDelete + * * @param id value of _id to query by */ findByIdAndRemove(): DocumentQuery & QueryHelpers; findByIdAndRemove(id: any | number | string, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; - findByIdAndRemove(id: any | number | string, options: { - /** if multiple docs are found by the conditions, sets the sort order to choose which doc to update */ - sort?: any; - /** sets the document fields to return */ - select?: any; - }, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; + findByIdAndRemove(id: any | number | string, options: QueryFindOneAndRemoveOptions, + callback?: (err: any, res: mongodb.FindAndModifyWriteOpResultObject) => void) + : Query> & QueryHelpers; + findByIdAndRemove(id: any | number | string, options: QueryFindOneAndRemoveOptions, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; /** @@ -3016,31 +3048,44 @@ declare module "mongoose" { * findByIdAndDelete(id, ...) is equivalent to findByIdAndDelete({ _id: id }, ...). * Finds a matching document, removes it, passing the found document (if any) to the callback. * Executes immediately if callback is passed, else a Query object is returned. + * + * Note: same signatures as findByIdAndRemove + * * @param id value of _id to query by */ - findByIdAndDelete(): DocumentQuery; + findByIdAndDelete(): DocumentQuery & QueryHelpers; findByIdAndDelete(id: any | number | string, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; - findByIdAndDelete(id: any | number | string, options: { - /** if multiple docs are found by the conditions, sets the sort order to choose which doc to update */ - sort?: any; - /** sets the document fields to return */ - select?: any; - }, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; + findByIdAndDelete(id: any | number | string, options: QueryFindOneAndRemoveOptions, + callback?: (err: any, res: mongodb.FindAndModifyWriteOpResultObject) => void) + : Query> & QueryHelpers; + findByIdAndDelete(id: any | number | string, options: QueryFindOneAndRemoveOptions, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; /** * Issues a mongodb findAndModify update command by a document's _id field. findByIdAndUpdate(id, ...) * is equivalent to findOneAndUpdate({ _id: id }, ...). + * + * If mongoose option 'useFindAndModify': set to false it uses native findOneAndUpdate() rather than deprecated findAndModify(). + * https://mongoosejs.com/docs/api.html#mongoose_Mongoose-set + * * @param id value of _id to query by */ findByIdAndUpdate(): DocumentQuery & QueryHelpers; findByIdAndUpdate(id: any | number | string, update: any, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; findByIdAndUpdate(id: any | number | string, update: any, - options: { upsert: true, new: true } & ModelFindByIdAndUpdateOptions, + options: { rawResult: true } & { upsert: true } & { new: true } & QueryFindOneAndUpdateOptions, callback?: (err: any, res: T) => void): DocumentQuery & QueryHelpers; findByIdAndUpdate(id: any | number | string, update: any, - options: ModelFindByIdAndUpdateOptions, + options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, res: mongodb.FindAndModifyWriteOpResultObject) => void) + : Query> & QueryHelpers; + findByIdAndUpdate(id: any | number | string, update: any, + options: { rawResult : true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, res: mongodb.FindAndModifyWriteOpResultObject) => void) + : Query> & QueryHelpers; + findByIdAndUpdate(id: any | number | string, update: any, + options: QueryFindOneAndUpdateOptions, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; /** @@ -3059,62 +3104,62 @@ declare module "mongoose" { * Issue a mongodb findAndModify remove command. * Finds a matching document, removes it, passing the found document (if any) to the callback. * Executes immediately if callback is passed else a Query object is returned. + * + * If mongoose option 'useFindAndModify': set to false it uses native findOneAndUpdate() rather than deprecated findAndModify(). + * https://mongoosejs.com/docs/api.html#mongoose_Mongoose-set + * + * Note: same signatures as findOneAndDelete + * */ findOneAndRemove(): DocumentQuery & QueryHelpers; findOneAndRemove(conditions: any, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; - findOneAndRemove(conditions: any, options: { - /** - * if multiple docs are found by the conditions, sets the sort order to choose - * which doc to update - */ - sort?: any; - /** puts a time limit on the query - requires mongodb >= 2.6.0 */ - maxTimeMS?: number; - /** sets the document fields to return */ - select?: any; - }, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; + findOneAndRemove(conditions: any, options: { rawResult: true } & QueryFindOneAndRemoveOptions, + callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject, res: any) => void) + : Query> & QueryHelpers; + findOneAndRemove(conditions: any, options: QueryFindOneAndRemoveOptions, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; /** * Issues a mongodb findOneAndDelete command. * Finds a matching document, removes it, passing the found document (if any) to the * callback. Executes immediately if callback is passed. + * + * Note: same signatures as findOneAndRemove + * */ findOneAndDelete(): DocumentQuery & QueryHelpers; findOneAndDelete(conditions: any, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; - findOneAndDelete(conditions: any, options: { - /** - * if multiple docs are found by the conditions, sets the sort order to choose - * which doc to update - */ - sort?: any; - /** puts a time limit on the query - requires mongodb >= 2.6.0 */ - maxTimeMS?: number; - /** sets the document fields to return */ - select?: any; - /** like select, it determines which fields to return */ - projection?: any; - /** if true, returns the raw result from the MongoDB driver */ - rawResult?: boolean; - /** overwrites the schema's strict mode option for this update */ - strict?: boolean|string; - }, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; + findOneAndDelete(conditions: any, options: { rawResult: true } & QueryFindOneAndRemoveOptions, + callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject, res: any) => void) + : Query> & QueryHelpers; + findOneAndDelete(conditions: any, options: QueryFindOneAndRemoveOptions, callback?: (err: any, res: T | null) => void): DocumentQuery & QueryHelpers; /** * Issues a mongodb findAndModify update command. * Finds a matching document, updates it according to the update arg, passing any options, * and returns the found document (if any) to the callback. The query executes immediately * if callback is passed else a Query object is returned. + * ++ * If mongoose option 'useFindAndModify': set to false it uses native findOneAndUpdate() rather than the deprecated findAndModify(). ++ * https://mongoosejs.com/docs/api.html#mongoose_Mongoose-set */ findOneAndUpdate(): DocumentQuery & QueryHelpers; findOneAndUpdate(conditions: any, update: any, callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery & QueryHelpers; findOneAndUpdate(conditions: any, update: any, - options: { upsert: true, new: true } & ModelFindOneAndUpdateOptions, + options: { rawResult : true } & { upsert: true, new: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject, res: any) => void) + : Query> & QueryHelpers; + findOneAndUpdate(conditions: any, update: any, + options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions, callback?: (err: any, doc: T, res: any) => void): DocumentQuery & QueryHelpers; findOneAndUpdate(conditions: any, update: any, - options: ModelFindOneAndUpdateOptions, + options: { rawResult: true } & QueryFindOneAndUpdateOptions, + callback?: (err: any, doc: mongodb.FindAndModifyWriteOpResultObject, res: any) => void) + : Query> & QueryHelpers; + findOneAndUpdate(conditions: any, update: any, + options: QueryFindOneAndUpdateOptions, callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery & QueryHelpers; /** @@ -3308,43 +3353,6 @@ declare module "mongoose" { session?: ClientSession | null; } - interface ModelFindByIdAndUpdateOptions extends ModelOptions { - /** true to return the modified document rather than the original. defaults to false */ - new?: boolean; - /** creates the object if it doesn't exist. defaults to false. */ - upsert?: boolean; - /** - * if true, runs update validators on this command. Update validators validate the - * update operation against the model's schema. - */ - runValidators?: boolean; - /** - * if this and upsert are true, mongoose will apply the defaults specified in the model's - * schema if a new document is created. This option only works on MongoDB >= 2.4 because - * it relies on MongoDB's $setOnInsert operator. - */ - setDefaultsOnInsert?: boolean; - /** if multiple docs are found by the conditions, sets the sort order to choose which doc to update */ - sort?: any; - /** sets the document fields to return */ - select?: any; - /** if true, passes the raw result from the MongoDB driver as the third callback parameter */ - rawResult?: boolean; - /** overwrites the schema's strict mode option for this update */ - strict?: boolean; - /** The context option lets you set the value of this in update validators to the underlying query. */ - context?: string; - } - - interface ModelFindOneAndUpdateOptions extends ModelFindByIdAndUpdateOptions { - /** Field selection. Equivalent to .select(fields).findOneAndUpdate() */ - fields?: any | string; - /** puts a time limit on the query - requires mongodb >= 2.6.0 */ - maxTimeMS?: number; - /** if true, passes the raw result from the MongoDB driver as the third callback parameter */ - rawResult?: boolean; - } - interface ModelPopulateOptions { /** space delimited path(s) to populate */ path: string; diff --git a/types/mongoose/mongoose-tests.ts b/types/mongoose/mongoose-tests.ts index 6d487dd14d..6eda6d5eb0 100644 --- a/types/mongoose/mongoose-tests.ts +++ b/types/mongoose/mongoose-tests.ts @@ -1021,7 +1021,7 @@ query.findOne(function (err, res) { query.findOneAndRemove({name: 'aa'}, { rawResult: true }, function (err, doc) { - doc.execPopulate(); + doc.lastErrorObject }).findOneAndRemove(); query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { @@ -1911,6 +1911,14 @@ LocModel.findOneAndUpdate().exec().then(function (arg) { arg.openingTimes; } }); +LocModel.findOneAndUpdate( + // find a document with that filter + {name: "aa"}, + // document to insert when nothing was found + { $set: {name: "bb"} }, + // options + {upsert: true, new: true, runValidators: true, + rawResult: true, multipleCastError: true }); LocModel.geoSearch({}, { near: [1, 2], maxDistance: 22 diff --git a/types/mumath/index.d.ts b/types/mumath/index.d.ts new file mode 100644 index 0000000000..8967bafa4f --- /dev/null +++ b/types/mumath/index.d.ts @@ -0,0 +1,63 @@ +// Type definitions for mumath 3.3 +// Project: https://github.com/dfcreative/mumath +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.3 + +/** + * Detects proper clamp min/max. + */ +export function clamp(value: number, left: number, right: number): number; + +/** + * Get closest value out of a set. + */ +export function closest(value: number, list: number[]): number; + +/** + * Check if one number is multiple of other + * Same as a % b === 0, but with precision check. + */ +export function isMultiple(a: number, b: number, eps?: number): boolean; + +/** + * Return quadratic length of a vector. + */ +export function len(a: number, b: number): number; + +/** + * Return value interpolated between x and y. + */ +export function lerp(x: number, y: number, ratio: number): number; + +/** + * An enhanced mod-loop, like fmod — loops value within a frame. + */ +export function mod(value: number, max: number, min?: number): number; + +/** + * Get order of magnitude for a number. + */ +export function order(value: number): number; + +/** + * Get precision from float: + */ +export function precision(value: number): number; + +/** + * Rounds value to optional step. + */ +export function round(value: number, step?: number): number; + +/** + * Get first scale out of a list of basic scales, aligned to the power. E. g. + * step(.37, [1, 2, 5]) → .5 step(456, [1, 2]) → 1000 + * Similar to closest, but takes all possible powers of scales. + */ +export function scale(value: number, list: number[]): number; + +/** + * Whether element is between left & right, including. + */ +export function within(value: number, left: number, right: number): number; diff --git a/types/mumath/mumath-tests.ts b/types/mumath/mumath-tests.ts new file mode 100644 index 0000000000..c0fed04336 --- /dev/null +++ b/types/mumath/mumath-tests.ts @@ -0,0 +1,25 @@ +import * as mumath from "mumath"; + +mumath.clamp(1, 2, 3); + +mumath.closest(5, [1, 7, 3, 6, 10]); + +mumath.isMultiple(5, 10, 1.000074); +mumath.isMultiple(5, 10); + +mumath.len(15, 1.0); + +mumath.lerp(1, 2, 3); + +mumath.mod(1, 2, 3); +mumath.mod(1, 2); + +mumath.order(5); + +mumath.precision(5.0000001); + +mumath.round(0.3, 0.5); + +mumath.scale(5.93, [1.0, 35, 10, 7.135]); + +mumath.within(5, 1, 10); diff --git a/types/mumath/tsconfig.json b/types/mumath/tsconfig.json new file mode 100644 index 0000000000..67aa9c2b29 --- /dev/null +++ b/types/mumath/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mumath-tests.ts" + ] +} diff --git a/types/mumath/tslint.json b/types/mumath/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/mumath/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file diff --git a/types/rc-time-picker/package.json b/types/rc-time-picker/package.json new file mode 100644 index 0000000000..f06689a6b9 --- /dev/null +++ b/types/rc-time-picker/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "moment": "^2.19.4" + } +} diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index 0cee14dfd2..a96ffd41eb 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -9297,7 +9297,9 @@ export const PointPropType: React.Validator; export const ViewPropTypes: React.ValidationMap; declare global { - function require(name: string): any; + type ReactNativeRequireFunction = (name: string) => any; + + var require: ReactNativeRequireFunction; /** * Console polyfill @@ -9315,7 +9317,7 @@ declare global { ignoredYellowBox: string[]; } - const console: Console; + var console: Console; /** * Navigator object for accessing location API diff --git a/types/recharts/index.d.ts b/types/recharts/index.d.ts index 963f68600c..44f97c933b 100644 --- a/types/recharts/index.d.ts +++ b/types/recharts/index.d.ts @@ -30,7 +30,7 @@ export type TooltipFormatter = (value: string | number | Array, entry: TooltipPayload, index: number) => React.ReactNode; export type ItemSorter = (a: T, b: T) => number; export type ContentRenderer

= (props: P) => React.ReactNode; -export type DataKey = string | number | ((dataObject: any) => number | [number, number] | null); +export type DataKey = string | number | ((dataObject: any) => string | number | [number, number] | null); export type IconType = 'plainline' | 'line' | 'square' | 'rect' | 'circle' | 'cross' | 'diamond' | 'star' | 'triangle' | 'wye' | 'plainline'; export type LegendType = IconType | 'none'; @@ -201,6 +201,7 @@ export interface BarProps extends EventAttributes, Partial { - + diff --git a/types/rmc-drawer/package.json b/types/rmc-drawer/package.json new file mode 100644 index 0000000000..f06689a6b9 --- /dev/null +++ b/types/rmc-drawer/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "moment": "^2.19.4" + } +} diff --git a/types/shipit-utils/index.d.ts b/types/shipit-utils/index.d.ts index 64a62f2d61..6a8582bfad 100644 --- a/types/shipit-utils/index.d.ts +++ b/types/shipit-utils/index.d.ts @@ -3,7 +3,7 @@ // Definitions by: Cyril Schumacher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -import shipit = require("shipit"); +import shipit = require("shipit-cli"); export type GruntOrShipit = typeof shipit | {}; export type EmptyCallback = () => void; diff --git a/types/shipit-utils/shipit-utils-tests.ts b/types/shipit-utils/shipit-utils-tests.ts index 36da5f0073..96bbe2bbdb 100644 --- a/types/shipit-utils/shipit-utils-tests.ts +++ b/types/shipit-utils/shipit-utils-tests.ts @@ -1,4 +1,4 @@ -import shipit = require("shipit"); +import shipit = require("shipit-cli"); import utils = require("shipit-utils"); const originalShipit = utils.getShipit(shipit); diff --git a/types/storybook__addon-info/index.d.ts b/types/storybook__addon-info/index.d.ts index 9e5089d443..6adc628c31 100644 --- a/types/storybook__addon-info/index.d.ts +++ b/types/storybook__addon-info/index.d.ts @@ -1,7 +1,8 @@ -// Type definitions for @storybook/addon-info 3.4 +// Type definitions for @storybook/addon-info 4.1 // Project: https://github.com/storybooks/storybook, https://github.com/storybooks/storybook/tree/master/addons/info // Definitions by: Mark Kornblum // Mattias Wikstrom +// Kevin Lee // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -22,11 +23,22 @@ export interface Options { propTables?: React.ComponentType[] | false; propTablesExclude?: React.ComponentType[]; styles?: object; + components?: { [key: string]: React.ComponentType }; marksyConf?: object; maxPropsIntoLine?: number; maxPropObjectKeys?: number; maxPropArrayLength?: number; maxPropStringLength?: number; + TableComponent?: React.ComponentType<{ + propDefinitions: Array<{ + property: string; + propType: object | string; // TODO: info about what this object is... + required: boolean; + description: string; + defaultValue: any; + }> + }>; + excludedPropTypes?: string[]; } // TODO: it would be better to use type inference for the parameters diff --git a/types/storybook__addon-info/storybook__addon-info-tests.tsx b/types/storybook__addon-info/storybook__addon-info-tests.tsx index 505780bf7e..0e581c822d 100644 --- a/types/storybook__addon-info/storybook__addon-info-tests.tsx +++ b/types/storybook__addon-info/storybook__addon-info-tests.tsx @@ -6,6 +6,38 @@ import { setDefaults, withInfo } from '@storybook/addon-info'; const { Component } = React; +const TableComponent = ({ propDefinitions }: { propDefinitions: Array<{ + property: string; + propType: { [key: string]: any} | string; + required: boolean; + description: string; + defaultValue: any; +}> }) => ( + + + + + + + + + + + + {propDefinitions.map(row => ( + + + + + + + ))} + +
propertypropTyperequireddefaultdescription
{row.property}{row.required ? 'yes' : '-'} + {row.defaultValue === undefined ? '-' : row.defaultValue} + {row.description}
+); + addDecorator(withInfo); setDefaults({ @@ -31,11 +63,14 @@ storiesOf('Component', module) header: true, source: true, styles: {}, + components: {}, marksyConf: {}, maxPropObjectKeys: 1, maxPropArrayLength: 2, maxPropsIntoLine: 3, maxPropStringLength: 4, + TableComponent, + excludedPropTypes: [], })(() => Click the "?" mark at top-right to view the info. ) diff --git a/types/tokenizr/index.d.ts b/types/tokenizr/index.d.ts new file mode 100644 index 0000000000..1b1615e1b8 --- /dev/null +++ b/types/tokenizr/index.d.ts @@ -0,0 +1,268 @@ +// Type definitions for tokenizr 1.5 +// Project: https://github.com/rse/tokenizr +// Definitions by: Nicholas Sorokin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class Tokenizr { + constructor(); + + /** + * Configure a tokenization after-rule callback + */ + after(action: Action): this; + + /** + * Execute multiple alternative callbacks + */ + alternatives(...alternatives: Array<(this: this) => any>): any; + + /** + * Configure a tokenization before-rule callback + */ + before(action: Action): this; + + /** + * Open tokenization transaction + */ + begin(): this; + + /** + * Close (successfully) tokenization transaction + */ + commit(): this; + + /** + * Consume the current token (by expecting it to be a particular symbol) + */ + consume(type: string, value: any): Token; + + /** + * Configure debug operation + */ + debug(enableDebug: boolean): this; + + /** + * Determine depth of still open tokenization transaction + */ + depth(): number; + + /** + * Create an error message for the current position + */ + error(message?: string): ParsingError; + + /** + * Configure a tokenization finish callback + */ + finish(action: (this: ActionContext, ctx: ActionContext) => void): this; + + /** + * Provide (new) input string to tokenize + */ + input(input: string): this; + + /** + * Peek at the next token or token at particular offset + */ + peek(offset?: number): Token; + + /** + * Pop state + */ + pop(): string; + + /** + * Push state + */ + push(state: string): this; + + /** + * Reset the internal state + */ + reset(): this; + + /** + * Close (unsuccessfully) tokenization transaction + */ + rollback(): this; + + /** + * Configure a tokenization rule + */ + rule(pattern: RegExp, action: RuleAction, name?: string): this; + rule( + state: string, + pattern: RegExp, + action: RuleAction, + name: string + ): this; + + /** + * Skip one or more tokens + */ + skip(len?: number): this; + + /** + * Get/set state + */ + state(): string; + /** + * Replaces the current state + */ + state(state: string): this; + + /** + * Set a tag + */ + tag(tag: string): this; + + /** + * Check whether tag is set + */ + tagged(tag: string): boolean; + + /** + * Determine and return next token + */ + token(): Token | null; + + /** + * Determine and return all tokens + */ + tokens(): Token[]; + + /** + * Unset a tag + */ + untag(tag: string): this; + + static readonly ParsingError: typeof ParsingError; + static readonly ActionContext: typeof ActionContext; + static readonly Token: typeof Token; +} + +type Action = ( + this: ActionContext, + ctx: ActionContext, + found: RegExpExecArray, + rule: { + state: string; + pattern: RegExp; + action: RuleAction; + name: string; + } +) => void; + +type RuleAction = ( + this: ActionContext, + ctx: ActionContext, + found: RegExpExecArray +) => void; + +declare class ActionContext { + constructor(e: any); + + /** + * Accept current matching as a new token + */ + accept(type: string, value?: any): this; + + /** + * Store and retrieve user data attached to context + */ + data(key: string, value?: any): any; + + /** + * Mark current matching to be ignored + */ + ignore(): this; + + /** + * Retrieve information of current matching + */ + info(): { line: number; column: number; pos: number; len: number }; + + /** + * Pop state + */ + pop(): string; + + /** + * Push state + */ + push(state: string): this; + + /** + * Rark current matching to be rejected + */ + reject(): this; + + /** + * Mark current matching to be repeated from scratch + */ + repeat(): this; + + /** + * Get/set state + */ + state(): string; + /** + * Replaces the current state + */ + state(state: string): this; + + /** + * Immediately stop tokenization + */ + stop(): this; + + /** + * Set a tag + */ + tag(tag: string): this; + + /** + * Check whether tag is set + */ + tagged(tag: string): boolean; + + /** + * Unset a tag + */ + untag(tag: string): this; +} + +declare class ParsingError extends Error { + constructor( + message: string, + pos: number, + line: number, + column: number, + input: string + ); + + /** + * Render a useful string representation + */ + toString(): string; +} + +declare class Token { + constructor( + type: string, + value: any, + text: string, + pos?: number, + line?: number, + column?: number + ); + + isA(type: string, value?: any): boolean; + + /** + * Render a useful string representation + */ + toString(): string; +} + +export = Tokenizr; diff --git a/types/tokenizr/tokenizr-tests.ts b/types/tokenizr/tokenizr-tests.ts new file mode 100644 index 0000000000..a633a14a75 --- /dev/null +++ b/types/tokenizr/tokenizr-tests.ts @@ -0,0 +1,42 @@ +import Tokenizr = require('tokenizr'); + +const lexer = new Tokenizr(); + +lexer.rule(/[a-zA-Z_][a-zA-Z0-9_]*/, (ctx, match) => { + ctx.accept('id'); +}); + +lexer.rule(/[+-]?[0-9]+/, (ctx, match) => { + ctx.accept('number', parseInt(match[0], 10)); +}); + +lexer.rule(/"((?:\\"|[^\r\n])*)"/, (ctx, match) => { + ctx.accept('string', match[1].replace(/\\"/g, '"')); +}); + +lexer.rule(/\/\/[^\r\n]*\r?\n/, (ctx, match) => { + ctx.ignore(); +}); + +lexer.rule(/[ \t\r\n]+/, (ctx, match) => { + ctx.ignore(); +}); + +lexer.rule(/./, (ctx, match) => { + ctx.accept('char'); +}); + +const cfg = `foo { + baz = 1 // sample comment + bar { + quux = 42 + hello = "hello \"world\"!" + } + quux = 7 +}`; + +lexer.input(cfg); +lexer.debug(true); +lexer.tokens().forEach(token => { + // ... +}); diff --git a/types/tokenizr/tsconfig.json b/types/tokenizr/tsconfig.json new file mode 100644 index 0000000000..7b24906172 --- /dev/null +++ b/types/tokenizr/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "tokenizr-tests.ts"] +} diff --git a/types/tokenizr/tslint.json b/types/tokenizr/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tokenizr/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/word-extractor/index.d.ts b/types/word-extractor/index.d.ts new file mode 100644 index 0000000000..c6e6289774 --- /dev/null +++ b/types/word-extractor/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for word-extractor 0.3 +// Project: https://github.com/morungos/node-word-extractor +// Definitions by: Rodrigo Saboya +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class WordExtractor { + extract(documentPath: string): Promise; +} + +export = WordExtractor; + +declare namespace WordExtractor { + class Document { + getBody(): string; + getFootnotes(): string; + getHeaders(): string; + getAnnotations(): string; + getEndNotes(): string; + } +} diff --git a/types/word-extractor/tsconfig.json b/types/word-extractor/tsconfig.json new file mode 100644 index 0000000000..436687e1ff --- /dev/null +++ b/types/word-extractor/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "word-extractor-tests.ts" + ] +} diff --git a/types/word-extractor/tslint.json b/types/word-extractor/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/word-extractor/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/word-extractor/word-extractor-tests.ts b/types/word-extractor/word-extractor-tests.ts new file mode 100644 index 0000000000..a177b9d5c5 --- /dev/null +++ b/types/word-extractor/word-extractor-tests.ts @@ -0,0 +1,13 @@ +import WordExtractor = require("word-extractor"); + +const extractor = new WordExtractor(); + +let temp: string; + +const doc = extractor.extract('/path/to/file.doc').then(document => { + temp = document.getBody(); + temp = document.getAnnotations(); + temp = document.getEndNotes(); + temp = document.getFootnotes(); + temp = document.getHeaders(); +});