1.1.3 • Public • Published

Flourish pocket knife 🇨🇭

A module with handy tools that you can use in Flourish templates.

import { isUrl, isImage } from "@flourish/pocket-knife"



Checks if string looks like valid URL. Returns true or false


Checks if string looks like valid image URL. Returns true or false

getTextDimensions(string, font)

Gets dimensions of text. First argument contains the text you want to calculate the width for. The second argument is optional and lets you set font settings for the text in the standard css font property, eg. bold 16px arial. If font is empty, it uses 10px sans-serif. Returns an object with properties width and height.

getTextWidth(string, font)

Gets width of text. Uses same arguments as getTextDimensions. Returns a number.

getTextHeight(string, font)

Gets height of text. Uses same arguments as getTextDimensions. Returns a number.


Gets computed text direction on document.body. Returns a "ltr" or "rtl".

hexToColor(hex_string, opacity)

Converts hex to d3 color object as described here

hexToColor("#00ff00", 0.5); // {r: 0, g: 255, b: 0, a: 0.5}

hexToRgba(hex_string, opacity)

Converts hex to rgba string

hexToRgba("#00ff00", 0.5); // rgba(0, 255, 0, 0.5)


Returns if color is pale or not


Converts value specified in rems to px

wrapStringToLines(label, label_styles, text_max_lines, max_width)

Takes a string, and returns an array of strings where each string is one lines worth of text.

  • Label is a string, that you want to be broken up into lines
  • label_styles is a string that can include font weight, font size and font family in the structure: 'bold 48px serif'. it is what is given to the canvas context font method, and is used to measure the text.
  • text_max_lines is a number that says the maximum amount of lines you want (if you dont have a maximum you can give it null)
  • max_width is a number that states in px the maximum width for the label.

getUniqueValuesFromBinding(data, binding, index)

Gets all the unique values in a column associated to a data binding. If it is a multi column binding you can pass in index that is used to work out which of the bound columns it should look at. If you pass it no index and it is a multi column binding it will default to zero.




npm i @flourish/pocket-knife

DownloadsWeekly Downloads






Unpacked Size

11.4 kB

Total Files


Last publish


  • jwitcombe
  • katietannercanva
  • b3n-canva
  • caletilford
  • flourish-canva
  • declanvong
  • florin.oprina
  • robinhouston
  • duncanclark
  • daanlouter
  • hughsk
  • mark-kiln
  • animateddata
  • larsvers
  • luptilu
  • bobbysebolao
  • liakouras
  • oliviajanelawlor
  • hrobertson
  • chrisnewell
  • oampo
  • sebr
  • wearymonkey
  • mattcarter-canva
  • marcfallows
  • mafecafe
  • connormj
  • simonaats