UNPKG
is-svg-path
Version:
latest (1.0.2)
1.0.2
1.0.1
1.0.0
Detect if string an SVG path
github.com/dfcreative/is-svg-path
dfcreative/is-svg-path
is-svg-path
/
index.js
13 lines
(8 loc)
•
310 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
'use strict'
module
.
exports
=
function
isPath
(
str
) {
if
(
typeof
str !==
'string'
)
return
false
str = str.
trim
()
// https://www.w3.org/TR/SVG/paths.html#PathDataBNF
if
(
/^[mzlhvcsqta]\s*[-+.0-9][^mlhvzcsqta]+/i
.
test
(str) &&
/[\dz]$/i
.
test
(str) && str.
length
>
4
)
return
true
return
false
}