Hyperlinkv0.8.0-beta.28

String

String.takeRightconsteffect/String.ts:946
(n: number): (self: string) => string
(self: string, n: number): string

Keeps the specified number of characters from the end of a string.

Details

If n is larger than the available number of characters, the string will be returned whole.

If n is not a positive number, an empty string will be returned.

If n is a float, it will be rounded down to the nearest integer.

Example (Taking characters from the end)

import { String } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(String.takeRight("Hello World", 5), "World")
transforming
Source effect/String.ts:9467 lines
export const takeRight: {
  (n: number): (self: string) => string
  (self: string, n: number): string
} = dual(
  2,
  (self: string, n: number): string => self.slice(Math.max(0, self.length - Math.floor(n)), Infinity)
)