[jinja] Add support for dictsort filter (#1825)
- Understand the dictsort filter specification from Jinja docs
- Implement the dictsort filter in runtime.ts for ObjectValue
- Add tests for dictsort filter with various parameters
- Test the implementation with edge cases
- Run lint and build to ensure code quality
- Refactor to eliminate code duplication by extracting helper method
- Improve null/undefined handling in sort comparisons
- Add documentation for type handling assumptions
- Move dictsort logic to ObjectValue builtins as FunctionValue per @xenova’s feedback
- Extract index calculation to avoid duplication
Original prompt
On jinja, Add support for the
dictsort. jinja filter to @huggingface/jinja package. Here are the docs for the feature: https://jinja.palletsprojects.com/en/stable/templates/#jinja-filters.dictsort
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Co-authored-by: copilot-swe-agent[bot] 198982749+Copilot@users.noreply.github.com Co-authored-by: xenova 26504141+xenova@users.noreply.github.com Co-authored-by: Joshua Lochner admin@xenova.com
Hugging Face JS libraries
This is a collection of JS libraries to interact with the Hugging Face API, with TS types included.
mini_headeroutside Hugging FaceWe use modern features to avoid polyfills and dependencies, so the libraries will only work on modern browsers / Node.js >= 18 / Bun / Deno.
The libraries are still very young, please help us by opening issues!
Installation
From NPM
To install via NPM, you can download the libraries as needed:
Then import the libraries in your code:
From CDN or Static hosting
You can run our packages with vanilla JS, without any bundler, by using a CDN or static hosting. Using ES modules, i.e.
<script type="module">, you can import the libraries in your code:Deno
Usage examples
Get your HF access token in your account settings.
@huggingface/inference examples
@huggingface/hub examples
@huggingface/mcp-client example
There are more features of course, check each library’s README!
Formatting & testing
Building
This will generate ESM and CJS javascript files in
packages/*/dist, egpackages/inference/dist/index.mjs.