File: examples.js

package info (click to toggle)
node-to-regex-range 5.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 148 kB
  • sloc: javascript: 590; makefile: 2
file content (75 lines) | stat: -rw-r--r-- 1,353 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';

const toRegexRange = require('./');
const table = require('text-table');
const Time = require('time-diff');
const time = new Time();

/**
 * $ node examples.js
 */

const toRange = (min, max) => {
  let key = 'to-range' + min + max;
  time.start(key);

  return [
    '',
    `\`toRegexRange(${min}, ${max})\``,
    `\`${toRegexRange(min, max, { wrap: false }).split('|').join('\\|')}\``,
    `_${time.end(key)}_`,
    ''
  ];
};

toRange('1', '3');

let rows = [
  ['', '**Range**', '**Result**', '**Compile time**', ''],
  ['', '--- ', '--- ', '---', ''],
];

let examples = [
  ['-10', '10'],
  ['-100', '-10'],
  ['-100', '100'],

  ['001', '100'],
  ['001', '555'],
  ['0010', '1000'],

  ['1', '50'],
  ['1', '55'],
  ['1', '555'],
  ['1', '5555'],
  ['111', '555'],
  ['29', '51'],
  ['31', '877'],

  ['5', '5'],
  ['5', '6'],
  ['1', '2'],
  ['1', '5'],
  ['1', '10'],
  ['1', '100'],
  ['1', '1000'],
  ['1', '10000'],
  ['1', '100000'],
  ['1', '1000000'],
  ['1', '10000000'],
].forEach(args => {
  rows.push(toRange.apply(null, args));
});

let text = table(rows, { hsep: ' | ' });
console.log(text);

/**
 * This method is exposed as a helper, which is picked up
 * by verb and used in the .verb.md readme template
 */

module.exports = () => {
  return text.split('\n').map(line => line.replace(/^ +/, '')).join('\n');
};