How to use the pascalCase function from change-case

Find comprehensive JavaScript change-case.pascalCase code examples handpicked from public code repositorys.

change-case.pascalCase is a function that converts a string to PascalCase format, which is a naming convention where the first letter of each word is capitalized and there are no spaces or underscores between words.

5
6
7
8
9
10
11
12
13
14
const replace = require('@rollup/plugin-replace');
const pkg = require('./package.json');

pkg.name = pkg.name.replace('js', '');

const name = changeCase.pascalCase(pkg.name);
const banner = createBanner({
  data: {
    name: `${name}.js`,
    year: '2018-present',
fork icon411
star icon0
watch icon38

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
const list = fs.readdirSync(path.resolve(__dirname, 'markdown/v3'))

const posts = list.filter(item => item.endsWith('.md')).map(item => item.replace('.md', ''))

posts.forEach(post => {
  const title = changeCase.pascalCase(post.replace(/-/g, ' '))

  const frontmatterData = {
    title,
    keywords: `we-vue, ${post}`,
fork icon123
star icon486
watch icon20

+ 3 other calls in file

How does change-case.pascalCase work?

change-case.pascalCase works by taking a string input and transforming it into PascalCase format. Here's how it does that: The input string is split into an array of words based on the presence of spaces, underscores, hyphens, or any combination of these characters. Each word in the array is transformed into a new string in which the first letter is capitalized and all subsequent letters are lowercase. The resulting strings are concatenated together to form the final PascalCase string. For example, given the input string "foo_bar-baz", change-case.pascalCase would transform it into "FooBarBaz". Note that the underscores and hyphens are removed, and the first letter of each word is capitalized. change-case.pascalCase can also handle other types of input besides strings. For example, if the input is an array of words, each word will be transformed and concatenated into a PascalCase string. If the input is not a string or array, change-case.pascalCase will attempt to convert it to a string before performing the transformation. Overall, change-case.pascalCase provides a convenient way to transform strings into PascalCase format, which is commonly used in programming for naming classes, variables, and other entities.

37
38
39
40
41
42
43
  },
};

function isPascalCase({name, value}) {
  const identifier = name || value;
  return identifier != null && identifier === pascalCase(identifier);
}
fork icon55
star icon429
watch icon399

+ 3 other calls in file

48
49
50
51
52
53
54
55
56
57
  },
  {
    type: 'input',
    name: 'namespace',
    message: 'Namespace (e.g. "MyAwesomeProject")',
    filter: value => pascalCase(value.trim()),
    validate: value => value.length !== 0,
  },
])
.then((answers) => {
fork icon30
star icon283
watch icon17

+ 7 other calls in file

Ai Example

1
2
3
4
5
6
const changeCase = require("change-case");

const inputString = "my_input_string";
const pascalCaseString = changeCase.pascalCase(inputString);

console.log(pascalCaseString); // Output: "MyInputString"

In this example, we first import the change-case library and assign it to a variable called changeCase. We then define an input string that we want to convert to PascalCase format. In this case, the input string is 'my_input_string'. We then call the changeCase.pascalCase function with the input string as an argument. This function transforms the input string into PascalCase format and returns the result, which we assign to a variable called pascalCaseString. Finally, we log the pascalCaseString variable to the console, which outputs "MyInputString". Note that change-case.pascalCase can handle different types of input besides strings, such as arrays or objects with string properties. The function also handles edge cases such as empty strings and strings with no letters (e.g. "1234").

90
91
92
93
94
95
96
97
98
99
const entryNameToId = name => {
  const letters = name.split(/[-_]/);
  if (letters.length === 1) {
    return letters.join('');
  }
  return changeCase.pascalCase(letters.join(' '));
};
const entryFileTemplateContent = fs.readFileSync(entryFileTemplate);
const exportsFileTemplateContent = fs.readFileSync(
  path.join(webcubePath, 'boilerplate/exports.js')
fork icon21
star icon146
watch icon10

+ 3 other calls in file

63
64
65
66
67
68
69
70
71
72
73
    case FORMAT_TYPES.kebabCase:
      return paramCase(displayName)
    case FORMAT_TYPES.lowerCamelCase:
      return lowerCaseFirst(displayName)
    default:
      return pascalCase(displayName)
  }
}


function getOutputPath(copyOutDir, compileOpts) {
fork icon0
star icon3
watch icon0

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
24
25
  const schemaName = pluralize.singular(changeCase.pascalCase(splitCamelCase(rawName)))
  return `${schemaName}Schema`
}


const getSchemaImportName = (name) => {
  const nameSingle = changeCase.pascalCase(pluralize.singular(name))
  return `${lowercaseFirstLetter(nameSingle)}.schema`
}


const getStubsName = (name) => {
fork icon0
star icon2
watch icon1

+ 11 other calls in file

31
32
33
34
35
36
37
38
39
40
41
    'plates': 'PlatesView',
    'twig': 'TwigView'
};


function swapNameStrings() {
    let pascalName = pascalCase(argv.name);
    let kebabName = paramCase(argv.name);
    let snakeName = snakeCase(argv.name);
    let titleName = capitalCase(argv.name);
    return src(paths, { base: "./" })
fork icon0
star icon1
watch icon1

+ 35 other calls in file

13
14
15
16
17
18
19
20
21
22
      })
      .then(({ DTO_FILE }) => {
        const name = DTO_FILE.replace('.dto.ts', '');
        return {
          DTO_FILE,
          NAME: pascalCase(singular(name))
        };
      });
  }
};
fork icon0
star icon0
watch icon0

+ 2 other calls in file

6
7
8
9
10
11
12
13
14
15
16
for (const component of docs.components) {
  if (!component.usage.vue) continue
  const attributes = []
  const slots = []
  const events = []
  const componentName = pascalCase(component.tag)
  const docUrl = "https://ionicframework.com/docs/api/" + component.tag.substr(4)


  for (const prop of component.props || []) {
    attributes.push({
fork icon0
star icon0
watch icon0

+ 2 other calls in file

0
1
2
3
4
5
6
7
8
9
10
const changeCase = require('change-case');


module.exports = {
  helpers: {
    toPascalCase(text) {
      return changeCase.pascalCase(text);
    },
    createBaseClassName(level, name) {
      const atomicPrefix = `${level.slice(0, 1)}-`;
      return `${atomicPrefix}${name}`;
fork icon0
star icon0
watch icon0

15
16
17
18
19
20
21
22
23
24
upperCase: _.upperCase,
pascalCase: changeCase.pascalCase,
removeExt: (filename) => path.parse(filename).name,
dtoVar: (filename) => {
  const name = path.parse(filename).name.replace('dto', '');
  return changeCase.pascalCase(name) + 'DTO';
},
moduleName: (filename, suffix = '') => {
  const path = filename.split('.');
  const result = changeCase.pascalCase(path[0]);
fork icon0
star icon0
watch icon0