R/misc.R

Defines functions no_lookalikes

Documented in no_lookalikes

#' @noRd
#' @keywords internal
.url_alphabet <- c(
  LETTERS,
  letters,
  as.character(0:9),
  "-", "_"
)

#' @noRd
#' @keywords internal
.dict <- list(
  nolookalikes = strsplit(
    "346789ABCDEFGHJKLMNPQRTUVWXYabcdefghijkmnpqrtwxyz",
    "",
    perl = TRUE,
    useBytes = TRUE
  )[[1]],
  nolookalikessafe = strsplit(
    "6789BCDFGHJKLMNPQRTWbcdfghjkmnpqrtwz",
    "",
    perl = TRUE,
    useBytes = TRUE
  )[[1]]
)

#' Predefined character sets
#'
#' Return a predefined character set ported of the 'nanoid-dictionary'.
#' This function supports 2 patterns; "nolookalikes" or "nolookalikesSafe".
#'
#' @param pattern Choice one of `nolookalikes` or `nolookalikessafe`.
#' @return Character vectors.
#'
#' @examples
#' no_lookalikes("nolookalikes")
#' no_lookalikes("nolookalikessafe")
#' @export
no_lookalikes <- function(pattern = c(
                            "nolookalikes",
                            "nolookalikessafe"
                          )) {
  pattern <- match.arg(pattern)
  switch(pattern,
    nolookalikes = .dict[["nolookalikes"]],
    nolookalikessafe = .dict[["nolookalikessafe"]]
  )
}
paithiov909/nanoidr documentation built on Jan. 26, 2025, 9:54 p.m.