mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
Default properties; pseudo-nominal types; fixes after test run
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Note -- running these tests under cscript requires some ES5 polyfills
|
||||
|
||||
const collectionToArray = <T>(col: { Item(key: any): T }): T[] => {
|
||||
const results: T[] = [];
|
||||
const enumerator = new Enumerator<T>(col);
|
||||
@@ -12,7 +14,7 @@ const collectionToArray = <T>(col: { Item(key: any): T }): T[] => {
|
||||
const fso = new ActiveXObject('Scripting.FileSystemObject');
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/ebkhfaaz(v=vs.84).aspx
|
||||
(() => {
|
||||
{
|
||||
/** Generates a string describing the drive type of a given Drive object. */
|
||||
const driveTypeString = (drive: Scripting.Drive) => {
|
||||
switch (drive.DriveType) {
|
||||
@@ -133,14 +135,13 @@ ${subfolders.map(folderContentsString).join('')}`
|
||||
|
||||
const deleteTestFolder = () => {
|
||||
// two ways to delete a file:
|
||||
const filepathToDelete = `${testPath}\\LoremIpsum\Paragraph1.txt`;
|
||||
const filepathToDelete = `${testPath}\\LoremIpsum\\Paragraph1.txt`;
|
||||
fso.DeleteFile(filepathToDelete);
|
||||
fso.GetFile(filepathToDelete).Delete();
|
||||
// fso.GetFile(filepathToDelete).Delete();
|
||||
|
||||
// two ways to delete a folder:
|
||||
const folderpathToDelete = `${testPath}\\LoremIpsum`;
|
||||
fso.DeleteFolder(folderpathToDelete);
|
||||
fso.GetFolder(folderpathToDelete).Delete();
|
||||
fso.DeleteFolder(`${testPath}\\LoremIpsum`);
|
||||
fso.GetFolder(testPath).Delete();
|
||||
};
|
||||
|
||||
const createLyrics = (folder: Scripting.Folder) => {
|
||||
@@ -201,41 +202,44 @@ ${subfolders.map(folderContentsString).join('')}`
|
||||
|
||||
if (!buildTestFolder()) {
|
||||
WScript.Echo('Test directory already exists or cannot be created. Cannot continue.');
|
||||
return;
|
||||
} else {
|
||||
WScript.Echo(drivesInfoReport());
|
||||
echoLines(2);
|
||||
WScript.Echo(testfolderInfo());
|
||||
echoLines(2);
|
||||
WScript.Echo(getLyrics());
|
||||
echoLines(2);
|
||||
deleteTestFolder();
|
||||
}
|
||||
|
||||
WScript.Echo(drivesInfoReport);
|
||||
echoLines(2);
|
||||
WScript.Echo(testfolderInfo);
|
||||
echoLines(2);
|
||||
WScript.Echo(getLyrics());
|
||||
echoLines(2);
|
||||
deleteTestFolder();
|
||||
})();
|
||||
}
|
||||
|
||||
// source --https://msdn.microsoft.com/en-us/library/ts2t8ybh(v=vs.84).aspx
|
||||
const showFreeSpace = (drvPath: string) => {
|
||||
const d = fso.GetDrive(fso.GetDriveName(drvPath));
|
||||
let s = `Drive ${drvPath} - `;
|
||||
s += d.VolumeName + '<br>';
|
||||
s += `Free Space: ${d.FreeSpace / 1024} Kbytes`;
|
||||
return (s);
|
||||
};
|
||||
{
|
||||
const showFreeSpace = (drvPath: string) => {
|
||||
const d = fso.GetDrive(fso.GetDriveName(drvPath));
|
||||
let s = `Drive ${drvPath} - `;
|
||||
s += d.VolumeName + '<br>';
|
||||
s += `Free Space: ${d.FreeSpace / 1024} Kbytes`;
|
||||
return (s);
|
||||
};
|
||||
}
|
||||
|
||||
// source -- https://msdn.microsoft.com/en-us/library/kaf6yaft(v=vs.84).aspx
|
||||
const getALine = (filespec: string) => {
|
||||
const file = fso.OpenTextFile(filespec, Scripting.IOMode.ForReading, false);
|
||||
{
|
||||
const getALine = (filespec: string) => {
|
||||
const file = fso.OpenTextFile(filespec, Scripting.IOMode.ForReading, false);
|
||||
|
||||
let s = '';
|
||||
while (!file.AtEndOfLine) {
|
||||
s += file.Read(1);
|
||||
}
|
||||
file.Close();
|
||||
return (s);
|
||||
};
|
||||
let s = '';
|
||||
while (!file.AtEndOfLine) {
|
||||
s += file.Read(1);
|
||||
}
|
||||
file.Close();
|
||||
return (s);
|
||||
};
|
||||
}
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/ch28h2s7(v=vs.84).aspx
|
||||
(() => {
|
||||
{
|
||||
const showDriveInfo = (path: string) => {
|
||||
const bytesPerGB = 1024 * 1024 * 1024;
|
||||
const drv = fso.GetDrive(fso.GetDriveName(path));
|
||||
@@ -262,10 +266,10 @@ ${fldr.IsRootFolder ? 'Is root folder' : `Parent folder: ${fldr.ParentFolder}`}
|
||||
|
||||
WScript.Echo(ret);
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/czxefwt8(v=vs.84).aspx
|
||||
(() => {
|
||||
{
|
||||
const readFiles = () => {
|
||||
const file = fso.CreateTextFile("c:\\testfile.txt", true);
|
||||
|
||||
@@ -317,4 +321,4 @@ ${fldr.IsRootFolder ? 'Is root folder' : `Parent folder: ${fldr.ParentFolder}`}
|
||||
file3.Delete();
|
||||
WScript.Echo('All done!');
|
||||
};
|
||||
})();
|
||||
}
|
||||
|
||||
58
types/activex-scripting/index.d.ts
vendored
58
types/activex-scripting/index.d.ts
vendored
@@ -9,7 +9,7 @@ declare namespace Scripting {
|
||||
const enum CompareMethod {
|
||||
BinaryCompare = 0,
|
||||
DatabaseCompare = 2,
|
||||
TextCompare = 1
|
||||
TextCompare = 1,
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-const-enum
|
||||
@@ -19,7 +19,7 @@ declare namespace Scripting {
|
||||
RamDisk = 5,
|
||||
Remote = 3,
|
||||
Removable = 1,
|
||||
UnknownType = 0
|
||||
UnknownType = 0,
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-const-enum
|
||||
@@ -32,28 +32,28 @@ declare namespace Scripting {
|
||||
Normal = 0,
|
||||
ReadOnly = 1,
|
||||
System = 4,
|
||||
Volume = 8
|
||||
Volume = 8,
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-const-enum
|
||||
const enum IOMode {
|
||||
ForAppending = 8,
|
||||
ForReading = 1,
|
||||
ForWriting = 2
|
||||
ForWriting = 2,
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-const-enum
|
||||
const enum SpecialFolderConst {
|
||||
SystemFolder = 1,
|
||||
TemporaryFolder = 2,
|
||||
WindowsFolder = 0
|
||||
WindowsFolder = 0,
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-const-enum
|
||||
const enum StandardStreamTypes {
|
||||
StdErr = 2,
|
||||
StdIn = 0,
|
||||
StdOut = 1
|
||||
StdOut = 1,
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:no-const-enum
|
||||
@@ -61,7 +61,7 @@ declare namespace Scripting {
|
||||
TristateFalse = 0,
|
||||
TristateMixed = -2,
|
||||
TristateTrue = -1,
|
||||
TristateUseDefault = -2
|
||||
TristateUseDefault = -2,
|
||||
}
|
||||
|
||||
/** Scripting.Dictionary */
|
||||
@@ -96,10 +96,16 @@ declare namespace Scripting {
|
||||
|
||||
/** Remove all information from the dictionary. */
|
||||
RemoveAll(): void;
|
||||
|
||||
/** Set or get the item for a given key */
|
||||
(Key: TKey): TItem;
|
||||
}
|
||||
|
||||
/** Drive Object */
|
||||
interface Drive {
|
||||
class Drive {
|
||||
private constructor();
|
||||
private 'Scripting.Drive_typekey': Drive;
|
||||
|
||||
/** Get available space */
|
||||
readonly AvailableSpace: number;
|
||||
|
||||
@@ -144,16 +150,25 @@ declare namespace Scripting {
|
||||
|
||||
/** Get drive using the drive letter (`C`) or path (`C:\\`) */
|
||||
Item(Key: string): Drive;
|
||||
|
||||
/** Get drive using the drive letter (`C`) or path (`C:\\`) */
|
||||
(Key: string): Drive;
|
||||
}
|
||||
|
||||
/** Script Encoder Object */
|
||||
interface Encoder {
|
||||
/** Call the Encoder determined by szExt, passing bstrStreamIn and optional arguments */
|
||||
EncodeScriptFile(szExt: string, bstrStreamIn: string, cFlags: number, bstrDefaultLang: string): string;
|
||||
|
||||
/** Call the Encoder determined by szExt, passing bstrStreamIn and optional arguments */
|
||||
(szExt: string, bstrStreamIn: string, cFlags: number, bstrDefaultLang: string): string;
|
||||
}
|
||||
|
||||
/** File object */
|
||||
interface File {
|
||||
class File {
|
||||
private constructor();
|
||||
private 'Scripting.File_typekey': File;
|
||||
|
||||
/** File attributes */
|
||||
Attributes: FileAttribute;
|
||||
|
||||
@@ -220,10 +235,16 @@ declare namespace Scripting {
|
||||
|
||||
/** Get file object using the name and extension of the file */
|
||||
Item(Key: string): File;
|
||||
|
||||
/** Get file */
|
||||
(Key: string): File;
|
||||
}
|
||||
|
||||
/** FileSystem Object */
|
||||
interface FileSystemObject {
|
||||
class FileSystemObject {
|
||||
private constructor();
|
||||
private 'Scripting.FileSystemObject_typekey': FileSystemObject;
|
||||
|
||||
/** Generate a path from an existing path and a name */
|
||||
BuildPath(Path: string, Name: string): string;
|
||||
|
||||
@@ -331,7 +352,10 @@ declare namespace Scripting {
|
||||
}
|
||||
|
||||
/** Folder object */
|
||||
interface Folder {
|
||||
class Folder {
|
||||
private constructor();
|
||||
private 'Scripting.Folder_typekey': Folder;
|
||||
|
||||
/** Folder attributes */
|
||||
Attributes: FileAttribute;
|
||||
|
||||
@@ -410,10 +434,16 @@ declare namespace Scripting {
|
||||
|
||||
/** Get folder in collection using the folder's name */
|
||||
Item(Key: string): Folder;
|
||||
|
||||
/** Get folder in collection using the folder's name */
|
||||
(Key: string): Folder;
|
||||
}
|
||||
|
||||
/** TextStream object */
|
||||
interface TextStream {
|
||||
class TextStream {
|
||||
private constructor();
|
||||
private 'Scripting.TextStream_typekey': TextStream;
|
||||
|
||||
/** Is the current position at the end of a line? */
|
||||
readonly AtEndOfLine: boolean;
|
||||
|
||||
@@ -459,12 +489,12 @@ declare namespace Scripting {
|
||||
}
|
||||
|
||||
interface ActiveXObject {
|
||||
set(obj: Scripting.Dictionary, propertyName: 'Item', parameterTypes: [any], newValue: any): void;
|
||||
new <K extends keyof ActiveXObjectNameMap = any>(progid: K): ActiveXObjectNameMap[K];
|
||||
set(obj: Scripting.Dictionary, propertyName: 'Item', parameterTypes: [any], newValue: any): void;
|
||||
}
|
||||
|
||||
interface ActiveXObjectNameMap {
|
||||
'Scripting.Dictionary': Scripting.Dictionary;
|
||||
'Scirpting.Encoder': Scripting.Encoder;
|
||||
'Scripting.Encoder': Scripting.Encoder;
|
||||
'Scripting.FileSystemObject': Scripting.FileSystemObject;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user