# all files / src/util/ text-helper.js

100% Statements 31/31
93.75% Branches 15/16
100% Functions 7/7
100% Lines 27/27
1 branch Ignored

    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
    471×
    1×

    1×
    1×

    1×
    1×

    1×
    1×

    1×
    3×

    1×
    3×

    1×
    6×

    6×
    1×

    5×
    1×
    4×
    1×
    3×
    1×
    2×
    1×
    1×
    1×

     import chalk from 'chalk';
    import { depascalize, pascalize, camelize } from 'humps';

    // Bootstrap inspired text color helpers for the command line.
    export const success = (text) => {
      return chalk.green(text);
    };

    export const danger = (text) => {
      return chalk.red(text);
    };

    export const warning = (text) => {
      return chalk.yellow(text);
    };

    // Random string/text helpers
    export const normalizeComponentName = (name) => {
      return pascalize(name);
    };

    export const normalizeDuckName = (name) => {
      return camelize(name);
    };

    export const normalizeCasing = (string, casing) => {
      const types = ['default', 'snake', 'pascal', 'camel', 'dashes'];

      if (types.indexOf(casing) === -1) {
        throw new Error(
          `Casing must be one of: ${types.join(', ')} types`
        );
      }

      if (casing === 'snake') {
        return depascalize(pascalize(string));
      } else if (casing === 'pascal') {
        return pascalize(string);
      } else if (casing === 'camel') {
        return camelize(string);
      } else if (casing === 'default') {
        return string;
      } else Eif (casing == 'dashes') {
        return depascalize(string, { separator: '-' });
      }
    };