Gathering detailed insights and metrics for text2svg
Gathering detailed insights and metrics for text2svg
Gathering detailed insights and metrics for text2svg
Gathering detailed insights and metrics for text2svg
npm install text2svg
Typescript
Module System
Node Version
NPM Version
69.2
Supply Chain
98.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
9,863
Last Day
6
Last Week
45
Last Month
167
Last Year
2,773
MIT License
35 Stars
19 Commits
6 Forks
6 Watchers
1 Branches
1 Contributors
Updated on Oct 01, 2024
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
text2svg@1.0.1
Unpacked Size
12.72 kB
Size
4.55 kB
File Count
4
NPM Version
8.13.2
Node Version
16.14.0
Cumulative downloads
Total Downloads
Last Day
500%
6
Compared to previous day
Last Week
45.2%
45
Compared to previous week
Last Month
-21.6%
167
Compared to previous month
Last Year
95.6%
2,773
Compared to previous year
1
Convert text to svg path
$ npm install --save text2svg
1var Text2svg = require('text2svg'); 2var text2svg = new Text2svg('localFontPath'); 3var svg = text2svg.toSVG('something', options);
There are three ways to get an instance of Text2svg
:
The callback
function looks like:
1function (text2svg) { 2 // ... 3}
Convert the text
to path data, which is the attribute value of d
in the <path>
element. Return:
1{ 2 width : width, // Int, total width 3 height : height, // Int, total Height 4 pathData: pathData // Array/String 5}
If options.divided
is true
the pathData will be an Array.
Convert the text
to <path>
element(s). Return:
1{ 2 width : width, // Int, total width 3 height : height, // Int, total Height 4 pathData: pathData // Array/String 5 path : path // Array/String 6}
Convert the text
to <svg>
element. Return:
1{ 2 width : width, // Int, total width 3 height : height, // Int, total Height 4 pathData: pathData // Array/String 5 path : path // Array/String 6 svg : svg // String 7}
Horizontal position of the beginning of the text. (default: 0)
Vertical position of the baseline of the text. (default: 0)
Size of the text. (default: 72)
The letter spacing. (default: 0)
If true
takes kerning
information into account. (default: true
)
If true
generates individual path for every char. (default: false
)
If true
groups the individual <path>
with <g></g>
element. (default: false
)
This option only works for toSVG()
.
If specified will generate a <title>
at the root of <svg>
. (default: text
)
This option only works for toSVG()
.
If specified will generate a <desc>
at the root of <svg>
. (default: null
)
This option only works for toSVG()
.
Specify the padding of the <path>
relative to the <svg>
:
The <svg>
, <path>
and <g>
elements can be styled by any valid attributes.
The generated <svg>
has the following default attributes:
1{ 2 'version' : '1.1', 3 'xmlns' : 'http://www.w3.org/2000/svg', 4 'xmlns:xlink': 'http://www.w3.org/1999/xlink', 5 'role' : 'img', 6 'width' : width, 7 'height' : height, 8 'viewbox': [x, y, width, height].join(' ') 9}
We can add/update/remove by options.svg
:
1options.svg = { 2 'version': '', // remove this attribute 3 'role' : 'logo', // update this attribute 4 'fill' : 'red' // add some custiom styles 5}
Note that the width
, height
and viewbox
can't be specified.
Styling the <path>
by options.path
. If divided
is true
we can style the individual <path>
element by options.path?
, which ?
is the index of each char in the text
:
1// style for every path(s) 2options.path = { 3 'fill': yellow 4}; 5 6// style the first char 7options.path0 = { 8 'fill': '#FF0000', 9 'stroke': '#000000' 10};
As the same options.g
specified the style of <g>
element.
README.md
.Pull requests and stars are highly welcome.
For bugs and feature requests, please create an issue.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-04-21
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More