1.0.0-beta.1 • Published 3 years ago

farray v1.0.0-beta.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

test GitHub release npm download

GitHub (Pre-)Release Date dependencies Status codecov Codacy Badge npm type definitions Commitizen friendly Gitmoji semantic-release License: MIT

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

1.0.0-beta.3

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.1

3 years ago