![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
chai-latte
Advanced tools
It's a tool for building expressive fluent interface libraries.
Think of it as a simple tool to buid libraries à la chaijs but not necessarly related to testing. It can be about anyhting :).
Building expressive fluent interfaces isn't easy. the more expressions you add the more it becomes un-maintainable. You'll quickly run into conflicts between expressions.
This tool will do all the heavy lifting for you, removing all the repetitive and soul crushing tasks needed to create such libraries. Now, you can just focus on adding expressions and it will just work! ✨.
It's available on npm. To install it, type:
npm i chai-latte
or
yarn add chai-latte
Lets create a library that will be able to create arrays and add number to it. I know... The example is not exiting 😅. But let's create it anyway! The library we'll create should be able to execute the command below:
import example from './the/library/we/will/create';
const { create, add } = example;
const arr = create.an.array();
add(4).to.this.array(arr)
add(5).to(arr)
const arr2 = create.a.copy.of(arr);
add(5).to(arr2);
expression
function takes two arguments. The first argument should be a function that shows how to use the expression. The second argument is the callback. See example below:import { expression } from 'chai-latte';
const ourFirstExpression = expression(
({ create }) => create.an.array(),
() => {
console.log('Array Created!');
return [];
}
);
expression
alone just returns a configuration object. we should compile
it in order to use it. See example:import { expression, compile } from 'chai-latte';
const ourLibrary = compile(
expression(
({ create }) => create.an.array(),
() => {
console.log('Array Created!');
return [];
}
)
);
//
const { create } = ourLibrary;
const arr = create.an.array(); // [] and logged 'Array Created!'.
compile
function. See example:const addNumToArray = (num: number, arr: any[]) => arr.push(num);
const createArray = () : any[]=> [];
const cloneArray = (arr: any[]) : any[] => [...arr];
const ourLibrary = compile(
expression(({ create }) => create.an.array(), createArray),
expression(({ create }) => create.a.copy.of(Array), cloneArray),
expression(({ add }) => add(Number).to.this.array(Array), addNumToArray),
expression(({ add }) => add(Number).to(Array), addNumToArray),
);
const { create, add } = ourLibrary;
const arr = create.an.array();
add(4).to.this.array(arr)
add(5).to(arr)
console.log(arr) // logs [4, 5]
const arr2 = create.a.copy.of(arr);
add(12).to(arr2);
console.log(arr2) // logs [4, 5, 12]
To make your library type-safe, you can generate the corresponding typings using the command line. It will create a new file called generated.ts
that will export the same fluent interface but fully typed. Then simply use this new file as your entry file!
To create the generated.ts
type this in the terminal:
npx chai-latte ./index.ts
// example
class Human {}
class Child extends Human {}
the(Human).can.jump(); // expression 1
the(Child).will.play(); // expression 2
// if we try to call
const human = new Human();
const child = new Child();
the(child).can.jump(); // <-- will work since Child inherits Human
the(human).will.play(); // <- won't work because .will.play() isn't defined for expression 1
// example
the(Human).works.up.until(Number);
the(Human).can.jump();
the(Human).is.alive // <- won't compile because it doesn't end with a function
// example
the(Human).can.say('Hi!');
the(Baby).can.say('Hi!'); // <- will work, because Human and Baby are different classes
the(Baby).can.say('Hi!').and.say('I\'m hungry'); // <- won't compile
You can generate the corresponding typings using the command line. It will create a new file called generated.ts
next to index.ts
.
This file will export yout same fluent interface but fully typed. Use this new file as your entry file to enjoy the typngs!
Ensure ts-node
is installed locally then type this in the terminal:
npx chai-latte
Thank you very much for considering to contribute!
Please don't hesitate to create issues and PRs. Your contribution is very much welcome!.
The MIT License
Copyright (c) 2022 Chai-Latte
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Build expressive & readable fluent interface libraries.
The npm package chai-latte receives a total of 3 weekly downloads. As such, chai-latte popularity was classified as not popular.
We found that chai-latte demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.