Skip to main content

getLength()

Part of the @remotion/paths package.

Gets the length of an SVG path. The argument must be a valid SVG path property.

A number is returned if the path is valid:

tsx
import { getLength } from "@remotion/paths";
 
const length = getLength("M 0 0 L 100 0");
console.log(length); // 100
tsx
import { getLength } from "@remotion/paths";
 
const length = getLength("M 0 0 L 100 0");
console.log(length); // 100

The function will throw if the path is invalid:

tsx
getLength("remotion"); // Error: Malformed path data: ...
tsx
getLength("remotion"); // Error: Malformed path data: ...

Credits

Source code stems mostly from svg-path-properties.

See also