本文整理汇总了TypeScript中utils/types.isString函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isString函数的具体用法?TypeScript isString怎么用?TypeScript isString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isString函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Promise
return new Promise((resolve, reject) => {
try {
let MediaPlayer = android.media.MediaPlayer;
let audioPath;
let fileName = isString(options.audioFile) ? options.audioFile.trim() : "";
if (fileName.indexOf("~/") === 0) {
fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
console.log('fileName: ' + fileName);
audioPath = fileName;
}
this.player = new MediaPlayer();
this.player.setAudioStreamType(android.media.AudioManager.STREAM_MUSIC);
this.player.setDataSource(audioPath);
this.player.prepareAsync();
// On Complete
this.player.setOnCompletionListener(new MediaPlayer.OnCompletionListener({
onCompletion: (mp) => {
options.completeCallback();
}
}));
// On Error
this.player.setOnErrorListener(new MediaPlayer.OnErrorListener({
onError: (mp: any, what: number, extra: number) => {
options.errorCallback();
}
}));
// On Info
this.player.setOnInfoListener(new MediaPlayer.OnInfoListener({
onInfo: (mp: any, what: number, extra: number) => {
options.infoCallback();
}
}))
// On Prepared
this.player.setOnPreparedListener(new MediaPlayer.OnPreparedListener({
onPrepared: (mp) => {
mp.start();
resolve();
}
}));
} catch (ex) {
reject(ex);
}
});
示例2: validateArgs
function validateArgs(source: observable.Observable, eventName: string, handler: (eventData: observable.EventData) => void, target: any) {
if (types.isNullOrUndefined(source)) {
throw new Error("source is null or undefined");
}
if (types.isNullOrUndefined(target)) {
throw new Error("target is null or undefined");
}
if (!types.isString(eventName)) {
throw new Error("eventName is not a string");
}
if (!types.isFunction(handler)) {
throw new Error("handler is not a function");
}
}
示例3: Error
return new Promise<http.HttpResponse>((resolve, reject) => {
try {
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration();
var queue = NSOperationQueue.mainQueue();
var session = NSURLSession.sessionWithConfigurationDelegateDelegateQueue(
sessionConfig, null, queue);
var urlRequest = NSMutableURLRequest.requestWithURL(
NSURL.URLWithString(options.url));
urlRequest.HTTPMethod = types.isDefined(options.method) ? options.method : GET;
urlRequest.setValueForHTTPHeaderField(USER_AGENT, USER_AGENT_HEADER);
if (options.headers) {
for (var header in options.headers) {
urlRequest.setValueForHTTPHeaderField(options.headers[header] + "", header);
}
}
if (types.isString(options.content) || options.content instanceof FormData) {
urlRequest.HTTPBody = NSString.alloc().initWithString(options.content.toString()).dataUsingEncoding(4);
}
if (types.isNumber(options.timeout)) {
urlRequest.timeoutInterval = options.timeout / 1000;
}
var dataTask = session.dataTaskWithRequestCompletionHandler(urlRequest,
function (data: NSData, response: NSHTTPURLResponse, error: NSError) {
if (error) {
reject(new Error(error.localizedDescription));
} else {
var headers = {};
if (response && response.allHeaderFields) {
var headerFields = response.allHeaderFields;
var keys = headerFields.allKeys;
for (var i = 0, l = keys.count; i < l; i++) {
var key = keys.objectAtIndex(i);
headers[key] = headerFields.valueForKey(key);
}
}
resolve({
content: {
raw: data,
toString: () => { return NSDataToString(data); },
toJSON: () => {
ensureUtils();
return utils.parseJSON(NSDataToString(data));
},
toImage: () => {
ensureImageSource();
if (UIImage.imageWithData["async"]) {
return UIImage.imageWithData["async"](UIImage, [data])
.then(image => {
if (!image) {
throw new Error("Response content may not be converted to an Image");
}
var source = new imageSource.ImageSource();
source.setNativeSource(image);
return source;
});
}
return new Promise<any>((resolveImage, rejectImage) => {
var img = imageSource.fromData(data);
if (img instanceof imageSource.ImageSource) {
resolveImage(img);
} else {
rejectImage(new Error("Response content may not be converted to an Image"));
}
});
},
toFile: (destinationFilePath?: string) => {
var fs: typeof fsModule = require("file-system");
var fileName = options.url;
if (!destinationFilePath) {
destinationFilePath = fs.path.join(fs.knownFolders.documents().path, fileName.substring(fileName.lastIndexOf('/') + 1));
}
if (data instanceof NSData) {
data.writeToFileAtomically(destinationFilePath, true);
return fs.File.fromPath(destinationFilePath);
} else {
reject(new Error(`Cannot save file with path: ${destinationFilePath}.`));
}
}
},
statusCode: response.statusCode,
headers: headers
});
}
});
dataTask.resume();
} catch (ex) {
//.........这里部分代码省略.........