npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

curry-rice

v1.0.0

Published

TypeScript-first curry function without upcast

Downloads

42

Readme

test GitHub release deno land nest badge deno doc deno version node support version npm download

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

A curly function with a strict type definition. There is no upcast to any types, respecting the typedef of the callback function.


:sparkles: Features

  • :zap: Multi runtime support (Deno, Node.js and Browsers)
  • :books: Pure TypeScript and provides type definition
  • :earth_americas: Universal module, providing ES modules and Commonjs
  • :package: Optimized, super slim size
  • :page_facing_up: TSDoc-style comments

Package name

Deno: curry (deno.land, nest.land)

Node.js: curry-rice (npm)

The origin of the word curry-rice is Rice and curry 🍛.

:zap: Overview

ReturnValue

const replace = (from: string, to: string, val: string) =>
  val.replace(from, to);
const curriedReplace = curry(replace);

curriedReplace("hello", "hi", "hello world"); // 'hi world'
curriedReplace("hello")("hi", "hello world"); // 'hi world'
curriedReplace("hello", "hi")("hello world"); // 'hi world'
curriedReplace("hello")("hi")("hello world"); // 'hi world'
curriedReplace("hello", "hi", "hello world"); // 'hi world'

ReturnType

curriedReplace("hello"); // (to: string, val: string): string

curriedReplace("hello")("hi"); // (val: string): string
curriedReplace("hello", "hi"); // (val: string): string

curriedReplace("hello", "hi", "hello world"); // string
curriedReplace("hello")("hi")("hello world"); // string
curriedReplace("hello", "hi")("hello world"); // string
curriedReplace("hello")("hi", "hello world"); // string

:dizzy: Usage

curry provides multi platform modules.

🦕 Deno

deno.land

import { curry } from "https://deno.land/x/curry/mod.ts";

curry(AnyFn);

nest.land

import { curry } from "https://x.nest.land/curry/mod.ts";

curry(AnyFn);

:package: Node.js

NPM package name is curry-rice .

Install

npm i curry-rice
or
yarn add curry-rice

ES modules

import { curry } from "curry-rice";

curry(AnyFn);

Commonjs

const { curry } = require("curry-rice");

curry(AnyFn);

:globe_with_meridians: Browser

The module that bundles the dependencies is obtained from skypack.

<script type="module">
  import { curry } from "https://cdn.skypack.dev/curry-rice";
  curry(AnyFn)
</script>

API

Type definition

curry

declare const curry: <T extends unknown[], R>(
  fn: (...args: T) => R,
) => Curried<T, R>;

| Parameter | Description | | --------- | ------------ | | fn | Any function |

=> The new curried function

Example

const nullary = () => true;
curry(nullary); // ()  => boolean
const unary = (val: number) => val++;
curry(unary); // (val: number)  => number
const binaryFn = (a: number, b: number) => a + b;
curry(binaryFn); // (a: number, b: number)  => number || (a: number) => (b:number) => number

Restriction

This package is focused on getting correct type inference. Hence, there are the following limitations:

  • Maximum number of arity is 19.

Beyond that, the type system will breaks.

Overloads function is something like this:

function len(s: string): number;
function len(arr: any[]): number;
function len(x: any) {
  return x.length;
}

For example, it has the following differences from lodash.curry.

  • lodash.curry has a placeholder feature, which this package does not have.
  • The argument of the curried function in lodash.curry is any types, but in this package, the type of the original argument is inferred.

Although placeholders are a useful feature, it is very difficult to implement it while maintaining correct type inference.

If you can solve this issue, please make a pull request.

:green_heart: Supports

ie is no longer supported to reduce bundle size.

The TypeScript version must be 4.1.0 or higher.

This project provides ES modules and Commonjs.

If you have an opinion about what to support, you can open an issue to discuss it.

The browserslist has the following settings.

defaults
last 8 version
not IE <= 11
not ie_mob <= 11
node 6

| Deno | Node.js | Edge | Firefox | Chrome | Safari | iOS Safari | Samsung | Opera | | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | ^1.6.0 | ^6.17.0 | ^83 | ^78 | ^83 | ^11 | ^12.0 | ^7.2 | ^68 |

:handshake: Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues.

Contributing guide

:seedling: Show your support

Give a ⭐️ if this project helped you!

:bulb: License

Copyright © 2021-present TomokiMiyauci.

Released under the MIT license