Debian Codegraph @

node/detect-libc/README.md

raw
1 # detect-libc
2
3 Node.js module to detect details of the C standard library (libc)
4 implementation provided by a given Linux system.
5
6 Currently supports detection of GNU glibc and MUSL libc.
7
8 Provides asychronous and synchronous functions for the
9 family (e.g. `glibc`, `musl`) and version (e.g. `1.23`, `1.2.3`).
10
11 The version numbers of libc implementations
12 are not guaranteed to be semver-compliant.
13
14 For previous v1.x releases, please see the
15 [v1](https://github.com/lovell/detect-libc/tree/v1) branch.
16
17 ## Install
18
19 ```sh
20 npm install detect-libc
21 ```
22
23 ## API
24
25 ### GLIBC
26
27 ```ts
28 const GLIBC: string = 'glibc';
29 ```
30
31 A String constant containing the value `glibc`.
32
33 ### MUSL
34
35 ```ts
36 const MUSL: string = 'musl';
37 ```
38
39 A String constant containing the value `musl`.
40
41 ### family
42
43 ```ts
44 function family(): Promise<string | null>;
45 ```
46
47 Resolves asychronously with:
48
49 * `glibc` or `musl` when the libc family can be determined
50 * `null` when the libc family cannot be determined
51 * `null` when run on a non-Linux platform
52
53 ```js
54 const { family, GLIBC, MUSL } = require('detect-libc');
55
56 switch (await family()) {
57 case GLIBC: ...
58 case MUSL: ...
59 case null: ...
60 }
61 ```
62
63 ### familySync
64
65 ```ts
66 function familySync(): string | null;
67 ```
68
69 Synchronous version of `family()`.
70
71 ```js
72 const { familySync, GLIBC, MUSL } = require('detect-libc');
73
74 switch (familySync()) {
75 case GLIBC: ...
76 case MUSL: ...
77 case null: ...
78 }
79 ```
80
81 ### version
82
83 ```ts
84 function version(): Promise<string | null>;
85 ```
86
87 Resolves asychronously with:
88
89 * The version when it can be determined
90 * `null` when the libc family cannot be determined
91 * `null` when run on a non-Linux platform
92
93 ```js
94 const { version } = require('detect-libc');
95
96 const v = await version();
97 if (v) {
98 const [major, minor, patch] = v.split('.');
99 }
100 ```
101
102 ### versionSync
103
104 ```ts
105 function versionSync(): string | null;
106 ```
107
108 Synchronous version of `version()`.
109
110 ```js
111 const { versionSync } = require('detect-libc');
112
113 const v = versionSync();
114 if (v) {
115 const [major, minor, patch] = v.split('.');
116 }
117 ```
118
119 ### isNonGlibcLinux
120
121 ```ts
122 function isNonGlibcLinux(): Promise<boolean>;
123 ```
124
125 Resolves asychronously with:
126
127 * `false` when the libc family is `glibc`
128 * `true` when the libc family is not `glibc`
129 * `false` when run on a non-Linux platform
130
131 ```js
132 const { isNonGlibcLinux } = require('detect-libc');
133
134 if (await isNonGlibcLinux()) { ... }
135 ```
136
137 ### isNonGlibcLinuxSync
138
139 ```ts
140 function isNonGlibcLinuxSync(): boolean;
141 ```
142
143 Synchronous version of `isNonGlibcLinux()`.
144
145 ```js
146 const { isNonGlibcLinuxSync } = require('detect-libc');
147
148 if (isNonGlibcLinuxSync()) { ... }
149 ```
150
151 ## Licensing
152
153 Copyright 2017 Lovell Fuller and others.
154
155 Licensed under the Apache License, Version 2.0 (the "License");
156 you may not use this file except in compliance with the License.
157 You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
158
159 Unless required by applicable law or agreed to in writing, software
160 distributed under the License is distributed on an "AS IS" BASIS,
161 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
162 See the License for the specific language governing permissions and
163 limitations under the License.