1
1
is-ipfs
2
2
====
3
3
4
- [ ![ build status ] ( https://secure.travis-ci.org/ ipfs/is-ipfs.svg )] ( http ://travis-ci.org /ipfs/is-ipfs)
5
- [ ![ dignified.js ] ( https://img.shields.io/badge/follows-dignified.js -blue.svg?style=flat-square )] ( https://github.com/dignifiedquire/dignified.js )
4
+ [ ![ ] ( https://img.shields.io/github/release/ ipfs/is-ipfs.svg )] ( https ://github.com /ipfs/is-ipfs/releases/latest )
5
+ [ ![ ] ( https://img.shields.io/badge/freenode-%23ipfs -blue.svg?style=flat-square )] ( https://webchat.freenode.net/?channels=%23ipfs )
6
6
7
- A set of utilities to help identify [ IPFS] ( https://ipfs.io/ ) resources.
7
+ > A set of utilities to help identify [ IPFS] ( https://ipfs.io/ ) resources
8
8
9
+ ## Lead Maintainer
9
10
10
- ## Install
11
+ [ Marcin Rataj] ( https://github.com/lidel )
12
+
13
+ # Install
11
14
12
15
### In Node.js through npm
13
16
@@ -34,7 +37,7 @@ Loading this module through a script tag will make the ```IsIpfs``` obj availabl
34
37
<script src="https://unpkg.com/is-ipfs/dist/index.js"></script>
35
38
```
36
39
37
- ## Usage
40
+ # Usage
38
41
``` javascript
39
42
const isIPFS = require (' is-ipfs' )
40
43
@@ -45,6 +48,9 @@ isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') // true (CIDv0)
45
48
isIPFS .cid (' zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7' ) // true (CIDv1)
46
49
isIPFS .cid (' noop' ) // false
47
50
51
+ isIPFS .base32cid (' bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va' ) // true
52
+ isIPFS .base32cid (' QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // false
53
+
48
54
isIPFS .url (' https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // true
49
55
isIPFS .url (' https://ipfs.io/ipns/github.com' ) // true
50
56
isIPFS .url (' https://github.com/ipfs/js-ipfs/blob/master/README.md' ) // false
@@ -71,9 +77,31 @@ isIPFS.ipfsPath('/ipfs/invalid-hash') // false
71
77
72
78
isIPFS .ipnsPath (' /ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // false
73
79
isIPFS .ipnsPath (' /ipns/github.com' ) // true
80
+
81
+ isIPFS .subdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link' ) // true
82
+ isIPFS .subdomain (' http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.ipns.dweb.link' ) // true
83
+ isIPFS .subdomain (' http://www.bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link' ) // false
84
+ isIPFS .subdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.dweb.link' ) // false
85
+
86
+ isIPFS .ipfsSubdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link' ) // true
87
+ isIPFS .ipfsSubdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.dweb.link' ) // false
88
+
89
+ isIPFS .ipnsSubdomain (' http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.ipns.dweb.link' ) // true
90
+ isIPFS .ipnsSubdomain (' http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.dweb.link' ) // false
91
+ isIPFS .ipnsSubdomain (' http://QmcNioXSC1bfJj1dcFErhUfyjFzoX2HodkRccsFFVJJvg8.ipns.dweb.link' ) // false
92
+ isIPFS .ipnsSubdomain (' http://foo-bar.ipns.dweb.link' ) // false (not a PeerID)
74
93
```
75
94
76
- ## API
95
+ # API
96
+
97
+ A suite of util methods that provides efficient validation.
98
+
99
+ Detection of IPFS Paths and identifiers in URLs is a two-stage process:
100
+ 1 . ` urlPattern ` /` pathPattern ` /` subdomainPattern ` regex is applied to quickly identify potential candidates
101
+ 2 . proper CID validation is applied to remove false-positives
102
+
103
+
104
+ ## Utils
77
105
78
106
### ` isIPFS.multihash(hash) `
79
107
@@ -83,17 +111,15 @@ Returns `true` if the provided string is a valid `multihash` or `false` otherwis
83
111
84
112
Returns ` true ` if the provided string is a valid ` CID ` or ` false ` otherwise.
85
113
86
- ### ` isIPFS.url(url ) `
114
+ ### ` isIPFS.base32cid(hash ) `
87
115
88
- Returns ` true ` if the provided string is a valid IPFS or IPNS url or ` false ` otherwise.
116
+ Returns ` true ` if the provided string is a valid ` CID ` in Base32 encoding or ` false ` otherwise.
89
117
90
- ### ` isIPFS.path(path) `
91
-
92
- Returns ` true ` if the provided string is a valid IPFS or IPNS path or ` false ` otherwise.
118
+ ## URLs
93
119
94
- ### ` isIPFS.urlOrPath(path ) `
120
+ ### ` isIPFS.url(url ) `
95
121
96
- Returns ` true ` if the provided string is a valid IPFS or IPNS url or path or ` false ` otherwise.
122
+ Returns ` true ` if the provided string is a valid IPFS or IPNS url or ` false ` otherwise.
97
123
98
124
### ` isIPFS.ipfsUrl(url) `
99
125
@@ -103,6 +129,19 @@ Returns `true` if the provided string is a valid IPFS url or `false` otherwise.
103
129
104
130
Returns ` true ` if the provided string is a valid IPNS url or ` false ` otherwise.
105
131
132
+ ## Paths
133
+
134
+ Standalone validation of IPFS Paths: ` /ip(f|n)s/<cid>/.. `
135
+
136
+ ### ` isIPFS.path(path) `
137
+
138
+ Returns ` true ` if the provided string is a valid IPFS or IPNS path or ` false ` otherwise.
139
+
140
+ ### ` isIPFS.urlOrPath(path) `
141
+
142
+ Returns ` true ` if the provided string is a valid IPFS or IPNS url or path or ` false ` otherwise.
143
+
144
+
106
145
### ` isIPFS.ipfsPath(path) `
107
146
108
147
Returns ` true ` if the provided string is a valid IPFS path or ` false ` otherwise.
@@ -111,10 +150,23 @@ Returns `true` if the provided string is a valid IPFS path or `false` otherwise.
111
150
112
151
Returns ` true ` if the provided string is a valid IPNS path or ` false ` otherwise.
113
152
153
+ ## Subdomains
154
+
155
+ Validated subdomain convention: ` cidv1b32.ip(f|n)s.domain.tld `
156
+
157
+ ### ` isIPFS.subdomain(url) `
158
+
159
+ Returns ` true ` if the provided string includes a valid IPFS or IPNS subdomain or ` false ` otherwise.
160
+
161
+ ### ` isIPFS.ipfsSubdomain(url) `
162
+
163
+ Returns ` true ` if the provided string includes a valid IPFS subdomain or ` false ` otherwise.
164
+
165
+ ### ` isIPFS.ipnsSubdomain(url) `
114
166
115
- ** Note: ** the regex used for these checks is also exported as ` isIPFS.urlPattern `
167
+ Returns ` true ` if the provided string includes a valid IPNS subdomain or ` false ` otherwise.
116
168
117
- ## License
118
169
170
+ # License
119
171
120
172
MIT
0 commit comments