本文整理汇总了TypeScript中lodash.padStart函数的典型用法代码示例。如果您正苦于以下问题:TypeScript padStart函数的具体用法?TypeScript padStart怎么用?TypeScript padStart使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了padStart函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: msToTime
export function msToTime(ms: number) {
if (isNumber(ms)) {
const d = duration(ms);
const h = padStart(d.hours().toString(), 2, "0");
const m = padStart(d.minutes().toString(), 2, "0");
return `${h}:${m}`;
} else {
return "00:01";
}
}
示例2: handler
export async function handler(context: Context) {
const { schemaPath } = await context.getProjectConfig()
if (!schemaPath) {
throw new Error('No `schemaPath` found in GraphQL config file.')
}
const relativeSchemaPath = relative(process.cwd(), schemaPath)
if (!existsSync(schemaPath)) {
console.log(
chalk.yellow("Schema file doesn't exist at ") +
chalk.blue(relativeSchemaPath),
)
return
}
const extensions = {
schemaPath: relativeSchemaPath,
...getSchemaExtensions(schemaPath),
}
const maxLength = _(extensions)
.keys()
.map('length')
.max()
for (let name in extensions) {
const padName = _.padStart(name, maxLength)
console.log(`${padName}\t${chalk.blue(extensions[name])}`)
}
if (Object.keys(extensions).length === 0) {
return
}
}
示例3: create
static create(opts) {
opts = opts || {};
const x = new Notification();
x.version = '1.0.0';
const now = Date.now();
x.createdOn = Math.floor(now / 1000);
x.id = _.padStart(now.toString(), 14, '0') + _.padStart(opts.ticker || 0, 4, '0');
x.type = opts.type || 'general';
x.data = opts.data;
x.walletId = opts.walletId;
x.creatorId = opts.creatorId;
return x;
}
示例4: Promise
return new Promise(resolve => {
const notes = path.resolve(__dirname, `../src/notes/${topic}`)
const note = path.join(notes, `${dateFns.format(date, 'yyyy-MM-dd')}--${padStart(String(count), 2, '0')}`)
fs.access(note, fs.constants.F_OK, async err => {
if (err) return resolve(note)
return resolve(await uniqueNote(topic, date, count + 1))
})
})
示例5: linewrap
const lines = items.map(i => {
let left = i[0]
let right = i[1]
if (!right) {
return left
}
left = `${padStart(left, maxLength)}`
right = linewrap(maxLength + 2, right)
return `${left} ${right}`
})
示例6: runNumber
async function runNumber(scriptNumber: string) {
const prefix = padStart(scriptNumber, 2, '0') + '-';
const script = scripts.find(filename => filename.startsWith(prefix));
if (!script) {
throw new Error('No script found starting with ' + prefix);
}
await bootstrapDatabase();
logger.info(null, '[migrate] Executing migrating script %s...', script);
const migrate = require(resolvePath(scriptFolder, script));
await migrate.up();
}
示例7: padStart
export const DebugTiming = (label?: string) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
const fn = descriptor.value;
label = padStart(label ? label : getMethodName(target, propertyKey), 50);
descriptor.value = function() {
const start = now();
const result = fn.apply(this, arguments);
const delta = now() - start;
log(`${label} ${delta} ms`);
return result;
};
};
示例8: parse
public async parse($: any): Promise<ParserResponseInterface> {
const downloadResponse: ParserResponseInterface = { text: [] };
downloadResponse.links = [];
let items = $('.synopsis .syn-body');
if (items.length === 0) {
items = $('.musicList');
}
const itemsList: any[] = [];
items.each((i, item) => {
itemsList.push(item);
});
let i = 0;
for (const item of itemsList) {
i += 1;
let link = $(item).find('h2 a');
if (link.length === 0) {
link = $(item).find('.fileTitle a');
}
const subtitle = $(item).find('.contextTitle');
let title = '';
title = $(link).text();
if (subtitle.length) {
title = $(subtitle).text() + ' - ' + title;
}
downloadResponse.links.push({
link: $(link).attr('href'),
number: padStart(String(i), 3, '0'),
title,
title_pinyin: (await pinyinConverter.toPinyin(title.split(' ')))
.map(item => {
if (!isChinese(item.ideogram)) {
return item.pinyin.split('').join(String.fromCharCode(160));
}
const pinyinSeparated = separatePinyinInSyllables(item.pinyin);
return pinyinSeparated.join(String.fromCharCode(160));
})
.join(String.fromCharCode(160)),
});
}
return downloadResponse;
}
示例9: getTimerBucket
export function getTimerBucket(expiration: number, length: number): string {
const delta = expiration - Date.now();
if (delta < 0) {
return '00';
}
if (delta > length) {
return '60';
}
const bucket = Math.round(delta / length * 12);
return padStart(String(bucket * 5), 2, '0');
}
示例10: padStart
export const DebugTimingCumulative = (label?: string, logInterval = 5000) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
const fn = descriptor.value;
let count = 0;
label = padStart(label ? label : getMethodName(target, propertyKey), 50);
let cumulativeTime = 0;
setInterval(() => log(`${label} ${padStart('' + count, 10)} calls in ${cumulativeTime} ms`), logInterval);
descriptor.value = function() {
count++;
const start = now();
const result = fn.apply(this, arguments);
cumulativeTime += (now() - start);
return result;
}
};
示例11: sample
const CONTACTS = COLORS.map((color, index) => {
const title = `${sample(['Mr.', 'Mrs.', 'Ms.', 'Unknown'])} ${color} 🔥`;
const key = sample(['name', 'profileName']) as string;
const id = `+1202555${padStart(index.toString(), 4, '0')}`;
const contact = {
color,
[key]: title,
id,
type: 'private',
};
return parent.ConversationController.dangerouslyCreateAndAdd(contact);
});
示例12: padStart
return venues.filter(([, venue]) => {
const start = time * 100;
const dayAvailability = venue.find((availability) => availability.day === SCHOOLDAYS[day]);
if (!dayAvailability) return true;
// Check that all half-hour slots within the time requested are vacant
for (let i = 0; i < duration * 2; i++) {
const timeString = padStart(String(start + hourDifference[i]), 4, '0');
if (dayAvailability.availability[timeString] === OCCUPIED) {
return false;
}
}
return true;
});
示例13: notesDataAndKeysoundsDataForBmsonAndTiming
function notesDataAndKeysoundsDataForBmsonAndTiming(
bmson: Bmson,
timing: BMS.Timing
) {
let nextKeysoundNumber = 1
let beatForPulse = beatForPulseForBmson(bmson)
let notes = []
let keysounds: { [keysoundId: string]: string } = {}
let soundChannels = soundChannelsForBmson(bmson)
if (soundChannels) {
for (let { name, notes: soundChannelNotes } of soundChannels) {
let sortedNotes = _.sortBy(soundChannelNotes, 'y')
let keysoundNumber = nextKeysoundNumber++
let keysoundId = _.padStart('' + keysoundNumber, 4, '0')
let slices = utils.slicesForNotesAndTiming(soundChannelNotes, timing, {
beatForPulse: beatForPulse,
})
keysounds[keysoundId] = name
for (let { x, y, l } of sortedNotes) {
let note: BMS.BMSNote = {
column: getColumn(x),
beat: beatForPulse(y),
keysound: keysoundId,
endBeat: undefined,
}
if (l > 0) {
note.endBeat = beatForPulse(y + l)
}
let slice = slices.get(y)
if (slice) {
Object.assign(note, slice)
notes.push(note)
}
}
}
}
return { notes, keysounds }
}
示例14: moment
export const getSuggestedFilename = ({
attachment,
timestamp,
index,
}: {
attachment: Attachment;
timestamp?: number | Date;
index?: number;
}): string => {
if (attachment.fileName) {
return attachment.fileName;
}
const prefix = 'signal-attachment';
const suffix = timestamp
? moment(timestamp).format('-YYYY-MM-DD-HHmmss')
: '';
const fileType = getFileExtension(attachment);
const extension = fileType ? `.${fileType}` : '';
const indexSuffix = index ? `_${padStart(index.toString(), 3, '0')}` : '';
return `${prefix}${suffix}${indexSuffix}${extension}`;
};
示例15: create
static create(opts) {
opts = opts || {};
const x = new Email();
x.version = 2;
const now = Date.now();
x.createdOn = Math.floor(now / 1000);
x.id = _.padStart(now.toString(), 14, '0') + Uuid.v4();
x.walletId = opts.walletId;
x.copayerId = opts.copayerId;
x.from = opts.from;
x.to = opts.to;
x.subject = opts.subject;
x.bodyPlain = opts.bodyPlain;
x.bodyHtml = opts.bodyHtml;
x.status = 'pending';
x.attempts = 0;
x.lastAttemptOn = null;
x.notificationId = opts.notificationId;
x.language = opts.language || 'en';
return x;
}