omcg/id_case

Types

An identifier can be in one of the following cases: PascalCase, camelCase, snake_case or unknown.

pub type IdentifierCase {
  PascalCase(value: String)
  SnakeCase(value: String)
  CamelCase(value: String)
  SpaceCase(value: String)
  UnknownCase(value: String)
}

Constructors

  • PascalCase(value: String)
  • SnakeCase(value: String)
  • CamelCase(value: String)
  • SpaceCase(value: String)
  • UnknownCase(value: String)

Values

pub fn capitalise_first(string: String) -> String

Capitalises the first letter of a string. If the string is empty, returns an empty string.

pub fn compare(
  a: IdentifierCase,
  b: IdentifierCase,
  ignore_case: Bool,
) -> order.Order
pub fn identify_case(string: String) -> IdentifierCase

Identifies the case of a string. It can be PascalCase, camelCase, snake_case or unknown. If the string is in an unknown case, it will be returned as-is.

pub fn is_camel_case(string: String) -> Bool

A camelCase string is a string that starts with a lowercase letter and contains only letters and numbers. Each new word starts with an uppercase letter.

pub fn is_pascal_case(string: String) -> Bool

A PascalCase string is a string that starts with an uppercase letter and contains only letters and numbers. Each new word starts with an uppercase letter.

pub fn is_snake_case(string: String) -> Bool

A snake_case string is a string that is all lowercase and contains only letters, numbers and underscores. It cannot start or end with an underscore, and it cannot contain consecutive underscores.

pub fn namespace_of(path: String) -> String
pub fn namespace_only(name: String) -> String
pub fn string_to_pascal_case(string: String) -> String

Converts a string to PascalCase. This supports snake_case, camelCase and PascalCase strings. If the string is in an unknown case, it will be returned as-is.

pub fn string_to_snake_case(string: String) -> String

Converts a string to snake_case. This supports snake_case, camelCase and PascalCase strings. If the string is in an unknown case, it will be returned as-is.

pub fn string_to_space_case(string: String) -> String
pub fn to_camel_case(
  identifier: IdentifierCase,
) -> IdentifierCase

Converts an identifier to camelCase. This supports PascalCase, camelCase and snake_case identifiers. If the identifier is in an unknown case, it will be returned as-is.

pub fn to_gleam_path(path: String) -> String
pub fn to_pascal_case(
  identifier: IdentifierCase,
) -> IdentifierCase

Converts an identifier to PascalCase. This supports PascalCase, camelCase and snake_case identifiers. If the identifier is in an unknown case, it will be returned as-is.

pub fn to_snake_case(
  identifier: IdentifierCase,
) -> IdentifierCase

Converts an identifier to snake_case. This supports PascalCase, camelCase and snake_case identifiers. If the identifier is in an unknown case, it will be returned as-is.

pub fn to_space_case(
  identifier: IdentifierCase,
) -> IdentifierCase
pub fn without_namespace(name: String) -> String
✨ Search Document