Hyperlinkv0.8.0-beta.28

String

String.takeLeftconsteffect/String.ts:917
(n: number): (self: string) => string
(self: string, n: number): string

Keeps the specified number of characters from the start 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 start)

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

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