This commit is contained in:
richardgong1987
2017-04-24 09:31:21 +08:00
19 changed files with 435 additions and 4 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import * as Immutable from 'immutable';
type SyntheticKeyboardEvent = React.KeyboardEvent<{}>;
type SyntheticEvent = React.SyntheticEvent<{}>;
export as namespace Draft;
declare namespace Draft {
namespace Component {
namespace Base {
@@ -0,0 +1,26 @@
import settings = require("electron-settings");
settings.has('foo.bar'); // $ExpectType boolean
settings.set('foo.bar', 'test'); // $ExpectType Settings
settings.set('foo.bar', 'test', {prettify: true}); // $ExpectType Settings
settings.set('foo.bar', {test: 'test'}); // $ExpectType Settings
settings.set('foo.bar', {test: 'test'}, {prettify: true}); // $ExpectType Settings
settings.setAll({foo: {bar: 'test'}}); // $ExpectType Settings
settings.setAll({foo: {bar: 'test'}}, {prettify: true}); // $ExpectType Settings
settings.get('foo.bar'); // $ExpectType JsonValue
settings.get('foo.bar', 'test'); // $ExpectType JsonValue
settings.getAll(); // $ExpectType JsonValue
settings.delete('foo.bar'); // $ExpectType Settings
settings.delete('foo.bar', {prettify: true}); // $ExpectType Settings
settings.deleteAll(); // $ExpectType Settings
settings.deleteAll({prettify: true}); // $ExpectType Settings
settings.watch('foo.bar', () => {}); // $ExpectType SettingsObserver
settings.file(); // $ExpectType string
+122
View File
@@ -0,0 +1,122 @@
// Type definitions for electron-settings 3.0
// Project: https://github.com/nathanbuchar/electron-settings#readme
// Definitions by: Ian Copp <https://github.com/icopp>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
import * as fs from "fs";
type SettingsHandler = (newValue: any, oldValue: any) => any;
interface JsonObject {
[x: string]: JsonValue;
}
interface JsonArray extends Array<JsonValue> {} // tslint:disable-line no-empty-interface
type JsonValue = string | number | boolean | null | JsonArray | JsonObject;
interface SettingsOptions {
/**
* Prettify the JSON output. Defaults to `false`.
*/
prettify?: boolean;
}
interface Settings extends NodeJS.EventEmitter {
/**
* Returns a boolean indicating whether the settings object contains the
* given key path.
*/
has(keyPath: string): boolean;
/**
* Sets the value at the given key path and returns the Settings instance.
* Chainable.
* @param keyPath The path to the key whose value we wish to set. This key
* need not already exist.
* @param value The value to set the key at the chosen key path to. This
* must be a data type supported by JSON.
* @see #setAll
*/
set(keyPath: string, value: JsonValue, options?: SettingsOptions): Settings;
/**
* Sets all settings and returns the Settings instance. Chainable.
* @param obj The new settings object.
* @see #set
*/
setAll(obj: JsonValue, options?: SettingsOptions): Settings;
/**
* Returns the value at the given key path, or sets the value at that key
* path to the default value, if provided, if the key does not exist.
* @param defaultValue The value to apply if the setting does not already
* exist.
* @see #getAll
*/
get(keyPath: string, defaultValue?: any): JsonValue;
/**
* Returns all settings.
* @see #get
*/
getAll(): JsonValue;
/**
* Deletes the key and value at the given key path and returns the Settings
* instance. Chainable.
* @see #deleteAll
*/
delete(keyPath: string, options?: SettingsOptions): Settings;
/**
* Deletes all settings and returns the Settings instance. Chainable.
* @see #delete
*/
deleteAll(options?: SettingsOptions): Settings;
/**
* Returns an Observer instance which watches the given key path for changes
* and calls the given handler if the value changes. To unsubscribe from
* changes, call observer.dispose().
* @param keyPath The path to the key that we wish to watch for changes.
* @param handler The callback that will be invoked if the value at the
* chosen key path changes. The context of this callback is
* that of the observer instance.
*/
watch(keyPath: string, handler: SettingsHandler): SettingsObserver;
/**
* Returns the absolute path to where the settings file is or will be
* stored.
*
* In general, the settings file is stored in your app's user data directory
* in a file called Settings. The default user data directory for your
* system can be found below.
*
* * MacOS: If you're running macOS, your app's default user data directory
* is `~/Library/Application\ Support/<Your App>`.
* * Windows: If you're running Windows, your app's default user data
* directory is `%APPDATA%/<Your App>`.
* * Linux: If you're running Linux, your app's default user data directory
* is either `$XDG_CONFIG_HOME/<Your App>` or `~/.config/<Your App>`.
*
* If you wish, you may change your app's default user data directory by
* calling Electron's `app.setPath()` method before the ready event of the
* app module is emitted, but this is not recommended, as it will likely
* cause unintended consequences.
*/
file(): string;
}
interface SettingsObserver {
/**
* Disposes of this Observer instance.
*/
dispose(): void;
}
declare var settings: Settings;
export = settings;
+22
View File
@@ -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",
"electron-settings-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+12
View File
@@ -0,0 +1,12 @@
// Type definitions for karma-chai 0.1
// Project: http://xdissent.github.io/karma-chai
// Definitions by: Jay Sherby <https://github.com/JayAndCatchFire>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import chai = require('chai');
declare global {
var assert: Chai.AssertStatic;
var expect: Chai.ExpectStatic;
var should: Chai.Should;
}
+3
View File
@@ -0,0 +1,3 @@
true.should.be.ok;
expect(true).to.be.ok;
assert.isTrue(true);
+22
View File
@@ -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",
"karma-chai-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
+1 -1
View File
@@ -14,7 +14,7 @@ declare global {
// Map
//////////////////////////////////////////////////////////////////////
const accessToken: string;
let accessToken: string;
/**
* Create and automatically configure a map with layers, markers, and interactivity.
+3
View File
@@ -37,3 +37,6 @@ const marker2 = L.mapbox.featureLayer({
marker2.eachLayer((marker: L.Marker) => {
marker.openPopup();
});
// Can set the API key via left hand assignment
L.mapbox.accessToken = "keyGoesHere";
+2 -2
View File
@@ -1,5 +1,5 @@
// Type definitions for SharePoint: 2010.1 / 2013.1
// Project: https:// github.com/gandjustas/sptypescript
// Type definitions for Microsoft SharePoint: 2013.1
// Project: https://msdn.microsoft.com/en-us/library/office/jj193034.aspx
// Definitions by: Stanislav Vyshchepan <http:// blog.gandjustas.ru>, Andrey Markeev <http:// markeev.com>
// Definitions: https:// github.com/DefinitelyTyped/DefinitelyTyped
+3
View File
@@ -79,6 +79,7 @@ declare namespace Sinon {
alwaysReturned(obj: any): boolean;
invokeCallback(...args: any[]): void;
getCall(n: number): SinonSpyCall;
getCalls(): SinonSpyCall[];
reset(): void;
printf(format: string, ...args: any[]): string;
restore(): void;
@@ -260,6 +261,8 @@ declare namespace Sinon {
setResponseBody(body: string): void;
respond(status: number, headers: any, body: string): void;
autoRespond(ms: number): void;
error(): void;
onerror(): void;
}
interface SinonFakeXMLHttpRequestStatic {
+8
View File
@@ -147,3 +147,11 @@ class TestCreateStubInstance {
}
sinon.createStubInstance(TestCreateStubInstance).someTestMethod('some argument');
function testGetCalls() {
var double = sinon.spy((a: number) => a * 2);
double(2);
double(4);
double.getCall(0).args.length === 1;
double.getCalls().find(call => call.args[0] === 4).returnValue === 8;
}
+79
View File
@@ -0,0 +1,79 @@
// Type definitions for vue-i18n 6.1
// Project: https://github.com/kazupon/vue-i18n
// Definitions by: Kombu <https://github.com/aicest>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as Vue from 'vue';
import { PluginFunction } from 'vue';
declare namespace VueI18n {
type Path = string;
type Locale = string;
type Values = any[] | { [key: string]: any };
type Choice = number;
type LocaleMessage = string | LocaleMessageObject | LocaleMessageArray;
interface LocaleMessageObject { [key: string]: LocaleMessage; }
interface LocaleMessageArray { [index: number]: LocaleMessage; }
interface LocaleMessages { [key: string]: LocaleMessageObject; }
type TranslateResult = string | LocaleMessageArray;
interface Formatter {
format(message: string, values: Values): string;
}
type MissingHandler = (locale: Locale, key: Path, vm?: Vue) => void;
// tslint:disable-next-line:interface-name
interface I18nOptions {
locale?: Locale;
fallbackLocale?: Locale;
messages?: LocaleMessages;
formatter?: Formatter;
missing?: MissingHandler;
fallbackRoot?: boolean;
sync?: boolean;
silentTranslationWarn?: boolean;
}
}
declare class VueI18n {
constructor(options?: VueI18n.I18nOptions)
readonly messages: VueI18n.LocaleMessages;
locale: VueI18n.Locale;
fallbackLocale: VueI18n.Locale;
missing: VueI18n.MissingHandler;
formatter: VueI18n.Formatter;
silentTranslationWarn: boolean;
t(key: VueI18n.Path, values?: VueI18n.Values): VueI18n.TranslateResult;
t(key: VueI18n.Path, locale: VueI18n.Locale, values?: VueI18n.Values): VueI18n.TranslateResult;
tc(key: VueI18n.Path, choice?: VueI18n.Choice, values?: VueI18n.Values): string;
tc(key: VueI18n.Path, choice: VueI18n.Choice, locale: VueI18n.Locale, values?: VueI18n.Values): string;
te(key: VueI18n.Path, locale?: VueI18n.Locale): boolean;
getLocaleMessage(locale: VueI18n.Locale): VueI18n.LocaleMessageObject;
setLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void;
mergeLocaleMessage(locale: VueI18n.Locale, message: VueI18n.LocaleMessageObject): void;
static install: PluginFunction<never>;
static version: string;
}
declare module 'vue/types/vue' {
interface Vue {
readonly $i18n: VueI18n;
$t: typeof VueI18n.prototype.t;
$tc: typeof VueI18n.prototype.tc;
$te: typeof VueI18n.prototype.te;
}
}
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
i18n?: VueI18n;
}
}
export = VueI18n;
+5
View File
@@ -0,0 +1,5 @@
{
"dependencies": {
"vue": "^2.2.6"
}
}
+22
View File
@@ -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",
"vue-i18n-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}
+99
View File
@@ -0,0 +1,99 @@
/// <reference types="../../node" />
const assert = console.assert;
const random = () => Math.trunc(Math.exp(Math.log(Date.now()) * Math.random()));
import * as Vue from 'vue';
import * as VueI18n from 'vue-i18n';
import { ComponentOptions } from 'vue';
/**
* VueI18n.install
*/
Vue.use(VueI18n);
VueI18n.install(Vue);
/**
* VueI18n.version
*/
assert(typeof VueI18n.version === 'string');
/**
* VueI18n Instance
*/
const locale = random().toString();
const key = `_${random()}`;
const value = `${random()}|${random()}|${random()}`;
const i18n = new VueI18n({
locale,
fallbackLocale: locale,
messages: {
[locale]: {
[key]: value,
},
},
formatter: {
format(message, values) {
return message;
},
},
missing(locale, key, vm) {
},
fallbackRoot: false,
sync: true,
silentTranslationWarn: true,
});
assert(i18n.messages[locale][key] === value);
assert(i18n.locale === locale);
assert(i18n.fallbackLocale === locale);
assert(typeof i18n.missing === 'function');
assert(typeof i18n.formatter.format === 'function');
assert(i18n.silentTranslationWarn);
i18n.setLocaleMessage(locale, {});
assert(i18n.getLocaleMessage(locale)[key] === undefined);
i18n.mergeLocaleMessage(locale, { [key]: value });
assert(i18n.getLocaleMessage(locale)[key] === value);
assert(typeof i18n.t === 'function');
assert(typeof i18n.tc === 'function');
assert(typeof i18n.te === 'function');
/**
* Vue
*/
const vm = new Vue({
i18n,
});
assert(vm.$i18n === i18n);
assert(vm.$t(key) === value);
assert(vm.$t(key, ['', 0, false, null, undefined]) === value);
assert(vm.$t(key, { x: 'x' }) === value);
assert(vm.$t(key, locale) === value);
assert(vm.$t(key, locale, ['', 0, false, null, undefined]) === value);
assert(vm.$t(key, locale, { x: 'x' }) === value);
assert(vm.$tc(key) === value);
assert(vm.$tc(key, 1) === value.split('|')[1]);
assert(vm.$tc(key, 1, []) === value.split('|')[1]);
assert(vm.$tc(key, 1, {}) === value.split('|')[1]);
assert(vm.$tc(key, 1, locale) === value.split('|')[1]);
assert(vm.$tc(key, 1, locale, []) === value.split('|')[1]);
assert(vm.$tc(key, 1, locale, {}) === value.split('|')[1]);
assert(vm.$te(key));
assert(vm.$te(key, locale));
/**
* VueI18n
*/
{
let path: VueI18n.Path;
let locale: VueI18n.Locale;
let values: VueI18n.Values;
let choice: VueI18n.Choice;
let localeMessage: VueI18n.LocaleMessage;
let localeMessageObject: VueI18n.LocaleMessageObject;
let localeMessageArray: VueI18n.LocaleMessageArray;
let localeMessages: VueI18n.LocaleMessages;
let translateResult: VueI18n.TranslateResult;
let formatter: VueI18n.Formatter;
let missingHandler: VueI18n.MissingHandler;
let i18nOptions: VueI18n.I18nOptions;
}