README
farray
TypeScript-first functional array utility
Install
Node.js
npm i farray
yarn add farray
pnpm add farray
Deno
import { head } from 'https://esm.sh/farray'
API
head
Take first element or list safety
types
declare const head: <T extends string | readonly unknown[]>(val: T) => Head<T>
examples
// String
head('') // ''
head('hello') // 'h'
// Array
head<[]> // undefined
head<['hello', 'world']> // 'hello'
last
Take last element of list safety
types
declare const last: <T extends string | readonly unknown[]>(val: T) => Last<T>
examples
// String
last('') // ''
last('hello') // 'o'
// Array
last('hello', 'new', 'world') // 'world'
last([]) // undefined
last(['one', 2, 3, 4]) // 4
take
Return a slice of string or array with n
elements taken from the beginning.
types
declare const take: <T extends string | readonly unknown[]>(
howMany: number,
val: T
) => T
examples
// String
take(3, 'hello') // 'hel'
// Array
take(3, [1, 2, 3, 4]) // [1, 2, 3]
takeLast
Return a slice of string or array with n
elements taken from the end
types
declare const takeLast: <T extends string | readonly unknown[]>(
howMany: number,
val: T
) => T
examples
// String
takeLast(3, 'hello') // 'llo'
// Array
takeLast(3, [1, 2, 3, 4]) // [2, 3, 4]
:handshake: Contributing
Contributions, issues and feature requests are welcome!
Feel free to check
issues.
:seedling: Show your support
Give a ⭐️ if this project helped you!
:bulb: License
Copyright © 2021-present TomokiMiyauci.
Released under the MIT license