@@ -10,7 +10,7 @@ is-ipfs
10
10
11
11
[ Marcin Rataj] ( https://github.com/lidel )
12
12
13
- ## Install
13
+ # Install
14
14
15
15
### In Node.js through npm
16
16
@@ -37,17 +37,25 @@ Loading this module through a script tag will make the ```IsIpfs``` obj availabl
37
37
<script src="https://unpkg.com/is-ipfs/dist/index.js"></script>
38
38
```
39
39
40
- ## Usage
40
+ # Usage
41
41
``` javascript
42
42
const isIPFS = require (' is-ipfs' )
43
43
44
44
isIPFS .multihash (' QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // true
45
45
isIPFS .multihash (' noop' ) // false
46
46
47
+ isIPFS .multibase (' bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va' ) // 'base32'
48
+ isIPFS .multibase (' zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7' ) // 'base58btc'
49
+ isIPFS .multibase (' QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // false (no multibase prefix in CIDv0)
50
+ isIPFS .multibase (' noop' ) // false
51
+
47
52
isIPFS .cid (' QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // true (CIDv0)
48
53
isIPFS .cid (' zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7' ) // true (CIDv1)
49
54
isIPFS .cid (' noop' ) // false
50
55
56
+ isIPFS .base32cid (' bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va' ) // true
57
+ isIPFS .base32cid (' QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // false
58
+
51
59
isIPFS .url (' https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // true
52
60
isIPFS .url (' https://ipfs.io/ipns/github.com' ) // true
53
61
isIPFS .url (' https://github.com/ipfs/js-ipfs/blob/master/README.md' ) // false
@@ -74,29 +82,52 @@ isIPFS.ipfsPath('/ipfs/invalid-hash') // false
74
82
75
83
isIPFS .ipnsPath (' /ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o' ) // false
76
84
isIPFS .ipnsPath (' /ipns/github.com' ) // true
85
+
86
+ isIPFS .subdomain (' http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.ipns.dweb.link' ) // true
87
+ isIPFS .subdomain (' http://www.bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link' ) // false
88
+ isIPFS .subdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.dweb.link' ) // false
89
+
90
+ isIPFS .ipfsSubdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.ipfs.dweb.link' ) // true
91
+ isIPFS .ipfsSubdomain (' http://bafybeie5gq4jxvzmsym6hjlwxej4rwdoxt7wadqvmmwbqi7r27fclha2va.dweb.link' ) // false
92
+
93
+ isIPFS .ipnsSubdomain (' http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.ipns.dweb.link' ) // true
94
+ isIPFS .ipnsSubdomain (' http://bafybeiabc2xofh6tdi6vutusorpumwcikw3hf3st4ecjugo6j52f6xwc6q.dweb.link' ) // false
95
+ isIPFS .ipnsSubdomain (' http://QmcNioXSC1bfJj1dcFErhUfyjFzoX2HodkRccsFFVJJvg8.ipns.dweb.link' ) // false
96
+ isIPFS .ipnsSubdomain (' http://foo-bar.ipns.dweb.link' ) // false (not a PeerID)
77
97
```
78
98
79
- ## API
99
+ # API
100
+
101
+ A suite of util methods provides efficient validation.
102
+
103
+ Detection of IPFS Paths and identifiers in URLs is a two-stage process:
104
+ 1 . ` urlPattern ` /` pathPattern ` /` subdomainPattern ` regex is applied to quickly identify potential candidates
105
+ 2 . proper CID validation is applied to remove false-positives
106
+
107
+
108
+ ## Utils
80
109
81
110
### ` isIPFS.multihash(hash) `
82
111
83
112
Returns ` true ` if the provided string is a valid ` multihash ` or ` false ` otherwise.
84
113
114
+ ### ` isIPFS.multibase(cid) `
115
+
116
+ Returns a string with multibase name if the provided CID has ` multibase ` prefix or ` false ` otherwise.
117
+
85
118
### ` isIPFS.cid(hash) `
86
119
87
120
Returns ` true ` if the provided string is a valid ` CID ` or ` false ` otherwise.
88
121
89
- ### ` isIPFS.url(url ) `
122
+ ### ` isIPFS.base32cid(hash ) `
90
123
91
- Returns ` true ` if the provided string is a valid IPFS or IPNS url or ` false ` otherwise.
124
+ Returns ` true ` if the provided string is a valid ` CID ` in Base32 encoding or ` false ` otherwise.
92
125
93
- ### ` isIPFS.path(path) `
126
+ ## URLs
94
127
95
- Returns ` true ` if the provided string is a valid IPFS or IPNS path or ` false ` otherwise.
96
-
97
- ### ` isIPFS.urlOrPath(path) `
128
+ ### ` isIPFS.url(url) `
98
129
99
- Returns ` true ` if the provided string is a valid IPFS or IPNS url or path or ` false ` otherwise.
130
+ Returns ` true ` if the provided string is a valid IPFS or IPNS url or ` false ` otherwise.
100
131
101
132
### ` isIPFS.ipfsUrl(url) `
102
133
@@ -106,6 +137,19 @@ Returns `true` if the provided string is a valid IPFS url or `false` otherwise.
106
137
107
138
Returns ` true ` if the provided string is a valid IPNS url or ` false ` otherwise.
108
139
140
+ ## Paths
141
+
142
+ Standalone validation of IPFS Paths: ` /ip(f|n)s/<cid>/.. `
143
+
144
+ ### ` isIPFS.path(path) `
145
+
146
+ Returns ` true ` if the provided string is a valid IPFS or IPNS path or ` false ` otherwise.
147
+
148
+ ### ` isIPFS.urlOrPath(path) `
149
+
150
+ Returns ` true ` if the provided string is a valid IPFS or IPNS url or path or ` false ` otherwise.
151
+
152
+
109
153
### ` isIPFS.ipfsPath(path) `
110
154
111
155
Returns ` true ` if the provided string is a valid IPFS path or ` false ` otherwise.
@@ -114,10 +158,23 @@ Returns `true` if the provided string is a valid IPFS path or `false` otherwise.
114
158
115
159
Returns ` true ` if the provided string is a valid IPNS path or ` false ` otherwise.
116
160
161
+ ## Subdomains
162
+
163
+ Validated subdomain convention: ` cidv1b32.ip(f|n)s.domain.tld `
164
+
165
+ ### ` isIPFS.subdomain(url) `
166
+
167
+ Returns ` true ` if the provided string includes a valid IPFS or IPNS subdomain or ` false ` otherwise.
168
+
169
+ ### ` isIPFS.ipfsSubdomain(url) `
170
+
171
+ Returns ` true ` if the provided string includes a valid IPFS subdomain or ` false ` otherwise.
172
+
173
+ ### ` isIPFS.ipnsSubdomain(url) `
117
174
118
- ** Note: ** the regex used for these checks is also exported as ` isIPFS.urlPattern `
175
+ Returns ` true ` if the provided string includes a valid IPNS subdomain or ` false ` otherwise.
119
176
120
- ## License
121
177
178
+ # License
122
179
123
180
MIT
0 commit comments