本文整理汇总了TypeScript中sprintf-js.sprintf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sprintf函数的具体用法?TypeScript sprintf怎么用?TypeScript sprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sprintf函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: uploadFile
export async function uploadFile(file: File, requestConfig: AxiosRequestConfig = {}) {
let allowedExtensions = getMeta("upload.allowedExtensions", []) as string[];
allowedExtensions = allowedExtensions.map((ext: string) => ext.toLowerCase());
const maxSize = getMeta("upload.maxSize", 0);
const filePieces = file.name.split(".");
const extension = filePieces[filePieces.length - 1] || "";
if (file.size > maxSize) {
const humanSize = humanFileSize(maxSize);
const stringTotal: string = humanSize.amount + humanSize.unitAbbr;
const message = sprintf(t("The uploaded file was too big (max %s)."), stringTotal);
throw new Error(message);
} else if (!allowedExtensions.includes(extension.toLowerCase())) {
const attachmentsString = allowedExtensions.join(", ");
const message = sprintf(
t(
"The uploaded file did not have an allowed extension. \nOnly the following extensions are allowed. \n%s.",
),
attachmentsString,
);
throw new Error(message);
}
const data = new FormData();
data.append("file", file, file.name);
const result = await apiv2.post("/media", data, requestConfig);
return result.data;
}
示例2: stringTime
export function stringTime (input) {
let min = Math.floor(input / (1000 * 60));
let sec = Math.floor((input - min * 60 * 1000) / 1000);
let msec = input % 1000;
if(msec) {
if(min > 9) {
return sprintf('%02d:%02d.%03d', min, sec, msec);
} else {
return sprintf('%01d:%02d.%03d', min, sec, msec);
}
}
return sprintf('%02d:%02d', min, sec);
}
示例3: dependencies
fs.readFile(filename, (err, settingsBuffer: Buffer) => {
var info = JSON.parse(settingsBuffer + ''),
dependencyCount,
devDependencyCount;
if (err) {
this.services.log.warn('package.json not present');
} else {
dependencyCount = info.dependencies ? Object.keys(info.dependencies).length : 0;
devDependencyCount = info.devDependencies ? Object.keys(info.devDependencies).length : 0;
if (dependencyCount > 0 || devDependencyCount > 0) {
this.services.log.startSection(sprintf('Installing %d npm dependencies (%d dev)', dependencyCount, devDependencyCount));
} else {
this.services.log.startSection('Installing npm dependencies');
this.services.log.warn('package.json contains neither dependencies nor devDependencies');
}
}
this.services.shell.exec('npm install').then(() => {
this.services.log.closeSection('Node packages installed');
deferred.resolve(true);
}).fail(function (error) {
deferred.reject(error);
});
});
示例4: sprintf
Object.keys(buildConfig[dirsKey][workingKey]).forEach((key) => {
// determine the filename for the zip
let zipFilename = sprintf("%s-%s%s-%s-%s.zip",
buildConfig[packageKey][nameKey], options.version, flag, branch, key);
let zipFilepath = pathJoin(buildConfig[dirsKey][outputKey], zipFilename);
// zip up the files
zip(buildConfig[dirsKey][workingKey][key], zipFilepath, (err) => {
if (err) {
console.log("##vso[task.logissue type=error]Packaging Failed: %s", err);
} else {
console.log("Packaging Successful: %s", zipFilename);
// set a variable as the path to the zip_file, this can then be used in subsequent
// tasks to add the zip to the artefacts
console.log("##vso[task.setvariable variable=%s]%s", options.outputvar, zipFilepath);
// remove the createUIdefinition file from the working dir as this will be uploaded to
// blob storage and the API key should not be visible
let uiDefinitionFile = pathJoin(buildConfig[dirsKey][workingKey][key], "createUiDefinition.json");
if (existsSync(uiDefinitionFile)) {
console.log("Removing UI definition file: ", uiDefinitionFile);
unlinkSync(uiDefinitionFile);
}
}
});
});
示例5: execute
execute(): Q.Promise<boolean> {
var deferred = Q.defer<boolean>(),
filename = sprintf('%s/%s/bower.json', this.services.config.paths.getTemp(), this.services.config.projectName);
fs.readFile(filename, (err, settingsBuffer: Buffer) => {
var info = JSON.parse(settingsBuffer + '');
if (err) {
this.services.log.warn('bower.json not present');
} else {
this.services.log.startSection(sprintf('Installing %d bower dependencies', Object.keys(info.dependencies).length));
}
this.services.shell.exec('bower install').then(
()=> {
this.services.log.closeSection('Bower packages installed');
deferred.resolve(true);
},
(error) => {
deferred.reject(error);
});
});
return deferred.promise;
}
示例6: execute
execute() {
var d = Q.defer(),
filename = sprintf('%s/%s/composer.json', this.services.config.paths.getTemp(), this.services.config.projectName);
fs.readFile(filename, (err, settingsBuffer: Buffer) => {
var info = JSON.parse(settingsBuffer + '');
if (err) {
this.services.log.startSection('Installing composer dependencies');
this.services.log.warn('composer.json not present');
} else {
this.services.log.startSection(sprintf('Installing %d composer dependencies', Object.keys(info.require).length));
}
this.services.shell.exec(this.services.config.globalConfig.composer.command + ' install --optimize-autoloader').then((stdout) => {
this.services.log.closeSection('Composer dependencies installed');
d.resolve(true);
}).fail(function (error) {
d.reject(error);
});
});
return d.promise;
}
示例7: Date
() => {
var end = (new Date()).getTime();
this.serviceContainer.log.closeSection(sprintf(
'It took %ss to deploy "%s" to "%s". :)' + "\n\n",
(0.001 * (end - start)).toFixed(3),
config.projectName,
config.stageName
));
},
示例8: sprintf
articles.forEach((item) => {
var url = sprintf(config['rss']['urlfmt'], { 'id': item['id'] });
feed.item({
'title': item['title'],
'description': item['summary'],
'url': url, 'guid': url,
'author': item['username'],
'date': item['post_date']
});
});
示例9: function
fp.discover().forEach(function (entry)
{
console.log(sprintf("%8d %-8s %-8s %-32s", entry.handle, entry.driver_type, entry.driver, entry.driver_detail));
if (verbose)
{
var reader = promise.promisifyAll(fp.get_reader(entry.handle));
console.log(sprintf("\t Enroll stages: %d", reader.enroll_stages));
console.log(sprintf("\t Supports imaging: %s", reader.supports_imaging));
console.log(sprintf("\t Supports identification: %s", reader.supports_identification));
console.log(sprintf("\t Image height: %d", reader.img_height));
console.log(sprintf("\t Image width: %d", reader.img_width));
reader.start_enrollAsync().then(
function (result)
{
console.log(result);
}
)
.catch(
function (err)
{
console.log("ERR");
console.log(err);
}
)
console.log("DONE");
}
});
示例10: constructor
constructor(currentItem: any) {
super(currentItem);
this.searchPageUrl = ko.observable("");
this.allDocumentsLabel = ko.observable(sprintf.sprintf(i18n.t("allDocumentsLabel"), _spPageContextInfo.webTitle.toLowerCase()));
ko.bindingHandlers.getDocumentsSearchUrl = {
init: () => {
this.searchPageUrl(_spPageContextInfo.siteAbsoluteUrl + "/Pages/" + i18n.t("documentsSearchPageUrl"));
},
};
}