From 53ecd41e90b7ac667b2b59ce6c6ec2ee5d9355b5 Mon Sep 17 00:00:00 2001 From: Andy Date: Tue, 18 Apr 2017 13:57:54 -0700 Subject: [PATCH] Remove unnecessary namespaces in tests (#15922) --- .../pouchdb-adapter-fruitdown-tests.ts | 24 +- .../pouchdb-adapter-leveldb-tests.ts | 19 +- .../pouchdb-adapter-localstorage-tests.ts | 18 +- .../pouchdb-adapter-memory-tests.ts | 18 +- .../pouchdb-adapter-node-websql-tests.ts | 46 +- .../pouchdb-adapter-websql-tests.ts | 48 +- .../pouchdb-browser/pouchdb-browser-tests.ts | 26 +- types/pouchdb-core/pouchdb-core-tests.ts | 419 ++-- types/pouchdb-find/pouchdb-find-tests.ts | 115 +- types/pouchdb-http/pouchdb-http-tests.ts | 16 +- .../pouchdb-mapreduce-tests.ts | 66 +- types/pouchdb-node/pouchdb-node-tests.ts | 26 +- .../pouchdb-replication-tests.ts | 19 +- types/pouchdb-upsert/pouchdb-upsert-tests.ts | 82 +- types/pouchdb/pouchdb-tests.ts | 204 +- types/pug/pug-tests.ts | 4 +- types/query-string/query-string-tests.ts | 9 +- .../react-virtualized-tests.tsx | 1749 ----------------- types/response-time/response-time-tests.ts | 6 +- types/sigmajs/sigmajs-tests.ts | 150 +- .../string-template/string-template-tests.ts | 8 +- types/synaptic/synaptic-tests.ts | 341 ++-- types/validator/validator-tests.ts | 2 +- 23 files changed, 822 insertions(+), 2593 deletions(-) diff --git a/types/pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown-tests.ts b/types/pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown-tests.ts index 810cdc32c1..645ec0b448 100644 --- a/types/pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown-tests.ts +++ b/types/pouchdb-adapter-fruitdown/pouchdb-adapter-fruitdown-tests.ts @@ -1,15 +1,13 @@ -namespace PouchDBAdapterFruitdownTests { - function testConstructor() { - type MyModel = { numericProperty: number }; - let model: PouchDB.Core.Document; +function testConstructor() { + type MyModel = { numericProperty: number }; + let model: PouchDB.Core.Document; - let db = new PouchDB(null, { - adapter: 'fruitdown', - }); - db.get('model').then((result) => model); - db = new PouchDB('myDb', { - adapter: 'fruitdown', - }); - db.get('model').then((result) => model); - } + let db = new PouchDB(null, { + adapter: 'fruitdown', + }); + db.get('model').then((result) => model); + db = new PouchDB('myDb', { + adapter: 'fruitdown', + }); + db.get('model').then((result) => model); } diff --git a/types/pouchdb-adapter-leveldb/pouchdb-adapter-leveldb-tests.ts b/types/pouchdb-adapter-leveldb/pouchdb-adapter-leveldb-tests.ts index 72eb790e48..49c4a84088 100644 --- a/types/pouchdb-adapter-leveldb/pouchdb-adapter-leveldb-tests.ts +++ b/types/pouchdb-adapter-leveldb/pouchdb-adapter-leveldb-tests.ts @@ -1,12 +1,11 @@ -namespace PouchDBAdapterLevelDBTests { - function testConstructor() { - type MyModel = { numericProperty: number }; +function testConstructor() { + type MyModel = { numericProperty: number }; - let db = new PouchDB(null, { - adapter: 'leveldb', - }); - db = new PouchDB('myDb', { - adapter: 'leveldb', - }); - } + let db = new PouchDB(null, { + adapter: 'leveldb', + }); + db = new PouchDB('myDb', { + adapter: 'leveldb', + }); } + diff --git a/types/pouchdb-adapter-localstorage/pouchdb-adapter-localstorage-tests.ts b/types/pouchdb-adapter-localstorage/pouchdb-adapter-localstorage-tests.ts index 8588420f78..71a60e987f 100644 --- a/types/pouchdb-adapter-localstorage/pouchdb-adapter-localstorage-tests.ts +++ b/types/pouchdb-adapter-localstorage/pouchdb-adapter-localstorage-tests.ts @@ -1,12 +1,10 @@ -namespace PouchDBAdapterLocalStorageyTests { - function testConstructor() { - type MyModel = { numericProperty: number }; +function testConstructor() { + type MyModel = { numericProperty: number }; - let db = new PouchDB(null, { - adapter: 'localstorage', - }); - db = new PouchDB('myDb', { - adapter: 'localstorage', - }); - } + let db = new PouchDB(null, { + adapter: 'localstorage', + }); + db = new PouchDB('myDb', { + adapter: 'localstorage', + }); } diff --git a/types/pouchdb-adapter-memory/pouchdb-adapter-memory-tests.ts b/types/pouchdb-adapter-memory/pouchdb-adapter-memory-tests.ts index 9f59922fbc..a920375bb8 100644 --- a/types/pouchdb-adapter-memory/pouchdb-adapter-memory-tests.ts +++ b/types/pouchdb-adapter-memory/pouchdb-adapter-memory-tests.ts @@ -1,12 +1,10 @@ -namespace PouchDBAdapterMemoryTests { - function testConstructor() { - type MyModel = { numericProperty: number }; +function testConstructor() { + type MyModel = { numericProperty: number }; - let db = new PouchDB(null, { - adapter: 'memory', - }); - db = new PouchDB('myDb', { - adapter: 'memory', - }); - } + let db = new PouchDB(null, { + adapter: 'memory', + }); + db = new PouchDB('myDb', { + adapter: 'memory', + }); } diff --git a/types/pouchdb-adapter-node-websql/pouchdb-adapter-node-websql-tests.ts b/types/pouchdb-adapter-node-websql/pouchdb-adapter-node-websql-tests.ts index 17ae2f4ec9..b65fabca1b 100644 --- a/types/pouchdb-adapter-node-websql/pouchdb-adapter-node-websql-tests.ts +++ b/types/pouchdb-adapter-node-websql/pouchdb-adapter-node-websql-tests.ts @@ -1,25 +1,23 @@ -namespace PouchDBAdapterNodeWebSQLTests { - function isBoolean(someBoolean: boolean) { - } - function isNumber(someNumber: number) { - } - function isString(someString: string) { - } - - function testConstructor() { - type MyModel = { numericProperty: number }; - - let db = new PouchDB(null, { - adapter: 'websql', - size: 5, - }); - db = new PouchDB('myDb', { - adapter: 'websql', - }); - - db.info().then((info) => { - isBoolean(info.sqlite_plugin); - isString(info.websql_encoding); - }); - } +function isBoolean(someBoolean: boolean) { +} +function isNumber(someNumber: number) { +} +function isString(someString: string) { +} + +function testConstructor() { + type MyModel = { numericProperty: number }; + + let db = new PouchDB(null, { + adapter: 'websql', + size: 5, + }); + db = new PouchDB('myDb', { + adapter: 'websql', + }); + + db.info().then((info) => { + isBoolean(info.sqlite_plugin); + isString(info.websql_encoding); + }); } diff --git a/types/pouchdb-adapter-websql/pouchdb-adapter-websql-tests.ts b/types/pouchdb-adapter-websql/pouchdb-adapter-websql-tests.ts index 51916a3472..4fcd195669 100644 --- a/types/pouchdb-adapter-websql/pouchdb-adapter-websql-tests.ts +++ b/types/pouchdb-adapter-websql/pouchdb-adapter-websql-tests.ts @@ -1,26 +1,24 @@ -namespace PouchDBAdapterWebSQLTests { - function isBoolean(someBoolean: boolean) { - } - function isNumber(someNumber: number) { - } - function isString(someString: string) { - } - - function testConstructor() { - type MyModel = { numericProperty: number }; - - let db = new PouchDB('basic'); - db = new PouchDB(null, { - adapter: 'websql' - }); - db = new PouchDB('sized', { - adapter: 'websql', - size: 10 - }); - - db.info().then((info) => { - isBoolean(info.sqlite_plugin); - isString(info.websql_encoding); - }); - } +function isBoolean(someBoolean: boolean) { +} +function isNumber(someNumber: number) { +} +function isString(someString: string) { +} + +function testConstructor() { + type MyModel = { numericProperty: number }; + + let db = new PouchDB('basic'); + db = new PouchDB(null, { + adapter: 'websql' + }); + db = new PouchDB('sized', { + adapter: 'websql', + size: 10 + }); + + db.info().then((info) => { + isBoolean(info.sqlite_plugin); + isString(info.websql_encoding); + }); } diff --git a/types/pouchdb-browser/pouchdb-browser-tests.ts b/types/pouchdb-browser/pouchdb-browser-tests.ts index 8e5f1c913e..faaa5b5d21 100644 --- a/types/pouchdb-browser/pouchdb-browser-tests.ts +++ b/types/pouchdb-browser/pouchdb-browser-tests.ts @@ -1,16 +1,14 @@ -namespace PouchDBBrowserTests { - function testConstructor() { - type MyModel = { numericProperty: number }; - let model: PouchDB.Core.Document; +function testConstructor() { + type MyModel = { numericProperty: number }; + let model: PouchDB.Core.Document; - let db = new PouchDB(null, { - adapter: 'idb', - }); - db = new PouchDB('myDb', { - adapter: 'http', - }); - db.get('model').then((result) => model); - db.viewCleanup().catch((error) => { - }); - } + let db = new PouchDB(null, { + adapter: 'idb', + }); + db = new PouchDB('myDb', { + adapter: 'http', + }); + db.get('model').then((result) => model); + db.viewCleanup().catch((error) => { + }); } diff --git a/types/pouchdb-core/pouchdb-core-tests.ts b/types/pouchdb-core/pouchdb-core-tests.ts index fd8ac57359..a2593ce291 100644 --- a/types/pouchdb-core/pouchdb-core-tests.ts +++ b/types/pouchdb-core/pouchdb-core-tests.ts @@ -1,212 +1,209 @@ -namespace PouchDBCoreTests { - function isString(someString: string) { - } - function isNumber(someNumber: number) { - } - - function testAllDocs() { - const db = new PouchDB<{ foo: number }>(); - - db.allDocs().then(({ offset, total_rows, rows }) => { - isNumber(offset); - isNumber(total_rows); - - rows.forEach(({ id, key, value, doc }) => { - isString(id); - isString(key); - isString(value.rev); - - // check document property - isNumber(doc!.foo); - }) - }); - - db.allDocs({ startkey: "a", endkey: "b" }); - db.allDocs({ startkey: "a", endkey: "b", inclusive_end: true }); - db.allDocs({ keys: ["a", "b", "c" ]}); - db.allDocs({ key: "a" }); - db.allDocs({ - attachments: true, - binary: true, - conflicts: true, - descending: true, - include_docs: true, - limit: 5, - skip: 1 - }); - } - - function testBulkDocs() { - const db = new PouchDB(); - type MyModel = { property: string }; - let model = { property: 'test' }; - let model2 = { property: 'test' }; - - db.bulkDocs([model, model2]).then((result) => { - result.forEach(({ ok, id, rev }) => { - isString(id); - isString(rev); - }); - }); - - db.bulkDocs([model, model2], null, (error, response) => { - }); - } - - function testBulkGet() { - const db = new PouchDB<{}>(); - db.bulkGet({docs: [{id: 'a', rev: 'b'}, {id: 'b', rev: 'c'}, {id: 'c', rev: 'd'}]}).then((result) => {}); - db.bulkGet({docs: [{id: 'a', rev: 'b'}, {id: 'b', rev: 'c'}, {id: 'c', rev: 'd'}]}, (error, response) => {}); - } - - function testRevsDiff() { - const db = new PouchDB<{}>(); - db.revsDiff({'a': ['1-a', '2-b']}).then((result) => {}); - db.revsDiff({'a': ['1-a', '2-b']}, (error, response) => {}); - } - - function testCompact() { - const db = new PouchDB<{}>(); - // Promise version - db.compact().then( (res: PouchDB.Core.Response) => {}); - // Promise version with optional options - db.compact({interval: 300}).then( (res: PouchDB.Core.Response) => {}); - // Options with a callback - db.compact({interval: 300}, (res: PouchDB.Core.Response) => {}); - } - - function testDestroy() { - const db = new PouchDB<{}>(); - - db.destroy({}, (error) => { - }); - db.destroy().then(() => { - }).catch((error) => { - }); - } - - function testBasics() { - type MyModel = { property: string }; - let model = { property: 'test' }; - const id = 'model'; - - const db = new PouchDB(); - - db.post(model).then((result) => { - isString(result.id); - }); - db.post(model, null, (error, response) => { - }); - - db.get(id).then((result) => model = result); - db.get(id, null, (error, result) => { - }); - - db.put(model).then((error) => { - }); - db.put(model, null, (error) => { - }); - - db.info().then((info) => { - }); - db.info((error, result) => { - }); - - PouchDB.debug.enable('*'); - } - - function testRemove() { - type MyModel = { property: string }; - const id = 'model'; - const rev = 'rev'; - let model = { _id: id, _rev: rev, existingDocProperty: 'any' }; - - const db = new PouchDB(); - - // Promise version with doc - db.remove(model).then( (res: PouchDB.Core.Response) => {}); - - // Promise version with doc and options - db.remove(model, {}).then( (res: PouchDB.Core.Response) => {}); - - // Promise version with docId and rev - db.remove(id, rev).then( (res: PouchDB.Core.Response) => {}); - - // Promise version with docId and rev and options - db.remove(id, rev, {}).then( (res: PouchDB.Core.Response) => {}); - - // Callback version with doc - db.remove(model, {}, (res: PouchDB.Core.Response) => {}); - - // Callback version with docId and rev - db.remove(id, rev, {}, (res: PouchDB.Core.Response) => {}); - } - - function testChanges() { - type MyModel = { foo: string }; - const db = new PouchDB(); - - db.changes({ - live: true, - since: 'now', - timeout: 1, - include_docs: true, - limit: 1, - conflicts: true, - attachments: true, - binary: true, - descending: true, - heartbeat: 1, - filter: '', - doc_ids: [''], - query_params: {paramName: 'any'}, - view: '' - }) - .on('change', (change) => { - let _id: string = change.id; - let _seq: number = change.seq; - let _changes: { rev: string }[] = change.changes; - let _foo: string = change.doc!.foo; - let _deleted: boolean | undefined = change.doc!._deleted; - let _attachments: PouchDB.Core.Attachments | undefined = change.doc!._attachments; - }) - .on('complete', (info) => { - let _status: string = info.status; - let _last_req: number = info.last_seq; - let change = info.results[0]; - - let _id: string = change.id; - let _seq: number = change.seq; - let _changes: { rev: string }[] = change.changes; - let _deleted: boolean | undefined = change.doc!._deleted; - let _attachments: PouchDB.Core.Attachments | undefined = change.doc!._attachments; - }); - - db.changes({ - since: 1, - timeout: false, - limit: false, - heartbeat: false, - filter: (doc: any, params: any) => {} - }); - - db.changes({ limit: 50 }).then(() => {}); - } - - function testRemoteOptions() { - let db = new PouchDB('http://example.com/dbname', { - ajax: { - cache: false, - timeout: 10000, - headers: { - 'X-Some-Special-Header': 'foo' - }, - }, - auth: { - username: 'mysecretusername', - password: 'mysecretpassword' - }, - skip_setup: true - }); - } +function isString(someString: string) { +} +function isNumber(someNumber: number) { +} + +function testAllDocs() { + const db = new PouchDB<{ foo: number }>(); + + db.allDocs().then(({ offset, total_rows, rows }) => { + isNumber(offset); + isNumber(total_rows); + + rows.forEach(({ id, key, value, doc }) => { + isString(id); + isString(key); + isString(value.rev); + + // check document property + isNumber(doc!.foo); + }) + }); + + db.allDocs({ startkey: "a", endkey: "b" }); + db.allDocs({ startkey: "a", endkey: "b", inclusive_end: true }); + db.allDocs({ keys: ["a", "b", "c" ]}); + db.allDocs({ key: "a" }); + db.allDocs({ + attachments: true, + binary: true, + conflicts: true, + descending: true, + include_docs: true, + limit: 5, + skip: 1 + }); +} + +function testBulkDocs() { + const db = new PouchDB(); + type MyModel = { property: string }; + let model = { property: 'test' }; + let model2 = { property: 'test' }; + + db.bulkDocs([model, model2]).then((result) => { + result.forEach(({ ok, id, rev }) => { + isString(id); + isString(rev); + }); + }); + + db.bulkDocs([model, model2], null, (error, response) => { + }); +} + +function testBulkGet() { + const db = new PouchDB<{}>(); + db.bulkGet({docs: [{id: 'a', rev: 'b'}, {id: 'b', rev: 'c'}, {id: 'c', rev: 'd'}]}).then((result) => {}); + db.bulkGet({docs: [{id: 'a', rev: 'b'}, {id: 'b', rev: 'c'}, {id: 'c', rev: 'd'}]}, (error, response) => {}); +} +function testRevsDiff() { + const db = new PouchDB<{}>(); + db.revsDiff({'a': ['1-a', '2-b']}).then((result) => {}); + db.revsDiff({'a': ['1-a', '2-b']}, (error, response) => {}); +} + +function testCompact() { + const db = new PouchDB<{}>(); + // Promise version + db.compact().then( (res: PouchDB.Core.Response) => {}); + // Promise version with optional options + db.compact({interval: 300}).then( (res: PouchDB.Core.Response) => {}); + // Options with a callback + db.compact({interval: 300}, (res: PouchDB.Core.Response) => {}); +} + +function testDestroy() { + const db = new PouchDB<{}>(); + + db.destroy({}, (error) => { + }); + db.destroy().then(() => { + }).catch((error) => { + }); +} + +function testBasics() { + type MyModel = { property: string }; + let model = { property: 'test' }; + const id = 'model'; + + const db = new PouchDB(); + + db.post(model).then((result) => { + isString(result.id); + }); + db.post(model, null, (error, response) => { + }); + + db.get(id).then((result) => model = result); + db.get(id, null, (error, result) => { + }); + + db.put(model).then((error) => { + }); + db.put(model, null, (error) => { + }); + + db.info().then((info) => { + }); + db.info((error, result) => { + }); + + PouchDB.debug.enable('*'); +} + +function testRemove() { + type MyModel = { property: string }; + const id = 'model'; + const rev = 'rev'; + let model = { _id: id, _rev: rev, existingDocProperty: 'any' }; + + const db = new PouchDB(); + + // Promise version with doc + db.remove(model).then( (res: PouchDB.Core.Response) => {}); + + // Promise version with doc and options + db.remove(model, {}).then( (res: PouchDB.Core.Response) => {}); + + // Promise version with docId and rev + db.remove(id, rev).then( (res: PouchDB.Core.Response) => {}); + + // Promise version with docId and rev and options + db.remove(id, rev, {}).then( (res: PouchDB.Core.Response) => {}); + + // Callback version with doc + db.remove(model, {}, (res: PouchDB.Core.Response) => {}); + + // Callback version with docId and rev + db.remove(id, rev, {}, (res: PouchDB.Core.Response) => {}); +} + +function testChanges() { + type MyModel = { foo: string }; + const db = new PouchDB(); + + db.changes({ + live: true, + since: 'now', + timeout: 1, + include_docs: true, + limit: 1, + conflicts: true, + attachments: true, + binary: true, + descending: true, + heartbeat: 1, + filter: '', + doc_ids: [''], + query_params: {paramName: 'any'}, + view: '' + }) + .on('change', (change) => { + let _id: string = change.id; + let _seq: number = change.seq; + let _changes: { rev: string }[] = change.changes; + let _foo: string = change.doc!.foo; + let _deleted: boolean | undefined = change.doc!._deleted; + let _attachments: PouchDB.Core.Attachments | undefined = change.doc!._attachments; + }) + .on('complete', (info) => { + let _status: string = info.status; + let _last_req: number = info.last_seq; + let change = info.results[0]; + + let _id: string = change.id; + let _seq: number = change.seq; + let _changes: { rev: string }[] = change.changes; + let _deleted: boolean | undefined = change.doc!._deleted; + let _attachments: PouchDB.Core.Attachments | undefined = change.doc!._attachments; + }); + + db.changes({ + since: 1, + timeout: false, + limit: false, + heartbeat: false, + filter: (doc: any, params: any) => {} + }); + + db.changes({ limit: 50 }).then(() => {}); +} + +function testRemoteOptions() { + let db = new PouchDB('http://example.com/dbname', { + ajax: { + cache: false, + timeout: 10000, + headers: { + 'X-Some-Special-Header': 'foo' + }, + }, + auth: { + username: 'mysecretusername', + password: 'mysecretpassword' + }, + skip_setup: true + }); } diff --git a/types/pouchdb-find/pouchdb-find-tests.ts b/types/pouchdb-find/pouchdb-find-tests.ts index bebdc58cc1..6854d28e8f 100644 --- a/types/pouchdb-find/pouchdb-find-tests.ts +++ b/types/pouchdb-find/pouchdb-find-tests.ts @@ -1,70 +1,67 @@ -namespace PouchDBFindTests { +function testFind() { + const db = new PouchDB<{ foo: number }>(); - function testFind() { - const db = new PouchDB<{ foo: number }>(); + db.find({ + selector: {}, + fields: ['fieldName'], + sort: ['fieldName'], + limit: 1, + skip: 1 + }) - db.find({ - selector: {}, - fields: ['fieldName'], - sort: ['fieldName'], - limit: 1, - skip: 1 - }) + db.find({ + selector: {}, + sort: [{'fieldName': 'asc'}] + }); - db.find({ - selector: {}, - sort: [{'fieldName': 'asc'}] - }); + // test combinations of selectors + db.find({ + selector: { + // test id + _id: { + gt: null + }, - // test combinations of selectors - db.find({ - selector: { - // test id - _id: { - gt: null - }, + // conditions + foo: { + $lt: null, + $gt: null, + $lte: null, + $gte: null, + $eq: null, + $ne: null, + $elemMatch: null, - // conditions - foo: { - $lt: null, - $gt: null, - $lte: null, - $gte: null, - $eq: null, - $ne: null, - $elemMatch: null, + $exists: true, + $type: "null", + $in: ["string", null, 1, true, {}, []], + $nin: ["string", null, 1, true, {}, []], + $size: 5, + $mod: [1, 2], + $regex: "pattern", + $all: ["string", null, 1, true, {}, []] + }, - $exists: true, - $type: "null", - $in: ["string", null, 1, true, {}, []], - $nin: ["string", null, 1, true, {}, []], - $size: 5, - $mod: [1, 2], - $regex: "pattern", - $all: ["string", null, 1, true, {}, []] - }, + // value + bar: 'any value', - // value - bar: 'any value', + // combinatons + $and: [], + $or: [], + $nor: [], + $not: [], - // combinatons - $and: [], - $or: [], - $nor: [], - $not: [], - - // sub combinations - sub: { - $and: [ - { - foo: 'bar', - bar: { - $gt: null - } + // sub combinations + sub: { + $and: [ + { + foo: 'bar', + bar: { + $gt: null } - ] - } + } + ] } - }); - } + } + }); } diff --git a/types/pouchdb-http/pouchdb-http-tests.ts b/types/pouchdb-http/pouchdb-http-tests.ts index 17d28c81ea..05a0f1667d 100644 --- a/types/pouchdb-http/pouchdb-http-tests.ts +++ b/types/pouchdb-http/pouchdb-http-tests.ts @@ -1,11 +1,9 @@ -namespace PouchDBHttpTests { - function testConstructor() { - type MyModel = { numericProperty: number }; - let model: PouchDB.Core.Document; +function testConstructor() { + type MyModel = { numericProperty: number }; + let model: PouchDB.Core.Document; - let db = new PouchDB('myDb', { - adapter: 'http', - }); - db.get('model').then((result) => model); - } + let db = new PouchDB('myDb', { + adapter: 'http', + }); + db.get('model').then((result) => model); } diff --git a/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts b/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts index a2cdd053c9..6f6d941e83 100644 --- a/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts +++ b/types/pouchdb-mapreduce/pouchdb-mapreduce-tests.ts @@ -1,36 +1,34 @@ -namespace PouchDBBrowserTests { - function testConstructor() { - type MyModel = { numericProperty: number }; - let model: PouchDB.Core.Document; +function testConstructor() { + type MyModel = { numericProperty: number }; + let model: PouchDB.Core.Document; + + let db = new PouchDB('mydb'); + db.viewCleanup().catch((error) => { + }); +} + +function testQuery() { + let pouch = new PouchDB<{}>('mydb'); + // find pokemon with name === 'Pika pi!' + pouch.query('my_index/by_name', { + key : 'Pika pi!', + include_docs : true + }).then(function (result) { + // handle result + }).catch(function (err) { + // handle errors + }); + + // find the first 5 pokemon whose name starts with 'P' + pouch.query('my_index/by_name', { + startkey : 'P', + endkey : 'P\uffff', + limit : 5, + include_docs : true + }).then(function (result) { + // handle result + }).catch(function (err) { + // handle errors + }); - let db = new PouchDB('mydb'); - db.viewCleanup().catch((error) => { - }); - } - - function testQuery() { - let pouch = new PouchDB<{}>('mydb'); - // find pokemon with name === 'Pika pi!' - pouch.query('my_index/by_name', { - key : 'Pika pi!', - include_docs : true - }).then(function (result) { - // handle result - }).catch(function (err) { - // handle errors - }); - - // find the first 5 pokemon whose name starts with 'P' - pouch.query('my_index/by_name', { - startkey : 'P', - endkey : 'P\uffff', - limit : 5, - include_docs : true - }).then(function (result) { - // handle result - }).catch(function (err) { - // handle errors - }); - - } } diff --git a/types/pouchdb-node/pouchdb-node-tests.ts b/types/pouchdb-node/pouchdb-node-tests.ts index caa7f9d091..107dcf00e8 100644 --- a/types/pouchdb-node/pouchdb-node-tests.ts +++ b/types/pouchdb-node/pouchdb-node-tests.ts @@ -1,16 +1,14 @@ -namespace PouchDBBrowserTests { - function testConstructor() { - type MyModel = { numericProperty: number }; - let model: PouchDB.Core.Document; +function testConstructor() { + type MyModel = { numericProperty: number }; + let model: PouchDB.Core.Document; - let db = new PouchDB('myDb', { - adapter: 'http', - }); - db = new PouchDB('myDb', { - adapter: 'leveldb', - }); - db.get('model').then((result) => model); - db.viewCleanup().catch((error) => { - }); - } + let db = new PouchDB('myDb', { + adapter: 'http', + }); + db = new PouchDB('myDb', { + adapter: 'leveldb', + }); + db.get('model').then((result) => model); + db.viewCleanup().catch((error) => { + }); } diff --git a/types/pouchdb-replication/pouchdb-replication-tests.ts b/types/pouchdb-replication/pouchdb-replication-tests.ts index 3cb6d6bc17..9cf352bed6 100644 --- a/types/pouchdb-replication/pouchdb-replication-tests.ts +++ b/types/pouchdb-replication/pouchdb-replication-tests.ts @@ -1,16 +1,13 @@ -namespace PouchDBReplicationTests { +/** @todo make some real tests */ +function testReplication() { + type Model = { foo: number }; + const db = new PouchDB(); - /** @todo make some real tests */ - function testReplication() { - type Model = { foo: number }; - const db = new PouchDB(); + db.replicate.to('').then((res: PouchDB.Replication.ReplicationResultComplete) => { - db.replicate.to('').then((res: PouchDB.Replication.ReplicationResultComplete) => { + }); - }); + db.replicate.from('').then((res: PouchDB.Replication.ReplicationResultComplete) => { - db.replicate.from('').then((res: PouchDB.Replication.ReplicationResultComplete) => { - - }); - } + }); } diff --git a/types/pouchdb-upsert/pouchdb-upsert-tests.ts b/types/pouchdb-upsert/pouchdb-upsert-tests.ts index 5ed17266b1..7da1c46267 100644 --- a/types/pouchdb-upsert/pouchdb-upsert-tests.ts +++ b/types/pouchdb-upsert/pouchdb-upsert-tests.ts @@ -1,47 +1,45 @@ import * as pouchdbUpsert from 'pouchdb-upsert'; PouchDB.plugin(pouchdbUpsert); -namespace PouchDBUpsertTests { - type UpsertDocModel = { _id: 'test-doc1', name: 'test' }; - let docToUpsert: PouchDB.Core.Document; - const db = new PouchDB(); +type UpsertDocModel = { _id: 'test-doc1', name: 'test' }; +let docToUpsert: PouchDB.Core.Document; +const db = new PouchDB(); - function testUpsert_WithPromise_AndReturnDoc() { - db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { - // Make some updates.... - return doc; - }).then((res: PouchDB.Core.Response) => { - }); - } - - function testUpsert_WithPromise_AndReturnBoolean() { - db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { - // Make some updates.... - return false; - }).then((res: PouchDB.Core.Response) => { - }); - } - - function testUpsert_WithCallback_AndReturnDoc() { - db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { - // Make some updates.... - return doc; - }, (res: PouchDB.Core.Response) => {}); - } - - function testUpsert_WithCallback_AndReturnBoolean() { - // callback return boolean - db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { - // Make some updates.... - return false; - }, (res: PouchDB.Core.Response) => {}); - } - - function testPutIfNotExists_WithPromise() { - db.putIfNotExists(docToUpsert).then( (res: PouchDB.Core.Response) => {}); - } - - function testPutIfNotExists_WithCallback() { - db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Response) => {}); - } +function testUpsert_WithPromise_AndReturnDoc() { + db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { + // Make some updates.... + return doc; + }).then((res: PouchDB.Core.Response) => { + }); +} + +function testUpsert_WithPromise_AndReturnBoolean() { + db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { + // Make some updates.... + return false; + }).then((res: PouchDB.Core.Response) => { + }); +} + +function testUpsert_WithCallback_AndReturnDoc() { + db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { + // Make some updates.... + return doc; + }, (res: PouchDB.Core.Response) => {}); +} + +function testUpsert_WithCallback_AndReturnBoolean() { + // callback return boolean + db.upsert(docToUpsert._id, (doc: PouchDB.Core.Document) => { + // Make some updates.... + return false; + }, (res: PouchDB.Core.Response) => {}); +} + +function testPutIfNotExists_WithPromise() { + db.putIfNotExists(docToUpsert).then( (res: PouchDB.Core.Response) => {}); +} + +function testPutIfNotExists_WithCallback() { + db.putIfNotExists(docToUpsert, (res: PouchDB.Core.Response) => {}); } diff --git a/types/pouchdb/pouchdb-tests.ts b/types/pouchdb/pouchdb-tests.ts index 3d580b9bff..ef7da0fd83 100644 --- a/types/pouchdb/pouchdb-tests.ts +++ b/types/pouchdb/pouchdb-tests.ts @@ -1,106 +1,104 @@ import * as PouchDB from 'pouchdb'; -namespace PouchDBTests { - function isString(someString: string) { - } - function isNumber(someNumber: number) { - } - - function testAllDocs() { - const db = new PouchDB<{ foo: number }>(); - - db.allDocs().then(({ offset, total_rows, rows }) => { - isNumber(offset); - isNumber(total_rows); - - rows.forEach(({ id, key, value, doc }) => { - isString(id); - isString(key); - isString(value.rev); - - // check document property - isNumber(doc.foo); - }) - }); - - db.allDocs({ startkey: "a", endkey: "b" }); - db.allDocs({ startkey: "a", endkey: "b", inclusive_end: true }); - db.allDocs({ keys: ["a", "b", "c" ]}); - db.allDocs({ key: "a" }); - db.allDocs({ - attachments: true, - binary: true, - conflicts: true, - descending: true, - include_docs: true, - limit: 5, - skip: 1 - }); - } - - function testDestroy() { - const db = new PouchDB<{}>(); - - db.destroy({}, (error) => { - }); - db.destroy().then(() => { - }).catch((error) => { - }); - } - - function testBasics() { - type MyModel = { property: 'someProperty '}; - let model: PouchDB.Core.Document; - const id = 'model'; - - let db = new PouchDB(); - db = new PouchDB(null, { - adapter: 'fruitdown' - }); - db = new PouchDB(null, { - adapter: 'http' - }); - db = new PouchDB(null, { - adapter: 'idb' - }); - db = new PouchDB(null, { - adapter: 'leveldb' - }); - db = new PouchDB(null, { - adapter: 'localstorage' - }); - db = new PouchDB(null, { - adapter: 'memory' - }); - db = new PouchDB(null, { - adapter: 'websql' - }); - db = new PouchDB(null, { - adapter: 'websql', - size: 100 - }); - - db.post(model).then((result) => { - isString(result.id); - }); - db.post(model, null, (error, response) => { - }); - - db.get(id).then((result) => model = result); - db.get(id, null, (error, result) => { - }); - - db.put(model).then((error) => { - }); - db.put(model, null, (error) => { - }); - - db.info().then((info) => { - }); - db.info((error, result) => { - }); - - db.viewCleanup().catch((error) => { - }); - } +function isString(someString: string) { +} +function isNumber(someNumber: number) { +} + +function testAllDocs() { + const db = new PouchDB<{ foo: number }>(); + + db.allDocs().then(({ offset, total_rows, rows }) => { + isNumber(offset); + isNumber(total_rows); + + rows.forEach(({ id, key, value, doc }) => { + isString(id); + isString(key); + isString(value.rev); + + // check document property + isNumber(doc.foo); + }) + }); + + db.allDocs({ startkey: "a", endkey: "b" }); + db.allDocs({ startkey: "a", endkey: "b", inclusive_end: true }); + db.allDocs({ keys: ["a", "b", "c" ]}); + db.allDocs({ key: "a" }); + db.allDocs({ + attachments: true, + binary: true, + conflicts: true, + descending: true, + include_docs: true, + limit: 5, + skip: 1 + }); +} + +function testDestroy() { + const db = new PouchDB<{}>(); + + db.destroy({}, (error) => { + }); + db.destroy().then(() => { + }).catch((error) => { + }); +} + +function testBasics() { + type MyModel = { property: 'someProperty '}; + let model: PouchDB.Core.Document; + const id = 'model'; + + let db = new PouchDB(); + db = new PouchDB(null, { + adapter: 'fruitdown' + }); + db = new PouchDB(null, { + adapter: 'http' + }); + db = new PouchDB(null, { + adapter: 'idb' + }); + db = new PouchDB(null, { + adapter: 'leveldb' + }); + db = new PouchDB(null, { + adapter: 'localstorage' + }); + db = new PouchDB(null, { + adapter: 'memory' + }); + db = new PouchDB(null, { + adapter: 'websql' + }); + db = new PouchDB(null, { + adapter: 'websql', + size: 100 + }); + + db.post(model).then((result) => { + isString(result.id); + }); + db.post(model, null, (error, response) => { + }); + + db.get(id).then((result) => model = result); + db.get(id, null, (error, result) => { + }); + + db.put(model).then((error) => { + }); + db.put(model, null, (error) => { + }); + + db.info().then((info) => { + }); + db.info((error, result) => { + }); + + db.viewCleanup().catch((error) => { + }); } diff --git a/types/pug/pug-tests.ts b/types/pug/pug-tests.ts index 53c65fe995..ac4ae44051 100644 --- a/types/pug/pug-tests.ts +++ b/types/pug/pug-tests.ts @@ -4,7 +4,7 @@ import * as pug from 'pug'; //////////////////////////////////////////////////////////// /// Options https://pugjs.org/api/reference.html#options /// //////////////////////////////////////////////////////////// -namespace options_tests { +{ let opts: pug.Options = {}; let str = 'string' let bool = false; @@ -38,7 +38,7 @@ namespace options_tests { //////////////////////////////////////////////////////////// /// Methods https://pugjs.org/api/reference.html#methods /// //////////////////////////////////////////////////////////// -namespace methods_tests { +{ let source = `p #{ name } 's Pug source code!`; let path = "foo.pug"; let compileTemplate: pug.compileTemplate; diff --git a/types/query-string/query-string-tests.ts b/types/query-string/query-string-tests.ts index 32dd186c83..6e948cf6e5 100644 --- a/types/query-string/query-string-tests.ts +++ b/types/query-string/query-string-tests.ts @@ -1,6 +1,7 @@ import * as queryString from 'query-string'; -namespace stringify_tests { +// stringify +{ let result: string; // test obj result = queryString.stringify({ @@ -18,7 +19,8 @@ namespace stringify_tests { result = queryString.stringify({ foo: 'bar' }, { strict: false, encode: false }); } -namespace parse_tests { +// parse +{ let fooBar: { foo: 'bar' }; fooBar = queryString.parse('?foo=bar'); fooBar = queryString.parse('#foo=bar'); @@ -27,7 +29,8 @@ namespace parse_tests { fooBarBaz = queryString.parse('&foo=bar&foo=baz'); } -namespace extract_tests { +// extract +{ let result: string; result = queryString.extract('http://foo.bar/?abc=def&hij=klm'); result = queryString.extract('http://foo.bar/?foo=bar'); diff --git a/types/react-virtualized/react-virtualized-tests.tsx b/types/react-virtualized/react-virtualized-tests.tsx index ad413978ee..aa44909cdf 100644 --- a/types/react-virtualized/react-virtualized-tests.tsx +++ b/types/react-virtualized/react-virtualized-tests.tsx @@ -1,1751 +1,2 @@ -import * as React from 'react'; -import { PureComponent } from 'react' -import { ArrowKeyStepper, AutoSizer, Grid } from 'react-virtualized' - -export class ArrowKeyStepperExample extends PureComponent { - constructor(props) { - super(props) - - this._getColumnWidth = this._getColumnWidth.bind(this) - this._getRowHeight = this._getRowHeight.bind(this) - this._cellRenderer = this._cellRenderer.bind(this) - } - - render() { - const { mode } = this.state - - return ( - - - {({ onSectionRendered, scrollToColumn, scrollToRow }) => ( -
- - - {({ width }) => ( - this._cellRenderer({ columnIndex, key, rowIndex, scrollToColumn, scrollToRow, style })} - rowHeight={this._getRowHeight} - rowCount={100} - scrollToColumn={scrollToColumn} - scrollToRow={scrollToRow} - width={width} - /> - )} - -
- )} -
- ) - } - - _getColumnWidth({ index }) { - return (1 + (index % 3)) * 60 - } - - _getRowHeight({ index }) { - return (1 + (index % 3)) * 30 - } - - _cellRenderer({ columnIndex, key, rowIndex, scrollToColumn, scrollToRow, style }) { - - return ( -
- {`r:${rowIndex}, c:${columnIndex}`} -
- ) - } -} - -import { List } from 'react-virtualized' - -export class AutoSizerExample extends PureComponent { - constructor(props) { - super(props) - - this._rowRenderer = this._rowRenderer.bind(this) - } - - render() { - const { list } = this.context - const { hideDescription } = this.state - - return ( - - {({ width, height }) => ( - - )} - - ) - } - - _rowRenderer({ index, key, style }) { - const { list } = this.context - const row = list.get(index) - - return ( -
- {row.name} -
- ) - } -} import { } from 'react' import { CellMeasurer, CellMeasurerCache } from 'react-virtualized' - -export class DynamicHeightList extends PureComponent { - - _cache: CellMeasurerCache - - constructor(props, context) { - super(props, context) - - this._cache = new CellMeasurerCache({ - fixedWidth: true, - minHeight: 50 - }) - - this._rowRenderer = this._rowRenderer.bind(this) - } - - render() { - const { width } = this.props - - return ( - - ) - } - - _rowRenderer({ index, isScrolling, key, parent, style }) { - const { getClassName, list } = this.props - - const datum = list.get(index % list.size) - const classNames = getClassName({ columnIndex: 0, rowIndex: index }) - - const imageWidth = 300 - const imageHeight = datum.size * 2 - - const source = `http://fillmurray.com/${imageWidth}/${imageHeight}` - - return ( - - {({ measure }) => ( -
- -
- )} -
- ) - } -} - -import { Collection } from 'react-virtualized' - -// Defines a pattern of sizes and positions for a range of 10 rotating cells -// These cells cover an area of 600 (wide) x 400 (tall) -const GUTTER_SIZE = 3 -const CELL_WIDTH = 75 - -export class CollectionExample extends PureComponent { - _columnYMap: any; - - constructor(props, context) { - super(props, context) - - this.context = context; - - this.state = { - cellCount: context.list.size, - columnCount: this._getColumnCount(context.list.size), - height: 300, - horizontalOverscanSize: 0, - scrollToCell: undefined, - showScrollingPlaceholder: false, - verticalOverscanSize: 0 - } - - this._columnYMap = [] - - this._cellRenderer = this._cellRenderer.bind(this) - this._cellSizeAndPositionGetter = this._cellSizeAndPositionGetter.bind(this) - this._noContentRenderer = this._noContentRenderer.bind(this) - this._onCellCountChange = this._onCellCountChange.bind(this) - this._onHeightChange = this._onHeightChange.bind(this) - this._onHorizontalOverscanSizeChange = this._onHorizontalOverscanSizeChange.bind(this) - this._onScrollToCellChange = this._onScrollToCellChange.bind(this) - this._onVerticalOverscanSizeChange = this._onVerticalOverscanSizeChange.bind(this) - } - - render() { - const { cellCount, height, horizontalOverscanSize, scrollToCell, showScrollingPlaceholder, verticalOverscanSize } = this.state - - return ( - - {({ width }) => ( - - )} - - ) - } - - _cellRenderer({ index, isScrolling, key, style }) { - const { list } = this.context - const { showScrollingPlaceholder } = this.state - - const datum = list.get(index % list.size) - - // Customize style - style.backgroundColor = datum.color - - return ( -
- {showScrollingPlaceholder && isScrolling ? '...' : index} -
- ) - } - - _cellSizeAndPositionGetter({ index }) { - const { list } = this.context - const { columnCount } = this.state - - const columnPosition = index % (columnCount || 1) - const datum = list.get(index % list.size) - - // Poor man's Masonry layout; columns won't all line up equally with the bottom. - const height = datum.size - const width = CELL_WIDTH - const x = columnPosition * (GUTTER_SIZE + width) - const y = this._columnYMap[columnPosition] || 0 - - this._columnYMap[columnPosition] = y + height + GUTTER_SIZE - - return { - height, - width, - x, - y - } - } - - _getColumnCount(cellCount) { - return Math.round(Math.sqrt(cellCount)) - } - - _onHorizontalOverscanSizeChange(event) { - const horizontalOverscanSize = parseInt(event.target.value, 10) || 0 - - this.setState({ horizontalOverscanSize }) - } - - _noContentRenderer() { - return ( -
- No cells -
- ) - } - - _onCellCountChange(event) { - const cellCount = parseInt(event.target.value, 10) || 0 - - this._columnYMap = [] - - this.setState({ - cellCount, - columnCount: this._getColumnCount(cellCount) - }) - } - - _onHeightChange(event) { - const height = parseInt(event.target.value, 10) || 0 - - this.setState({ height }) - } - - _onScrollToCellChange(event) { - const { cellCount } = this.state - - let scrollToCell = Math.min(cellCount - 1, parseInt(event.target.value, 10)) - - if (isNaN(scrollToCell)) { - scrollToCell = undefined - } - - this.setState({ scrollToCell }) - } - - _onVerticalOverscanSizeChange(event) { - const verticalOverscanSize = parseInt(event.target.value, 10) || 0 - - this.setState({ verticalOverscanSize }) - } -} - -import { ColumnSizer } from 'react-virtualized' - -export class ColumnSizerExample extends PureComponent { - constructor(props) { - super(props) - - this._noColumnMaxWidthChange = this._noColumnMaxWidthChange.bind(this) - this._noColumnMinWidthChange = this._noColumnMinWidthChange.bind(this) - this._onColumnCountChange = this._onColumnCountChange.bind(this) - this._noContentRenderer = this._noContentRenderer.bind(this) - this._cellRenderer = this._cellRenderer.bind(this) - } - - render() { - const { - columnMaxWidth, - columnMinWidth, - columnCount - } = this.state - - return ( -
- - {({ width }) => ( - - {({ adjustedWidth, getColumnWidth, registerChild }) => ( -
- -
- )} -
- )} -
-
- ) - } - - _noColumnMaxWidthChange(event) { - let columnMaxWidth = parseInt(event.target.value, 10) - - if (isNaN(columnMaxWidth)) { - columnMaxWidth = undefined - } else { - columnMaxWidth = Math.min(1000, columnMaxWidth) - } - - this.setState({ columnMaxWidth }) - } - - _noColumnMinWidthChange(event) { - let columnMinWidth = parseInt(event.target.value, 10) - - if (isNaN(columnMinWidth)) { - columnMinWidth = undefined - } else { - columnMinWidth = Math.max(1, columnMinWidth) - } - - this.setState({ columnMinWidth }) - } - - _onColumnCountChange(event) { - this.setState({ columnCount: parseInt(event.target.value, 10) || 0 }) - } - - _noContentRenderer() { - return ( -
- No cells -
- ) - } - - _cellRenderer({ columnIndex, key, rowIndex, style }) { - const className = columnIndex === 0 - ? 'styles.firstCell' - : 'styles.cell' - - return ( -
- {`R:${rowIndex}, C:${columnIndex}`} -
- ) - } -} - -export class GridExample extends PureComponent { - constructor(props, context) { - super(props, context) - - this.state = { - columnCount: 1000, - height: 300, - overscanColumnCount: 0, - overscanRowCount: 10, - rowHeight: 40, - rowCount: 1000, - scrollToColumn: undefined, - scrollToRow: undefined, - useDynamicRowHeight: false - } - - this._cellRenderer = this._cellRenderer.bind(this) - this._getColumnWidth = this._getColumnWidth.bind(this) - this._getRowClassName = this._getRowClassName.bind(this) - this._getRowHeight = this._getRowHeight.bind(this) - this._noContentRenderer = this._noContentRenderer.bind(this) - this._onColumnCountChange = this._onColumnCountChange.bind(this) - this._onRowCountChange = this._onRowCountChange.bind(this) - this._onScrollToColumnChange = this._onScrollToColumnChange.bind(this) - this._onScrollToRowChange = this._onScrollToRowChange.bind(this) - this._renderBodyCell = this._renderBodyCell.bind(this) - this._renderLeftSideCell = this._renderLeftSideCell.bind(this) - } - - render() { - const { - columnCount, - height, - overscanColumnCount, - overscanRowCount, - rowHeight, - rowCount, - scrollToColumn, - scrollToRow, - useDynamicRowHeight - } = this.state - - return ( - - - {({ width }) => ( - - )} - - ) - } - - _cellRenderer({ columnIndex, key, rowIndex, style }) { - if (columnIndex === 0) { - return this._renderLeftSideCell({ key, rowIndex, style }) - } else { - return this._renderBodyCell({ columnIndex, key, rowIndex, style }) - } - } - - _getColumnWidth({ index }) { - switch (index) { - case 0: - return 50 - case 1: - return 100 - case 2: - return 300 - default: - return 80 - } - } - - _getDatum(index) { - const { list } = this.context - - return list.get(index % list.size) - } - - _getRowClassName(row) { - return row % 2 === 0 ? 'styles.evenRow' : 'styles.oddRow' - } - - _getRowHeight({ index }) { - return this._getDatum(index).size - } - - _noContentRenderer() { - return ( -
- No cells -
- ) - } - - _renderBodyCell({ columnIndex, key, rowIndex, style }) { - const rowClass = this._getRowClassName(rowIndex) - const datum = this._getDatum(rowIndex) - - let content - - switch (columnIndex) { - case 1: - content = datum.name - break - case 2: - content = datum.random - break - default: - content = `r:${rowIndex}, c:${columnIndex}` - break - } - - return ( -
- {content} -
- ) - } - - _renderLeftSideCell({ key, rowIndex, style }) { - const datum = this._getDatum(rowIndex) - - // Don't modify styles. - // These are frozen by React now (as of 16.0.0). - // Since Grid caches and re-uses them, they aren't safe to modify. - style = { - ...style, - backgroundColor: datum.color - } - - return ( -
- {datum.name.charAt(0)} -
- ) - } - - _updateUseDynamicRowHeights(value) { - this.setState({ - useDynamicRowHeight: value - }) - } - - _onColumnCountChange(event) { - const columnCount = parseInt(event.target.value, 10) || 0 - - this.setState({ columnCount }) - } - - _onRowCountChange(event) { - const rowCount = parseInt(event.target.value, 10) || 0 - - this.setState({ rowCount }) - } - - _onScrollToColumnChange(event) { - const { columnCount } = this.state - let scrollToColumn = Math.min(columnCount - 1, parseInt(event.target.value, 10)) - - if (isNaN(scrollToColumn)) { - scrollToColumn = undefined - } - - this.setState({ scrollToColumn }) - } - - _onScrollToRowChange(event) { - const { rowCount } = this.state - let scrollToRow = Math.min(rowCount - 1, parseInt(event.target.value, 10)) - - if (isNaN(scrollToRow)) { - scrollToRow = undefined - } - - this.setState({ scrollToRow }) - } -} - -import { InfiniteLoader } from 'react-virtualized' - -const STATUS_LOADING = 1 -const STATUS_LOADED = 2 - -export class InfiniteLoaderExample extends PureComponent { - _timeoutIdMap: any; - - constructor(props) { - super(props) - - this._timeoutIdMap = {} - - this._clearData = this._clearData.bind(this) - this._isRowLoaded = this._isRowLoaded.bind(this) - this._loadMoreRows = this._loadMoreRows.bind(this) - this._rowRenderer = this._rowRenderer.bind(this) - } - - componentWillUnmount() { - Object.keys(this._timeoutIdMap).forEach(timeoutId => { - clearTimeout(timeoutId as any) - }) - } - - render() { - const { list } = this.context - const { loadedRowCount, loadingRowCount } = this.state - - return ( - - {({ onRowsRendered, registerChild }) => ( - - {({ width }) => ( - - )} - - )} - - ) - } - - _clearData() { - this.setState({ - loadedRowCount: 0, - loadedRowsMap: {}, - loadingRowCount: 0 - }) - } - - _isRowLoaded({ index }) { - const { loadedRowsMap } = this.state - return !!loadedRowsMap[index] // STATUS_LOADING or STATUS_LOADED - } - - _loadMoreRows({ startIndex, stopIndex }) { - const { loadedRowsMap, loadingRowCount } = this.state - const increment = stopIndex - startIndex + 1 - - for (let i = startIndex; i <= stopIndex; i++) { - loadedRowsMap[i] = STATUS_LOADING - } - - this.setState({ - loadingRowCount: loadingRowCount + increment - }) - - const timeoutId = setTimeout(() => { - const { loadedRowCount, loadingRowCount } = this.state - - delete this._timeoutIdMap[timeoutId] - - for (let i = startIndex; i <= stopIndex; i++) { - loadedRowsMap[i] = STATUS_LOADED - } - - this.setState({ - loadingRowCount: loadingRowCount - increment, - loadedRowCount: loadedRowCount + increment - }) - - promiseResolver() - }, 1000 + Math.round(Math.random() * 2000)) - - this._timeoutIdMap[timeoutId] = true - - let promiseResolver - - return new Promise(resolve => { - promiseResolver = resolve - }) - } - - _rowRenderer({ index, key, style }) { - const { list } = this.context - const { loadedRowsMap } = this.state - - const row = list.get(index) - let content - - if (loadedRowsMap[index] === STATUS_LOADED) { - content = row.name - } else { - content = ( -
- ) - } - - return ( -
- {content} -
- ) - } -} - -export class ListExample extends PureComponent { - - constructor(props, context) { - super(props, context) - - this.state = { - listHeight: 300, - listRowHeight: 50, - overscanRowCount: 10, - rowCount: context.list.size, - scrollToIndex: undefined, - showScrollingPlaceholder: false, - useDynamicRowHeight: false - } - - this._getRowHeight = this._getRowHeight.bind(this) - this._noRowsRenderer = this._noRowsRenderer.bind(this) - this._onRowCountChange = this._onRowCountChange.bind(this) - this._onScrollToRowChange = this._onScrollToRowChange.bind(this) - this._rowRenderer = this._rowRenderer.bind(this) - } - - render() { - const { - listHeight, - listRowHeight, - overscanRowCount, - rowCount, - scrollToIndex, - showScrollingPlaceholder, - useDynamicRowHeight - } = this.state - - return ( - - {({ width }) => ( - - )} - - ) - } - - _getDatum(index) { - const { list } = this.context - - return list.get(index % list.size) - } - - _getRowHeight({ index }) { - return this._getDatum(index).size - } - - _noRowsRenderer() { - return ( -
- No rows -
- ) - } - - _onRowCountChange(event) { - const rowCount = parseInt(event.target.value, 10) || 0 - - this.setState({ rowCount }) - } - - _onScrollToRowChange(event) { - const { rowCount } = this.state - let scrollToIndex = Math.min(rowCount - 1, parseInt(event.target.value, 10)) - - if (isNaN(scrollToIndex)) { - scrollToIndex = undefined - } - - this.setState({ scrollToIndex }) - } - - _rowRenderer({ index, isScrolling, key, style }) { - const { - showScrollingPlaceholder, - useDynamicRowHeight - } = this.state - - if ( - showScrollingPlaceholder && - isScrolling - ) { - return ( -
- Scrolling... -
- ) - } - - const datum = this._getDatum(index) - - let additionalContent - - if (useDynamicRowHeight) { - switch (datum.size) { - case 75: - additionalContent =
It is medium-sized.
- break - case 100: - additionalContent =
It is large-sized.
It has a 3rd row.
- break - } - } - - return ( -
-
- {datum.name.charAt(0)} -
-
-
- {datum.name} -
-
- This is row {index} -
- {additionalContent} -
- {useDynamicRowHeight && - - {datum.size}px - - } -
- ) - } -} - -import { - WindowScroller, - createMasonryCellPositioner as createCellPositioner, - Positioner, - Masonry, - MasonryCellProps -} from 'react-virtualized' - -export class GridExample2 extends PureComponent { - _columnCount: number; - _cache: CellMeasurerCache; - _columnHeights: any; - _width: number; - _height: number; - _scrollTop: number; - _cellPositioner?: Positioner; - _masonry: Masonry; - - constructor(props, context) { - super(props, context) - - this._columnCount = 0 - - this._cache = new CellMeasurerCache({ - defaultHeight: 250, - defaultWidth: 200, - fixedWidth: true - }) - - this._columnHeights = {} - - this.state = { - columnWidth: 200, - height: 300, - gutterSize: 10, - windowScrollerEnabled: false - } - - this._cellRenderer = this._cellRenderer.bind(this) - this._onResize = this._onResize.bind(this) - this._renderAutoSizer = this._renderAutoSizer.bind(this) - this._renderMasonry = this._renderMasonry.bind(this) - this._setMasonryRef = this._setMasonryRef.bind(this) - } - - render() { - const { - columnWidth, - height, - gutterSize, - windowScrollerEnabled - } = this.state - - let child - - if (windowScrollerEnabled) { - child = ( - - {this._renderAutoSizer} - - ) - } else { - child = this._renderAutoSizer({ height }) - } - - return ( -
- {child} -
- ) - } - - _calculateColumnCount() { - const { - columnWidth, - gutterSize - } = this.state - - this._columnCount = Math.floor(this._width / (columnWidth + gutterSize)) - } - - _cellRenderer({ index, key, parent, style }: MasonryCellProps) { - const { list } = this.context - const { columnWidth } = this.state - - const datum = list.get(index % list.size) - - return ( - -
-
- {datum.random} -
- - ) - } - - _initCellPositioner() { - if (typeof this._cellPositioner === 'undefined') { - const { - columnWidth, - gutterSize - } = this.state - - this._cellPositioner = createCellPositioner({ - cellMeasurerCache: this._cache, - columnCount: this._columnCount, - columnWidth, - spacer: gutterSize - }) - } - } - - _onResize({ height, width }) { - this._width = width - - this._columnHeights = {} - this._calculateColumnCount() - this._resetCellPositioner() - this._masonry.recomputeCellPositions() - } - - _renderAutoSizer({ height, scrollTop }: { height: number, scrollTop?: number }) { - this._height = height - this._scrollTop = scrollTop - - return ( - - {this._renderMasonry} - - ) - } - - _renderMasonry({ width }) { - this._width = width - - this._calculateColumnCount() - this._initCellPositioner() - - const { height, windowScrollerEnabled } = this.state - - return ( - - ) - } - - _resetCellPositioner() { - const { - columnWidth, - gutterSize - } = this.state - - this._cellPositioner.reset({ - columnCount: this._columnCount, - columnWidth, - spacer: gutterSize - }) - } - - _setMasonryRef(ref) { - this._masonry = ref - } -} - -import { MultiGrid } from 'react-virtualized' - -const STYLE: React.CSSProperties = { - border: '1px solid #ddd', - overflow: 'hidden' -} -const STYLE_BOTTOM_LEFT_GRID: React.CSSProperties = { - borderRight: '2px solid #aaa', - backgroundColor: '#f7f7f7' -} -const STYLE_TOP_LEFT_GRID: React.CSSProperties = { - borderBottom: '2px solid #aaa', - borderRight: '2px solid #aaa', - fontWeight: 'bold' -} -const STYLE_TOP_RIGHT_GRID: React.CSSProperties = { - borderBottom: '2px solid #aaa', - fontWeight: 'bold' -} - -export class MultiGridExample extends PureComponent { - state - _onFixedColumnCountChange - _onFixedRowCountChange - _onScrollToColumnChange - _onScrollToRowChange - - constructor(props, context) { - super(props, context) - - this.state = { - fixedColumnCount: 2, - fixedRowCount: 1, - scrollToColumn: 0, - scrollToRow: 0 - } - - this._cellRenderer = this._cellRenderer.bind(this) - this._onFixedColumnCountChange = this._createEventHandler('fixedColumnCount') - this._onFixedRowCountChange = this._createEventHandler('fixedRowCount') - this._onScrollToColumnChange = this._createEventHandler('scrollToColumn') - this._onScrollToRowChange = this._createEventHandler('scrollToRow') - } - - render() { - return ( - - {({ width }) => ( - - )} - - ) - } - - _cellRenderer({ columnIndex, key, rowIndex, style }) { - return ( -
- {columnIndex}, {rowIndex} -
- ) - } - - _createEventHandler(property) { - return (event) => { - const value = parseInt(event.target.value, 10) || 0 - - this.setState({ - [property]: value - }) - } - } - - _createLabeledInput(property, eventHandler) { - const value = this.state[property] - - return ( - `` - ) - } -} - -import { ScrollSync } from 'react-virtualized' - -const LEFT_COLOR_FROM = hexToRgb('#471061') -const LEFT_COLOR_TO = hexToRgb('#BC3959') -const TOP_COLOR_FROM = hexToRgb('#000000') -const TOP_COLOR_TO = hexToRgb('#333333') - -function scrollbarSize() { return 42; } -export class GridExample3 extends PureComponent { - state - constructor(props, context) { - super(props, context) - - this.state = { - columnWidth: 75, - columnCount: 50, - height: 300, - overscanColumnCount: 0, - overscanRowCount: 5, - rowHeight: 40, - rowCount: 100 - } - - this._renderBodyCell = this._renderBodyCell.bind(this) - this._renderHeaderCell = this._renderHeaderCell.bind(this) - this._renderLeftSideCell = this._renderLeftSideCell.bind(this) - } - - render() { - const { - columnCount, - columnWidth, - height, - overscanColumnCount, - overscanRowCount, - rowHeight, - rowCount - } = this.state - - return ( - - - {({ clientHeight, clientWidth, onScroll, scrollHeight, scrollLeft, scrollTop, scrollWidth }) => { - const x = scrollLeft / (scrollWidth - clientWidth) - const y = scrollTop / (scrollHeight - clientHeight) - - const leftBackgroundColor = mixColors(LEFT_COLOR_FROM, LEFT_COLOR_TO, y) - const leftColor = '#ffffff' - const topBackgroundColor = mixColors(TOP_COLOR_FROM, TOP_COLOR_TO, x) - const topColor = '#ffffff' - const middleBackgroundColor = mixColors(leftBackgroundColor, topBackgroundColor, 0.5) - const middleColor = '#ffffff' - - return ( -
-
- -
-
- -
-
- - {({ width }) => ( -
-
- -
-
- -
-
- )} -
-
-
- ) - }} -
- ) - } - - _renderBodyCell({ columnIndex, key, rowIndex, style }) { - if (columnIndex < 1) { - return - } - - return this._renderLeftSideCell({ columnIndex, key, rowIndex, style }) - } - - _renderHeaderCell({ columnIndex, key, rowIndex, style }) { - if (columnIndex < 1) { - return - } - - return this._renderLeftHeaderCell({ columnIndex, key, rowIndex, style }) - } - - _renderLeftHeaderCell({ columnIndex, key, rowIndex, style }) { - return ( -
- {`C${columnIndex}`} -
- ) - } - - _renderLeftSideCell({ columnIndex, key, rowIndex, style }) { - return ( -
- {`R${rowIndex}, C${columnIndex}`} -
- ) - } -} - -function hexToRgb(hex) { - const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex) - return result ? { - r: parseInt(result[1], 16), - g: parseInt(result[2], 16), - b: parseInt(result[3], 16) - } : null -} - -/** - * Ported from sass implementation in C - * https://github.com/sass/libsass/blob/0e6b4a2850092356aa3ece07c6b249f0221caced/functions.cpp#L209 - */ -function mixColors(color1, color2, amount) { - const weight1 = amount - const weight2 = 1 - amount - - const r = Math.round(weight1 * color1.r + weight2 * color2.r) - const g = Math.round(weight1 * color1.g + weight2 * color2.g) - const b = Math.round(weight1 * color1.b + weight2 * color2.b) - - return { r, g, b } -} - -import { Column, Table, SortDirection, SortIndicator } from 'react-virtualized' - -export class TableExample extends PureComponent { - state; - context; - constructor(props, context) { - super(props, context) - - this.state = { - disableHeader: false, - headerHeight: 30, - height: 270, - hideIndexRow: false, - overscanRowCount: 10, - rowHeight: 40, - rowCount: 1000, - scrollToIndex: undefined, - sortBy: 'index', - sortDirection: SortDirection.ASC, - useDynamicRowHeight: false - } - - this._getRowHeight = this._getRowHeight.bind(this) - this._headerRenderer = this._headerRenderer.bind(this) - this._noRowsRenderer = this._noRowsRenderer.bind(this) - this._onRowCountChange = this._onRowCountChange.bind(this) - this._onScrollToRowChange = this._onScrollToRowChange.bind(this) - this._rowClassName = this._rowClassName.bind(this) - this._sort = this._sort.bind(this) - } - - render() { - const { - disableHeader, - headerHeight, - height, - hideIndexRow, - overscanRowCount, - rowHeight, - rowCount, - scrollToIndex, - sortBy, - sortDirection, - useDynamicRowHeight - } = this.state - - const { list } = this.context - const sortedList = this._isSortEnabled() - ? list - .sortBy(item => item[sortBy]) - .update(list => - sortDirection === SortDirection.DESC - ? list.reverse() - : list - ) - : list - - const rowGetter = ({ index }) => this._getDatum(sortedList, index) - - return ( -
- - {({ width }) => ( - - {!hideIndexRow && - rowData.index - } - dataKey='index' - disableSort={!this._isSortEnabled()} - width={60} - /> - } - - cellData - } - flexGrow={1} - /> -
- )} -
-
- ) - } - - _getDatum(list, index) { - return list.get(index % list.size) - } - - _getRowHeight({ index }) { - const { list } = this.context - - return this._getDatum(list, index).size - } - - _headerRenderer({ - columnData, - dataKey, - disableSort, - label, - sortBy, - sortDirection - }) { - return ( -
- Full Name - {sortBy === dataKey && - - } -
- ) - } - - _isSortEnabled() { - const { list } = this.context - const { rowCount } = this.state - - return rowCount <= list.size - } - - _noRowsRenderer() { - return ( -
- No rows -
- ) - } - - _onRowCountChange(event) { - const rowCount = parseInt(event.target.value, 10) || 0 - - this.setState({ rowCount }) - } - - _onScrollToRowChange(event) { - const { rowCount } = this.state - let scrollToIndex = Math.min(rowCount - 1, parseInt(event.target.value, 10)) - - if (isNaN(scrollToIndex)) { - scrollToIndex = undefined - } - - this.setState({ scrollToIndex }) - } - - _rowClassName({ index }) { - if (index < 0) { - return 'styles.headerRow' - } else { - return index % 2 === 0 ? 'styles.evenRow' : 'styles.oddRow' - } - } - - _sort({ sortBy, sortDirection }) { - this.setState({ sortBy, sortDirection }) - } - - _updateUseDynamicRowHeight(value) { - this.setState({ - useDynamicRowHeight: value - }) - } -} - -export class WindowScrollerExample extends PureComponent { - state; - context; - _windowScroller: WindowScroller; - - constructor(props) { - super(props) - - this.state = { - showHeaderText: true - } - - this._hideHeader = this._hideHeader.bind(this) - this._rowRenderer = this._rowRenderer.bind(this) - this._onCheckboxChange = this._onCheckboxChange.bind(this) - this._setRef = this._setRef.bind(this) - } - - render() { - const { list, isScrollingCustomElement, customElement } = this.context - const { showHeaderText } = this.state - - return ( - -
- - {({ height, isScrolling, scrollTop }) => ( - - {({ width }) => ( - this._rowRenderer({ index, isScrolling, isVisible, key, style })} - scrollTop={scrollTop} - width={width} - /> - )} - - )} - -
- ) - } - - _hideHeader() { - const { showHeaderText } = this.state - - this.setState({ - showHeaderText: !showHeaderText - }, () => { - this._windowScroller.updatePosition() - }) - } - - _rowRenderer({ index, isScrolling, isVisible, key, style }) { - const { list } = this.context - const row = list.get(index) - - return ( -
- {row.name} -
- ) - } - - _setRef(windowScroller) { - this._windowScroller = windowScroller - } - - _onCheckboxChange(event) { - this.context.setScrollingCustomElement(event.target.checked) - } -} diff --git a/types/response-time/response-time-tests.ts b/types/response-time/response-time-tests.ts index b6a9b4a2af..9b75aa2fec 100644 --- a/types/response-time/response-time-tests.ts +++ b/types/response-time/response-time-tests.ts @@ -5,7 +5,7 @@ import responseTime = require('response-time'); // expressconnect tests https://github.com/expressjs/response-time#expressconnect // //////////////////////////////////////////////////////////////////////////////////// import express = require('express') -namespace express_connect_tests { +{ const app = express() app.use(responseTime()) } @@ -15,7 +15,7 @@ namespace express_connect_tests { // vanilla http server tests https://github.com/expressjs/response-time#vanilla-http-server // ////////////////////////////////////////////////////////////////////////////////////////////// import http = require('http') -namespace vanilla_http_server_tests { +{ // create "middleware" var _responseTime = responseTime() http.createServer(function (req, res) { @@ -33,7 +33,7 @@ namespace vanilla_http_server_tests { ////////////////////////////////////////////////////////////////////////////////////////////////// // response time metrics tests https://github.com/expressjs/response-time#response-time-metrics // ////////////////////////////////////////////////////////////////////////////////////////////////// -namespace response_time_metrics_tests { +{ const app = express() app.use(responseTime(function (req, res, time) { let num: number = time; diff --git a/types/sigmajs/sigmajs-tests.ts b/types/sigmajs/sigmajs-tests.ts index a29ae0773c..7b305c1577 100644 --- a/types/sigmajs/sigmajs-tests.ts +++ b/types/sigmajs/sigmajs-tests.ts @@ -1,84 +1,82 @@ -namespace SigmaJsTests { - var container = document.createElement("sigma"); - var s = new sigma({ - settings: { - autoResize: true, - autoRescale: true - } - }); - - s.settings({ - maxNodeSize: 10 - }); - - s.settings("maxNodeSize"); - - s.addRenderer({ - type: 'canvas', - container: container - }); - - s.bind('clickNode', (e) => { - s.refresh(); - }); - - sigma.canvas.edges['def'] = function() {}; - sigma.svg.nodes['def'] = {create: (obj: SigmaJs.Node) => { return new Element(); }, - update: (obj: SigmaJs.Node) => { return; }}; - sigma.svg.edges['def'] = {create: (obj: SigmaJs.Edge) => { return new Element(); }, - update: (obj: SigmaJs.Edge) => { return; }}; - sigma.svg.edges.labels['def'] = {create: (obj: SigmaJs.Edge) => { return new Element(); }, - update: (obj: SigmaJs.Edge) => { return; }}; - - var N = 100; - var E = 500; - // Generate a random graph: - for (var i = 0; i < N; i++) { - s.graph.addNode({ - id: 'n' + i, - label: 'Node ' + i, - x: Math.random(), - y: Math.random(), - size: Math.random(), - color: '#666' - }); +var container = document.createElement("sigma"); +var s = new sigma({ + settings: { + autoResize: true, + autoRescale: true } +}); - for (var j = 0; j < E; j++) { - s.graph.addEdge({ - id: 'e' + j, - source: 'n' + Math.floor(Math.random() * N), - target: 'n' + Math.floor(Math.random() * N), - size: Math.random(), - color: '#ccc' - }); - } +s.settings({ + maxNodeSize: 10 +}); - sigma.plugins.dragNodes(s, s.renderers[0]); - s.renderers[0].resize(); +s.settings("maxNodeSize"); + +s.addRenderer({ + type: 'canvas', + container: container +}); + +s.bind('clickNode', (e) => { s.refresh(); +}); - sigma.parsers.json('myGraph.json', s, () => { - s.refresh(); - }); +sigma.canvas.edges['def'] = function() {}; +sigma.svg.nodes['def'] = {create: (obj: SigmaJs.Node) => { return new Element(); }, + update: (obj: SigmaJs.Node) => { return; }}; +sigma.svg.edges['def'] = {create: (obj: SigmaJs.Edge) => { return new Element(); }, + update: (obj: SigmaJs.Edge) => { return; }}; +sigma.svg.edges.labels['def'] = {create: (obj: SigmaJs.Edge) => { return new Element(); }, + update: (obj: SigmaJs.Edge) => { return; }}; - sigma.parsers.gexf('myGraph.gexf', s, () => { - s.refresh(); - }); - - s.configForceAtlas2({ - worker: true - }); - - s.isForceAtlas2Running(); - s.killForceAtlas2(); - s.startForceAtlas2(); - s.stopForceAtlas2(); - - s.cameras[0].goTo({ - angle: 0, - x: 100, - y: 100, - ratio: 1 +var N = 100; +var E = 500; +// Generate a random graph: +for (var i = 0; i < N; i++) { + s.graph.addNode({ + id: 'n' + i, + label: 'Node ' + i, + x: Math.random(), + y: Math.random(), + size: Math.random(), + color: '#666' }); } + +for (var j = 0; j < E; j++) { + s.graph.addEdge({ + id: 'e' + j, + source: 'n' + Math.floor(Math.random() * N), + target: 'n' + Math.floor(Math.random() * N), + size: Math.random(), + color: '#ccc' + }); +} + +sigma.plugins.dragNodes(s, s.renderers[0]); +s.renderers[0].resize(); +s.refresh(); + +sigma.parsers.json('myGraph.json', s, () => { + s.refresh(); +}); + +sigma.parsers.gexf('myGraph.gexf', s, () => { + s.refresh(); +}); + +s.configForceAtlas2({ + worker: true +}); + +s.isForceAtlas2Running(); +s.killForceAtlas2(); +s.startForceAtlas2(); +s.stopForceAtlas2(); + +s.cameras[0].goTo({ + angle: 0, + x: 100, + y: 100, + ratio: 1 +}); diff --git a/types/string-template/string-template-tests.ts b/types/string-template/string-template-tests.ts index 90e852e2f1..8ac76014c1 100644 --- a/types/string-template/string-template-tests.ts +++ b/types/string-template/string-template-tests.ts @@ -1,8 +1,8 @@ import * as format from "string-template"; import * as compile from "string-template/compile"; - -namespace format_tests { +// Format tests +{ let greeting: string; // Format using an object hash with keys matching [0-9a-zA-Z]+ @@ -23,8 +23,8 @@ namespace format_tests { } -namespace compile_tests { - +// Compile tests +{ { let greetingTemplate = compile("Hello {0}, you have {1} unread messages", true) // -> greetingTemplate generated using new Function diff --git a/types/synaptic/synaptic-tests.ts b/types/synaptic/synaptic-tests.ts index 8c06985d63..58fc6735d2 100644 --- a/types/synaptic/synaptic-tests.ts +++ b/types/synaptic/synaptic-tests.ts @@ -1,136 +1,145 @@ // Neurons // ======= -namespace NeuronTests { +{ // project - // ------- - var A = new Neuron(); - var B = new Neuron(); - A.project(B); // A now projects a connection to B - A.project(A); // Neurons can also self-connect - - // gate - // ---- - var A = new Neuron(); - var B = new Neuron(); - var connection = A.project(B); - - var C = new Neuron(); - C.gate(connection); // now C gates the connection between A and B - - // activate - // -------- - var A = new Neuron(); - var B = new Neuron(); - A.project(B); - - A.activate(0.5); // 0.5 - B.activate(); // 0.3244554645 - - // propagate - // --------- - var A = new Neuron(); - var B = new Neuron(); - A.project(B); - - var learningRate = .3; - - for (var i = 0; i < 20000; i++) { - // when A activates 1 - A.activate(1); - - // train B to activate 0 - B.activate(); - B.propagate(learningRate, 0); + { + const A = new Neuron(); + const B = new Neuron(); + A.project(B); // A now projects a connection to B + A.project(A); // Neurons can also self-connect } - // test it - A.activate(1); - B.activate(); // 0.006540565760853365 + // gate + { + const A = new Neuron(); + const B = new Neuron(); + const connection = A.project(B); - // squashing function and bias - var A = new Neuron(); - A.squash = Neuron.squash.TANH; - A.bias = 1; + const C = new Neuron(); + C.gate(connection); // now C gates the connection between A and B + } + + // activate + { + const A = new Neuron(); + const B = new Neuron(); + A.project(B); + + A.activate(0.5); // 0.5 + B.activate(); // 0.3244554645 + } + + // propagate + { + const A = new Neuron(); + const B = new Neuron(); + A.project(B); + + const learningRate = .3; + + for (let i = 0; i < 20000; i++) { + // when A activates 1 + A.activate(1); + + // train B to activate 0 + B.activate(); + B.propagate(learningRate, 0); + } + + // test it + A.activate(1); + B.activate(); // 0.006540565760853365 + } + + { + // squashing function and bias + const A = new Neuron(); + A.squash = Neuron.squash.TANH; + A.bias = 1; + } } // Layers // ====== -namespace LayerTests { +{ // project - // ------- - var A = new Layer(5); - var B = new Layer(3); - A.project(B, Layer.connectionType.ALL_TO_ALL); // All the neurons in layer A now project a connection to all the neurons in layer B - A.project(A, Layer.connectionType.ONE_TO_ONE); - - // gate - // ---- - var A = new Layer(5); - var B = new Layer(3); - var connection = A.project(B); - - var C = new Layer(4); - C.gate(connection, Layer.gateType.INPUT); // now C gates the connection between A and B (input gate) - - // activate - // -------- - var A = new Layer(5); - var B = new Layer(3); - A.project(B); - - A.activate([1, 0, 1, 0, 1]); // [1,0,1,0,1] - B.activate(); // [0.3280457, 0.83243247, 0.5320423] - - // propagate - // --------- - var A = new Layer(5); - var B = new Layer(2); - A.project(B); - - var learningRate = .3; - - for (var i = 0; i < 20000; i++) { - // when A activates [1, 0, 1, 0, 1] - A.activate([1, 0, 1, 0, 1]); - - // train B to activate [0,0] - B.activate(); - B.propagate(learningRate, [0, 0]); + { + const A = new Layer(5); + const B = new Layer(3); + A.project(B, Layer.connectionType.ALL_TO_ALL); // All the neurons in layer A now project a connection to all the neurons in layer B + A.project(A, Layer.connectionType.ONE_TO_ONE); } - // test it - A.activate([1, 0, 1, 0, 1]); - B.activate(); // [0.004606949693864496, 0.004606763721459169] + // gate + { + const A = new Layer(5); + const B = new Layer(3); + const connection = A.project(B); - // squashing function and bias - A.set({ - squash: Neuron.squash.TANH, - bias: 0 - }) + const C = new Layer(4); + C.gate(connection, Layer.gateType.INPUT); // now C gates the connection between A and B (input gate) + } - // neurons - // ------- - A.neurons(); + // activate + { + const A = new Layer(5); + const B = new Layer(3); + A.project(B); + + A.activate([1, 0, 1, 0, 1]); // [1,0,1,0,1] + B.activate(); // [0.3280457, 0.83243247, 0.5320423] + } + + // propagate + { + const A = new Layer(5); + const B = new Layer(2); + A.project(B); + + const learningRate = .3; + + for (let i = 0; i < 20000; i++) { + // when A activates [1, 0, 1, 0, 1] + A.activate([1, 0, 1, 0, 1]); + + // train B to activate [0,0] + B.activate(); + B.propagate(learningRate, [0, 0]); + } + + // test it + A.activate([1, 0, 1, 0, 1]); + B.activate(); // [0.004606949693864496, 0.004606763721459169] + + // squashing function and bias + A.set({ + squash: Neuron.squash.TANH, + bias: 0 + }) + + // neurons + // ------- + A.neurons(); + } } // Networks // ======== - -namespace NetworkTests { - var inputLayer = new Layer(4); - var hiddenLayer = new Layer(6); - var outputLayer = new Layer(2); +{ + let inputLayer = new Layer(4); + let hiddenLayer = new Layer(6); + let outputLayer = new Layer(2); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var A = new Network({ + const A = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer }); - var B = new Network({ + const B = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer @@ -143,24 +152,24 @@ namespace NetworkTests { // gate // ---- - var C = new Network({ + const C = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer }); - var connection = A.project(B); + const connection = A.project(B); C.gate(connection, Layer.gateType.INPUT); // now C's output layer gates the connection between A's output layer and B's input layer (input gate) // activate // -------- - var inputLayer = new Layer(4); - var hiddenLayer = new Layer(6); - var outputLayer = new Layer(2); + inputLayer = new Layer(4); + hiddenLayer = new Layer(6); + outputLayer = new Layer(2); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var myNetwork = new Network({ + let myNetwork = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer @@ -171,22 +180,22 @@ namespace NetworkTests { // propagate // --------- // create the network - var inputLayer = new Layer(2); - var hiddenLayer = new Layer(3); - var outputLayer = new Layer(1); + inputLayer = new Layer(2); + hiddenLayer = new Layer(3); + outputLayer = new Layer(1); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var myNetwork = new Network({ + myNetwork = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer }); // train the network - var learningRate = .3; - for (var i = 0; i < 20000; i++) { + let learningRate = .3; + for (let i = 0; i < 20000; i++) { // 0,0 => 0 myNetwork.activate([0, 0]); myNetwork.propagate(learningRate, [0]); @@ -218,14 +227,14 @@ namespace NetworkTests { // toJSON/fromJSON // --------------- - var exported = myNetwork.toJSON(); - var imported = Network.fromJSON(exported); + const exported = myNetwork.toJSON(); + const imported = Network.fromJSON(exported); // worker // ------ // training set - var learningRate = .3; - var trainingSet = [ + learningRate = .3; + const trainingSet = [ { input: [0, 0], output: [0] @@ -245,21 +254,21 @@ namespace NetworkTests { ]; // create a network - var inputLayer = new Layer(2); - var hiddenLayer = new Layer(3); - var outputLayer = new Layer(1); + inputLayer = new Layer(2); + hiddenLayer = new Layer(3); + outputLayer = new Layer(1); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var myNetwork = new Network({ + myNetwork = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer }); // create a worker - var myWorker = myNetwork.worker(); + const myWorker = myNetwork.worker(); // activate the network function activateWorker(input: number[]) { @@ -290,10 +299,10 @@ namespace NetworkTests { index = 0; iterations++; if (iterations % 100 == 0) { - var output00 = myNetwork.activate([0, 0]); - var output01 = myNetwork.activate([0, 1]); - var output10 = myNetwork.activate([1, 0]); - var output11 = myNetwork.activate([1, 1]); + const output00 = myNetwork.activate([0, 0]); + const output01 = myNetwork.activate([0, 1]); + const output10 = myNetwork.activate([1, 0]); + const output11 = myNetwork.activate([1, 1]); console.log("0,0 => ", output00); console.log("0,1 => ", output01); @@ -312,46 +321,46 @@ namespace NetworkTests { } // kick it - var index = 0; - var iterations = 0; + let index = 0; + let iterations = 0; activateWorker(trainingSet[index].input); // standalone // ---------- - var inputLayer = new Layer(4); - var hiddenLayer = new Layer(6); - var outputLayer = new Layer(2); + inputLayer = new Layer(4); + hiddenLayer = new Layer(6); + outputLayer = new Layer(2); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var myNetwork = new Network({ + myNetwork = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer }); - var standalone = myNetwork.standalone(); + const standalone = myNetwork.standalone(); myNetwork.activate([1, 0, 1, 0]); // [0.5466397925108878, 0.5121246668637663] standalone([1, 0, 1, 0]); // [0.5466397925108878, 0.5121246668637663] // clone // ----- - var inputLayer = new Layer(4); - var hiddenLayer = new Layer(6); - var outputLayer = new Layer(2); + inputLayer = new Layer(4); + hiddenLayer = new Layer(6); + outputLayer = new Layer(2); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var myNetwork = new Network({ + myNetwork = new Network({ input: inputLayer, hidden: [hiddenLayer], output: outputLayer }); - var clone = myNetwork.clone(); + const clone = myNetwork.clone(); myNetwork.activate([1, 0, 1, 0]); // [0.5466397925108878, 0.5121246668637663] clone.activate([1, 0, 1, 0]); // [0.5466397925108878, 0.5121246668637663] @@ -362,14 +371,14 @@ namespace NetworkTests { // set // --- - var inputLayer = new Layer(4); - var hiddenLayer = new Layer(6); - var outputLayer = new Layer(2); + inputLayer = new Layer(4); + hiddenLayer = new Layer(6); + outputLayer = new Layer(2); inputLayer.project(hiddenLayer); hiddenLayer.project(outputLayer); - var myNetwork = new Network(); + myNetwork = new Network(); myNetwork.set({ input: inputLayer, @@ -380,28 +389,28 @@ namespace NetworkTests { // Architect // ========= -namespace ArchitectTests { +{ // Perceptron // ---------- - var myPerceptron = new Architect.Perceptron(2, 3, 1); + const myPerceptron = new Architect.Perceptron(2, 3, 1); // LSTM // ---- - var myLSTM = new Architect.LSTM(2, 6, 1); + const myLSTM = new Architect.LSTM(2, 6, 1); // Liquid // ------ - var input = 2; - var pool = 20; - var output = 1; - var connections = 30; - var gates = 10; + const input = 2; + const pool = 20; + const output = 1; + const connections = 30; + const gates = 10; - var myLiquidStateMachine = new Architect.Liquid(input, pool, output, connections, gates); + const myLiquidStateMachine = new Architect.Liquid(input, pool, output, connections, gates); // Hopfield // -------- - var hopfield = new Architect.Hopfield(10) // create a network for 10-bit patterns + const hopfield = new Architect.Hopfield(10) // create a network for 10-bit patterns // teach the network two different patterns hopfield.learn([ @@ -416,13 +425,13 @@ namespace ArchitectTests { // Trainer // ======= -namespace TrainerTests { +{ // train // ----- - var myNetwork = new Architect.Perceptron(2, 2, 1) - var trainer = new Trainer(myNetwork) + let myNetwork = new Architect.Perceptron(2, 2, 1) + let trainer = new Trainer(myNetwork) - var trainingSet = [ + let trainingSet = [ { input: [0, 0], output: [0] @@ -443,7 +452,7 @@ namespace TrainerTests { trainer.train(trainingSet); - var traningOptions = { + const traningOptions = { rate: .1, iterations: 20000, error: .005, @@ -465,14 +474,14 @@ namespace TrainerTests { // trainAsync // ---------- - var trainer = new Trainer(myNetwork); + trainer = new Trainer(myNetwork); trainer.trainAsync(trainingSet, traningOptions) .then((results: any) => console.log('done!', results)) - var myNetwork = new Architect.Perceptron(2, 2, 1) - var trainer = new Trainer(myNetwork) + myNetwork = new Architect.Perceptron(2, 2, 1) + trainer = new Trainer(myNetwork) - var trainingSet = [ + trainingSet = [ { input: [0, 0], output: [0] @@ -499,7 +508,7 @@ namespace TrainerTests { // XOR // --- - var trainer = new Trainer(myNetwork); + trainer = new Trainer(myNetwork); trainer.XOR(); // {error: 0.004999821588193305, iterations: 21333, time: 111} // DSR diff --git a/types/validator/validator-tests.ts b/types/validator/validator-tests.ts index 48621f1acd..71661b48ff 100644 --- a/types/validator/validator-tests.ts +++ b/types/validator/validator-tests.ts @@ -66,7 +66,7 @@ import trimFunc = require('validator/lib/trim'); import unescapeFunc = require('validator/lib/unescape'); import whitelistFunc = require('validator/lib/whitelist'); -namespace import_tests { +{ let _blacklist = validator.blacklist; _blacklist = blacklistFunc;