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

thurl

v0.1.1

Published

Thumbor URL builder

Downloads

5

Readme

Thurl - Thumbor Url Builder

Simple thumbor url builder that supports all adjustments in a single function call and can be used securely with HMAC or insecurely.

Installation

Using NPM

npm install --save thurl

Using Yarn

yarn add thurl

Setup

Load the package and create an instance with your base thumbor url and security key if using secure urls.

const thurl = new Thurl('<thumbor url>', '<thumbor security key>');

Secure

Use thumbor in secure (hmac) mode by providing the thumbor security key when initialising Thurl. It is not recommended to use a security key is using this library within the browser as the security key will be exposed.

ES6

import Thurl from 'thurl';
const thurl = new Thurl('http://thumbor.mydomain.com', 'abcdefghijklmnopqrstuvwxyz123');

CommonJS

const Thurl = require('../lib/index.js');
const thurl = new Thurl('http://thumbor.mydomain.com', 'abcdefghijklmnopqrstuvwxyz123');

CommonJS as a one liner

const thurl = new (require('../lib/index.js'))('http://thumbor.mydomain.com', 'abcdefghijklmnopqrstuvwxyz123')

Insecure

You can use thumbor in unsafe / insecure mode by omitting the key when initialising Thurl.

ES6

const Thurl = import 'thurl';
const thurl = new Thurl('http://thumbor.mydomain.com');

CommonJS

const Thurl = require('../lib/index.js');
const thurl = new Thurl('http://thumbor.mydomain.com');

Usage

thurl.build('image', {adjustments})

All thumbor adjustments are supported in the adjustments object provided to the build function. e.g. thurl.build('image.jpg', {property: value})

Simple Adjustments

|Property |Type |Default |Usage | |---|---|---|---| |trim |Boolean |false |{trim: true} | |crop |Object |null |{crop: {left: 1, top: 1, right: 1, bottom: 1}} | |fit |String |null |{fit: 'fit-in'} | |width |Number |null |{width: 100}} | |height |Number |null |{height: 100}} | |halign |String |null |{halign: 'center'}} | |valign |String |null |{valign: 'middle'}} | |smart |Boolean |false |{smart: true} | |filter* |String or Array |null | *Read filters section |

Simple Adjustment Examples:

// Url: 
const imageUrl = thurl.build('image.jpg')
// imageUrl = 'http://thumbor.mydomain.com/<hmac|unsafe>/image.jpg'

// Resize: 
const thumbnail = thurl.build('image.jpg', {width: 100, height: 100})
// thumbnail = 'http://thumbor.mydomain.com/<hmac|unsafe>/100x100/image.jpg'

// Resize & Crop: 
const thumbnail = thurl.build('image.jpg', {
    crop: { left: 5, top: 10, right: 15, bottom: 20 },
    width: 100, 
    height: 100
})
// thumbnail = 'http://thumbor.mydomain.com/<hmac|unsafe>/5x10:15x20/100x100/image.jpg'

See https://thumbor.readthedocs.io/en/latest/usage.html for all adjustments.

Filters

You can use any thumbor filter by specifying the name and providing the filter properties as a string, number or array of properties.

Example {blur: '12,25'} {blur: [12,25]} {brightness: -100} {brightness: '-100'} {brightness: [-100]} are all valid.

Filter Examples:

// Blur: 
const imageUrl = thurl.build('image.jpg', {blur: [12,25]})
// imageUrl = 'http://thumbor.mydomain.com/<hmac|unsafe>/filters:blur(12,25)/image.jpg'

// Blur & Resize: 
const thumbnail = thurl.build('image.jpg', {width: 100, height: 100, blur: '12,25'})
// thumbnail = 'http://thumbor.mydomain.com/<hmac|unsafe>/100x100/filters:blur(12,25)/image.jpg'

// Resize & Watermark
const imageUrl = thurl.build('image.jpg', {width: 1024, watermark: ['http:/www.abc.com/img.png', -10, -11, 15, 25, 20]})
// imageUrl = 'http://thumbor.mydomain.com/<hmac|unsafe>/1024x/filters:watermark(http:/www.abc.com/img.png,-10,-11,15,25,20)/image.jpg'

See https://thumbor.readthedocs.io/en/latest/filters.html form more information about filters.