change-case#pascalCase TypeScript Examples

The following examples show how to use change-case#pascalCase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnumRenderer.ts    From modelina with Apache License 2.0 6 votes vote down vote up
CSHARP_DEFAULT_ENUM_PRESET: EnumPreset<EnumRenderer> = {
  self({ renderer }) {
    return renderer.defaultSelf();
  },
  item({ item }) {
    let itemName = FormatHelpers.replaceSpecialCharacters(String(item), { exclude: [' '], separator: '_' });
    if (typeof item === 'number' || typeof item === 'bigint') {
      itemName = `Number_${itemName}`;
    } else if (typeof item === 'object') {
      itemName = `${JSON.stringify(item)}`;
    } else if (!(/^[a-zA-Z]+$/).test(itemName.charAt(0))) {
      itemName = `String_${itemName}`;
    }

    return pascalCase(itemName);
  },
}
Example #2
Source File: ts.ts    From fantasticon with MIT License 6 votes vote down vote up
generateEnumKeys = (assetKeys: string[]): Record<string, string> =>
  assetKeys
    .map(name => {
      const enumName = pascalCase(name);
      const prefix = enumName.match(/^\d/) ? 'i' : '';

      return {
        [name]: `${prefix}${enumName}`
      };
    })
    .reduce((prev, curr) => Object.assign(prev, curr), {})
Example #3
Source File: run.ts    From design-systems-cli with MIT License 6 votes vote down vote up
/** Determine the destination directory of the templated package. */
function getDestDirectory(
  command: CreationChoice,
  name: string,
  dest?: string
) {
  const pascal = pascalCase(name);
  const kebab = paramCase(name);

  return (
    (command === 'component' &&
      path.join(BASE_DIR, dest ?? 'components', pascal)) ||
    (command === 'package' && path.join(BASE_DIR, dest ?? 'packages', kebab)) ||
    dest ||
    name
  );
}
Example #4
Source File: index.ts    From graphql-mesh with MIT License 6 votes vote down vote up
NAMING_CONVENTIONS: Record<NamingConventionType, NamingConventionFn> = {
  camelCase,
  capitalCase,
  constantCase,
  dotCase,
  headerCase,
  noCase,
  paramCase,
  pascalCase,
  pathCase,
  sentenceCase,
  snakeCase,
  upperCase,
  lowerCase,
}
Example #5
Source File: helpers.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
structNameForPropertyName(propertyName: string) {
    return pascalCase(Inflector.singularize(propertyName));
  }
Example #6
Source File: ts.ts    From fantasticon with MIT License 5 votes vote down vote up
generator: FontGenerator = {
  generate: async ({
    name,
    codepoints,
    assets,
    formatOptions: { ts } = {}
  }) => {
    const quote = Boolean(ts?.singleQuotes) ? "'" : '"';
    const generateKind: Record<string, boolean> = (
      Boolean(ts?.types?.length)
        ? ts.types
        : ['enum', 'constant', 'literalId', 'literalKey']
    )
      .map(kind => ({ [kind]: true }))
      .reduce((prev, curr) => Object.assign(prev, curr), {});

    const enumName = pascalCase(name);
    const codepointsName = `${constantCase(name)}_CODEPOINTS`;
    const literalIdName = `${pascalCase(name)}Id`;
    const literalKeyName = `${pascalCase(name)}Key`;
    const names = { enumName, codepointsName, literalIdName, literalKeyName };

    const enumKeys = generateEnumKeys(Object.keys(assets));

    const stringLiteralId = generateKind.literalId
      ? generateStringLiterals(literalIdName, Object.keys(enumKeys), quote)
      : null;
    const stringLiteralKey = generateKind.literalKey
      ? generateStringLiterals(literalKeyName, Object.values(enumKeys), quote)
      : null;

    const enums = generateKind.enum
      ? generateEnums(enumName, enumKeys, quote)
      : null;
    const constant = generateKind.constant
      ? generateConstant({
          ...names,
          enumKeys,
          codepoints,
          quote,
          kind: generateKind
        })
      : null;

    return [stringLiteralId, stringLiteralKey, enums, constant]
      .filter(Boolean)
      .join('\n');
  }
}
Example #7
Source File: genres.ts    From aws-nestjs-starter with The Unlicense 5 votes vote down vote up
async function main() {
  if (!matchPattern || !outputFile) {
    console.log('missing required arguments.');
    return;
  }

  dynamoose.aws.sdk.config.update({
    region: 'any',
  });

  const slsResources: { Resources: Record<string, any> } = { Resources: {} };

  // find all the files that match the given pattern
  const files = await glob.promise(matchPattern);
  await Promise.all(
    files.map(async (file) => {
      console.log('detected:', file);

      // use the filename without extention as tablename
      const fileNameExt = file.split(/[\\\/]/).pop()!;
      const fileName = fileNameExt.split('.').shift()!;
      const tableName = pascalCase(fileName);

      // dynamic import the typescript file
      const exports = await import(`.${path.sep}${file}`);
      // get the first export
      const schema = Object.values(exports).shift() as Schema;

      // make sure it is a Schema class
      if (schema.constructor.name === 'Schema') {
        const model = dynamoose.model(fileName, schema, globalOptions);
        // append to the resources object
        slsResources.Resources[`${tableName}Table`] = {
          Type: 'AWS::DynamoDB::Table',
          DeletionPolicy: deletionPolicy,
          Properties: await (model as any).table.create.request(),
        };
      }
    }),
  );

  // convert from js object to yaml
  const yamlReources = yaml.dump(slsResources);
  const outputPath = outputFile.split(/[\\\/]/);
  // create the missing folders if necessary
  if (outputPath.length > 1) {
    await fs.promises.mkdir(
      outputPath.slice(0, outputPath.length - 1).join(path.sep),
      { recursive: true },
    );
  }
  // write to output file
  await fs.promises.writeFile(outputFile, yamlReources);
  console.log(`Serverless resources file generated at ${outputFile}`);
  process.exit(0);
}
Example #8
Source File: transformSvgToComponent.ts    From reskript with MIT License 5 votes vote down vote up
resolveDisplayName = (filename: string) => {
    const base = path.basename(path.basename(filename), path.extname(filename));
    return pascalCase(base);
}
Example #9
Source File: helpers.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
structNameForVariant(variant: SelectionSet) {
    return 'As' + variant.possibleTypes.map(type => pascalCase(type.name)).join('Or');
  }
Example #10
Source File: helpers.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
structNameForFragmentName(fragmentName: string) {
    return pascalCase(fragmentName);
  }
Example #11
Source File: helpers.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
operationClassName(name: string) {
    return pascalCase(name);
  }
Example #12
Source File: appsync-visitor.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
protected getEnumName(enumField: CodeGenEnum | string): string {
    if (typeof enumField === 'string') {
      return pascalCase(enumField);
    }
    return pascalCase(enumField.name);
  }
Example #13
Source File: appsync-java-visitor.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
/**
   * Generate the name of the step builder interface
   * @param nextFieldName: string
   * @returns string
   */
  private getStepInterfaceName(nextFieldName: string): string {
    return `${pascalCase(nextFieldName)}Step`;
  }
Example #14
Source File: appsync-java-visitor.ts    From amplify-codegen with Apache License 2.0 5 votes vote down vote up
/**
   * Generate Java field getter name
   * @param field codegen field
   */
  protected getFieldGetterName(field: CodeGenField): string {
    return `get${pascalCase(field.name)}`;
  }
Example #15
Source File: FormatHelpers.ts    From modelina with Apache License 2.0 5 votes vote down vote up
/**
   * Transform into a string of capitalized words without separators.
   * @param {string} value to transform
   * @returns {string}
   */
  static toPascalCase = pascalCase;
Example #16
Source File: ClassRenderer.ts    From modelina with Apache License 2.0 5 votes vote down vote up
CSHARP_DEFAULT_CLASS_PRESET: CsharpClassPreset = {
  self({ renderer }) {
    return renderer.defaultSelf();
  },
  async property({ renderer, propertyName, options, property, type }) {
    propertyName = renderer.nameProperty(propertyName, property);
    let propertyType = renderer.renderType(property, propertyName);
    if (type === PropertyType.additionalProperty || type === PropertyType.patternProperties) {
      propertyType = `Dictionary<string, ${propertyType}>`;
    }
    if (options?.autoImplementedProperties) {
      const getter = await renderer.runGetterPreset(propertyName, property, options, type);
      const setter = await renderer.runSetterPreset(propertyName, property, options, type);
      return `public ${propertyType} ${pascalCase(propertyName)} { ${getter} ${setter} }`;
    }
    return `private ${propertyType} ${propertyName};`;
  },
  async accessor({ renderer, propertyName, options, property, type }) {
    const formattedAccessorName = pascalCase(renderer.nameProperty(propertyName, property));
    let propertyType = renderer.renderType(property, propertyName);
    if (type === PropertyType.additionalProperty || type === PropertyType.patternProperties) {
      propertyType = `Dictionary<string, ${propertyType}>`;
    }
    if (options?.autoImplementedProperties) {
      return '';
    }

    return `public ${propertyType} ${formattedAccessorName} 
{
  ${await renderer.runGetterPreset(propertyName, property, options, type)}
  ${await renderer.runSetterPreset(propertyName, property, options, type)}
}`;
  },
  getter({ renderer, propertyName, options, property }) {
    if (options?.autoImplementedProperties) {
      return 'get;';
    }
    const formattedPropertyName = renderer.nameProperty(propertyName, property);
    return `get { return ${formattedPropertyName}; }`;
  },
  setter({ renderer, propertyName, options, property }) {
    if (options?.autoImplementedProperties) {
      return 'set;';
    }
    const formattedPropertyName = renderer.nameProperty(propertyName, property);
    return `set { ${formattedPropertyName} = value; }`;
  }
}
Example #17
Source File: run.ts    From design-systems-cli with MIT License 4 votes vote down vote up
/** A plugin to create a completely new system or a new package in a system. */
export default async function run(args: CreateArgs) {
  const command = getCommand(args);

  if (args.listTemplates) {
    logger.info(listTemplates(command, args.template, args.templates));
    return;
  }

  const template = await getTemplatePath(args);
  const skipUnnecessaryPrompts = Boolean(args.name);
  const name = args.name || (await askName(command, args.force));
  const config: TemplateOptions = {
    name,
    authorName:
      (skipUnnecessaryPrompts && defaultAuthorName()) || (await askAuthor()),
    authorEmail:
      (skipUnnecessaryPrompts && defaultAuthorEmail()) || (await askEmail()),
    version: (skipUnnecessaryPrompts && defaultVersion) || (await askVersion()),
    repoUrl:
      ('repo' in args && args.repo) ||
      (skipUnnecessaryPrompts && repo()) ||
      repo() ||
      (await askRepo()),
    monorepoName: monorepoName()
  };
  const pascal = pascalCase(config.name);
  const kebab = paramCase(config.name);
  let destinationDirectory = getDestDirectory(
    command,
    config.name,
    'destination' in args ? args.destination : undefined
  );

  if ('cwd' in args && args.cwd) {
    logger.debug('Creating repo in current working directory...');
    destinationDirectory = '.';
  }

  if ('force' in args && args.force) {
    await fs.remove(destinationDirectory);
  } else if (fs.existsSync(destinationDirectory)) {
    logger.error(
      `Destination directory already exists! '${destinationDirectory}'\n\nRun with --force to ignore`
    );
    process.exit(1);
  }

  logger.debug('Creating templated directory...');
  await copy(template, destinationDirectory, {
    ...config,
    cliVersion,
    title: titleCase(config.name),
    kebab,
    pascal,
    camel: camelCase(config.name)
  });
  logger.debug('Created templated directory!');

  if (command === 'component') {
    logger.success(dedent`\n
      ✨   You made a component  ✨

      ?️   Start developing:

      yarn
      cd ${destinationDirectory}
      yarn dev
    `);
  } else if (command === 'package') {
    logger.success(dedent`\n
      ✨   You made a package  ✨

      ?   Start developing:

      yarn
      cd ${destinationDirectory}
      yarn start
    `);
  } else {
    if ('cwd' in args && !args.cwd) {
      logger.info('Initializing git repo');

      execSync(`cd ${config.name} && git init`);
      execSync(`cd ${config.name} && git remote add origin ${config.repoUrl}`);

      logger.await('Running yarn. This may take a bit...');

      await estimator(
        new Promise<void>((res, rej) => {
          try {
            const isVerbose =
              getLogLevel() === 'debug' || getLogLevel() === 'trace';
            execSync(`cd ${config.name} && yarn`, {
              stdio: isVerbose ? 'inherit' : 'ignore'
            });
            res();
          } catch (error) {
            rej(error);
          }
        }),
        'Installing dependencies',
        72 * 1000 as LogOption
      );
      execSync(
        `cd ${config.name} && git add . && git commit --no-verify -m "Create new design system"`
      );
    }

    logger.success(dedent`\n
      ✨  You made a design system  ✨
        
      ?   Create your first component:
      ${destinationDirectory === '.' ? '' : `\ncd ${destinationDirectory}`}
      yarn run create
    `);
  }
}