Beautify Path

You can beautify the ā€œdā€ property of a given path element using the beautifyPath() function. It receives an optional decimalPlaces parameter with the default value equals to 2 decimal places after the dot.

import { beautifyPath } from 'mz-svg';

const d = beautifyPath(`M233.51,56.8c-0.57,0.24-1.33,0.52-2.28,0.86c-0.95,0.33-1.93,0.5-2.92,0.5s-1.84-0.27-2.53-0.82
	c-0.69-0.55-1.03-1.49-1.03-2.82V36.25h7.85V28.9h-7.85V16.77h-9.56V28.9h-17.84V16.77h-9.56V28.9h-4.92v7.35h4.92v21.48
	c0,1.67,0.26,3.08,0.79,4.25c0.52,1.17,1.22,2.12,2.1,2.85c0.88,0.74,1.9,1.27,3.07,1.61c1.16,0.33,2.41,0.5,3.75,0.5
	c2.05,0,4-0.28,5.85-0.86c1.86-0.57,3.42-1.14,4.71-1.71l-1.93-7.56c-0.57,0.24-1.33,0.52-2.28,0.86c-0.95,0.33-1.93,0.5-2.92,0.5
	c-1,0-1.84-0.27-2.53-0.82c-0.69-0.55-1.03-1.49-1.03-2.82V36.25h17.84v21.48c0,1.67,0.26,3.08,0.79,4.25
	c0.52,1.17,1.22,2.12,2.1,2.85c0.88,0.74,1.9,1.27,3.07,1.61c1.16,0.33,2.41,0.5,3.75,0.5c2.05,0,4-0.28,5.85-0.86
	c1.86-0.57,3.42-1.14,4.71-1.71L233.51,56.8z`); 


// The result is: -------------------
/*
M 233.51 56.8 c -0.57 0.24 -1.33 0.52 -2.28 0.86 c -0.95 0.33 -1.93 0.5 -2.92 0.5 s -1.84 -0.27 -2.53 -0.82 c -0.69 -0.55 -1.03 -1.49 -1.03 -2.82 V 36.25 h 7.85 V 28.9 h -7.85 V 16.77 h -9.56 V 28.9 h -17.84 V 16.77 h -9.56 V 28.9 h -4.92 v 7.35 h 4.92 v 21.48 c 0 1.67 0.26 3.08 0.79 4.25 c 0.52 1.17 1.22 2.12 2.1 2.85 c 0.88 0.74 1.9 1.27 3.07 1.61 c 1.16 0.33 2.41 0.5 3.75 0.5 c 2.05 0 4 -0.28 5.85 -0.86 c 1.86 -0.57 3.42 -1.14 4.71 -1.71 l -1.93 -7.56 c -0.57 0.24 -1.33 0.52 -2.28 0.86 c -0.95 0.33 -1.93 0.5 -2.92 0.5 c -1 0 -1.84 -0.27 -2.53 -0.82 c -0.69 -0.55 -1.03 -1.49 -1.03 -2.82 V 36.25 h 17.84 v 21.48 c 0 1.67 0.26 3.08 0.79 4.25 c 0.52 1.17 1.22 2.12 2.1 2.85 c 0.88 0.74 1.9 1.27 3.07 1.61 c 1.16 0.33 2.41 0.5 3.75 0.5 c 2.05 0 4 -0.28 5.85 -0.86 c 1.86 -0.57 3.42 -1.14 4.71 -1.71 L 233.51 56.8 z
 */

To allow any number of decimal places, pass Infinity as a parameter.