source: trip-planner-front/node_modules/gauge/progress-bar.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 998 bytes
Line 
1'use strict'
2var validate = require('aproba')
3var renderTemplate = require('./render-template.js')
4var wideTruncate = require('./wide-truncate')
5var stringWidth = require('string-width')
6
7module.exports = function (theme, width, completed) {
8 validate('ONN', [theme, width, completed])
9 if (completed < 0) completed = 0
10 if (completed > 1) completed = 1
11 if (width <= 0) return ''
12 var sofar = Math.round(width * completed)
13 var rest = width - sofar
14 var template = [
15 {type: 'complete', value: repeat(theme.complete, sofar), length: sofar},
16 {type: 'remaining', value: repeat(theme.remaining, rest), length: rest}
17 ]
18 return renderTemplate(width, template, theme)
19}
20
21// lodash's way of repeating
22function repeat (string, width) {
23 var result = ''
24 var n = width
25 do {
26 if (n % 2) {
27 result += string
28 }
29 n = Math.floor(n / 2)
30 /*eslint no-self-assign: 0*/
31 string += string
32 } while (n && stringWidth(result) < width)
33
34 return wideTruncate(result, width)
35}
Note: See TracBrowser for help on using the repository browser.