1 | /**
|
2 | * Convert string into upper snake case.
|
3 | * Join punctuation with underscore and convert letters into uppercase.
|
4 | * @memberof module:stringcase/lib
|
5 | * @function constcase
|
6 | * @param {string} str - String to convert.
|
7 | * @returns {string} Const cased string.
|
8 | */
|
9 |
|
10 |
|
11 |
|
12 | const uppercase = require('./uppercase')
|
13 | const snakecase = require('./snakecase')
|
14 |
|
15 | /** @lends constcase */
|
16 | function constcase (str) {
|
17 | if (constcase.isConstcase(str)) {
|
18 | return str
|
19 | }
|
20 | return uppercase(snakecase(str))
|
21 | }
|
22 |
|
23 | /**
|
24 | * Checks whether the string are constcase.
|
25 | * @memberof module:stringcase/lib
|
26 | * @function constcase.isConstcase
|
27 | * @param {string} str - String to check.
|
28 | * @returns {boolean} - True if the string are constcase.
|
29 | */
|
30 | constcase.isConstcase = function (str) {
|
31 | return str && /^[A-Z_]+$/.test(str)
|
32 | }
|
33 |
|
34 | module.exports = constcase;
|