PHP 8.2.30
Preview: template-item.js Size: 1.86 KB
//usr/lib/node_modules/npm/node_modules/gauge/template-item.js

'use strict'
var stringWidth = require('string-width')

module.exports = TemplateItem

function isPercent (num) {
  if (typeof num !== 'string') return false
  return num.slice(-1) === '%'
}

function percent (num) {
  return Number(num.slice(0, -1)) / 100
}

function TemplateItem (values, outputLength) {
  this.overallOutputLength = outputLength
  this.finished = false
  this.type = null
  this.value = null
  this.length = null
  this.maxLength = null
  this.minLength = null
  this.kerning = null
  this.align = 'left'
  this.padLeft = 0
  this.padRight = 0
  this.index = null
  this.first = null
  this.last = null
  if (typeof values === 'string') {
    this.value = values
  } else {
    for (var prop in values) this[prop] = values[prop]
  }
  // Realize percents
  if (isPercent(this.length)) {
    this.length = Math.round(this.overallOutputLength * percent(this.length))
  }
  if (isPercent(this.minLength)) {
    this.minLength = Math.round(this.overallOutputLength * percent(this.minLength))
  }
  if (isPercent(this.maxLength)) {
    this.maxLength = Math.round(this.overallOutputLength * percent(this.maxLength))
  }
  return this
}

TemplateItem.prototype = {}

TemplateItem.prototype.getBaseLength = function () {
  var length = this.length
  if (length == null && typeof this.value === 'string' && this.maxLength == null && this.minLength == null) {
    length = stringWidth(this.value)
  }
  return length
}

TemplateItem.prototype.getLength = function () {
  var length = this.getBaseLength()
  if (length == null) return null
  return length + this.padLeft + this.padRight
}

TemplateItem.prototype.getMaxLength = function () {
  if (this.maxLength == null) return null
  return this.maxLength + this.padLeft + this.padRight
}

TemplateItem.prototype.getMinLength = function () {
  if (this.minLength == null) return null
  return this.minLength + this.padLeft + this.padRight
}

Directory Contents

Dirs: 1 × Files: 19

Name Size Perms Modified Actions
- drwxr-xr-x 2024-03-03 22:36:28
Edit Download
395 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
6.23 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
616 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
292 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
6.83 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
751 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
2.13 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
1.24 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
89 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
998 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
14.72 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
5.60 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
139 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
93 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
105 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download
1.86 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
3.61 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
1.51 KB lrw-r--r-- 2021-03-10 14:36:39
Edit Download
828 B lrw-r--r-- 2021-03-10 14:36:39
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).