1.0.0-beta.1 • Published 4 years ago
farray v1.0.0-beta.1
Install
Node.js
npm i farrayyarn add farraypnpm add farrayDeno
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]) // 4take
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
) => Texamples
// 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
) => Texamples
// 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