當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript formatDate.default函數代碼示例

本文整理匯總了TypeScript中src/utilities/formatDate.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了default函數的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: formatDate

export const printInvoice = (
  account: Linode.Account,
  invoice: Linode.Invoice,
  items: Linode.InvoiceItem[]
) => {
  try {
    const itemsPerPage = 18;
    const date = formatDate(invoice.date, { format: 'YYYY-MM-DD' });
    const invoiceId = invoice.id;
    const itemsChunks = items ? splitEvery(itemsPerPage, items) : [[]];
    const tableEnd =
      tableBodyStart + cellHeight * itemsChunks[itemsChunks.length - 1].length;

    const doc = new jsPDF({
      unit: 'px'
    });

    const addTable = (itemsChunk: Linode.InvoiceItem[]) => {
      doc.setFontSize(10);

      const header = [
        { name: 'Description', prompt: 'Description', width: 235 },
        { name: 'From', prompt: 'From', width: 72 },
        { name: 'To', prompt: 'To', width: 72 },
        { name: 'Quantity', prompt: 'Quantity', width: 52 },
        { name: 'Unit Price', prompt: 'Unit Price', width: 67 },
        { name: 'Amount', prompt: 'Amount', width: 52 }
      ] as any[]; // assert type 'any' because per source code this is an extended and more advanced way of usage

      const itemRows = itemsChunk.map(item => {
        const { label, from, to, quantity, unit_price, amount } = item;
        return {
          Description: formatDescription(label),
          From: renderDate(from),
          To: renderDate(to),
          Quantity: renderQuantity(quantity),
          'Unit Price': renderUnitPrice(unit_price),
          Amount: '$' + amount
        };
      });

      // Place table header
      doc.table(leftPadding, 140, [], header, {
        fontSize: 10,
        printHeaders: true,
        autoSize: false,
        margins: {
          left: 15,
          top: 10,
          width: 800,
          bottom: 0
        }
      });

      // Place table body
      doc.table(leftPadding, tableBodyStart, itemRows, header, {
        fontSize: 9,
        printHeaders: false,
        autoSize: false,
        margins: {
          left: leftPadding,
          top: 10,
          width: 800,
          bottom: 0
        }
      });
    };

    const addTotalAmount = () => {
      doc.setFontSize(13);
      doc.setFontStyle('bold');
      // Empty line
      doc.cell(leftPadding, tableEnd, 412.5, 10, ' ', 1, 'left');
      // "Total" cell
      doc.cell(leftPadding, tableEnd + 10, 374, 20, 'Total:  ', 2, 'right');
      // Total value cell
      doc.cell(
        leftPadding + 300,
        tableEnd + 10,
        38.5,
        20,
        `$${Number(invoice.total).toFixed(2)}`,
        2,
        'left'
      );
      // reset text format
      doc.setFontStyle('normal');
    };

    // Create a separate page for each set of invoice items
    itemsChunks.forEach((itemsChunk, index) => {
      doc.addImage(LinodeLogo, 'JPEG', 150, 5, 120, 50);
      addLeftHeader(doc, index + 1, itemsChunks.length, date, 'Invoice');
      addRightHeader(doc, account);
      addTitle(doc, `Invoice: #${invoiceId}`);
      addTable(itemsChunk);
      addFooter(doc);
      if (index < itemsChunks.length - 1) {
        doc.addPage();
      }
//.........這裏部分代碼省略.........
開發者ID:displague,項目名稱:manager,代碼行數:101,代碼來源:PdfGenerator.ts


注:本文中的src/utilities/formatDate.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。