Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
937 bytes
|
Line | |
---|
1 | var prefix = function (name) {
|
---|
2 | return '_' + name
|
---|
3 | }
|
---|
4 |
|
---|
5 | var defined = function (name) {
|
---|
6 | return name
|
---|
7 | }
|
---|
8 |
|
---|
9 | exports.stringify = function (data) {
|
---|
10 | if (typeof data === 'object' && data && data.name) return exports.stringify(data.name, data.protocol, data.subtypes)
|
---|
11 | return Array.prototype.concat.apply([], arguments).filter(defined).map(prefix).join('.')
|
---|
12 | }
|
---|
13 |
|
---|
14 | exports.parse = function (str) {
|
---|
15 | var parts = str.split('.')
|
---|
16 |
|
---|
17 | for (var i = 0; i < parts.length; i++) {
|
---|
18 | if (parts[i][0] !== '_') continue
|
---|
19 | parts[i] = parts[i].slice(1)
|
---|
20 | }
|
---|
21 |
|
---|
22 | return {
|
---|
23 | name: parts.shift(),
|
---|
24 | protocol: parts.shift() || null,
|
---|
25 | subtypes: parts
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | exports.tcp = function (name) {
|
---|
30 | return exports.stringify(name, 'tcp', Array.prototype.concat.apply([], Array.prototype.slice.call(arguments, 1)))
|
---|
31 | }
|
---|
32 |
|
---|
33 | exports.udp = function (name) {
|
---|
34 | return exports.stringify(name, 'udp', Array.prototype.concat.apply([], Array.prototype.slice.call(arguments, 1)))
|
---|
35 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.