Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <!--
  2. -- This file is auto-generated from README_js.md. Changes should be made there.
  3. -->
  4. # uuid [![CI](https://github.com/uuidjs/uuid/workflows/CI/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [![Browser](https://github.com/uuidjs/uuid/workflows/Browser/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ABrowser)
  5. For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs
  6. - **Complete** - Support for RFC4122 version 1, 3, 4, and 5 UUIDs
  7. - **Cross-platform** - Support for ...
  8. - CommonJS, [ECMAScript Modules](#ecmascript-modules) and [CDN builds](#cdn-builds)
  9. - Node 8, 10, 12, 14
  10. - Chrome, Safari, Firefox, Edge, IE 11 browsers
  11. - Webpack and rollup.js module bundlers
  12. - [React Native / Expo](#react-native--expo)
  13. - **Secure** - Cryptographically-strong random values
  14. - **Small** - Zero-dependency, small footprint, plays nice with "tree shaking" packagers
  15. - **CLI** - Includes the [`uuid` command line](#command-line) utility
  16. **Upgrading from `uuid@3.x`?** Your code is probably okay, but check out [Upgrading From `uuid@3.x`](#upgrading-from-uuid3x) for details.
  17. ## Quickstart
  18. To create a random UUID...
  19. **1. Install**
  20. ```shell
  21. npm install uuid
  22. ```
  23. **2. Create a UUID** (ES6 module syntax)
  24. ```javascript
  25. import { v4 as uuidv4 } from 'uuid';
  26. uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
  27. ```
  28. ... or using CommonJS syntax:
  29. ```javascript
  30. const { v4: uuidv4 } = require('uuid');
  31. uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
  32. ```
  33. For timestamp UUIDs, namespace UUIDs, and other options read on ...
  34. ## API Summary
  35. | | | |
  36. | --- | --- | --- |
  37. | [`uuid.NIL`](#uuidnil) | The nil UUID string (all zeros) | New in `uuid@8.3` |
  38. | [`uuid.parse()`](#uuidparsestr) | Convert UUID string to array of bytes | New in `uuid@8.3` |
  39. | [`uuid.stringify()`](#uuidstringifyarr-offset) | Convert array of bytes to UUID string | New in `uuid@8.3` |
  40. | [`uuid.v1()`](#uuidv1options-buffer-offset) | Create a version 1 (timestamp) UUID | |
  41. | [`uuid.v3()`](#uuidv3name-namespace-buffer-offset) | Create a version 3 (namespace w/ MD5) UUID | |
  42. | [`uuid.v4()`](#uuidv4options-buffer-offset) | Create a version 4 (random) UUID | |
  43. | [`uuid.v5()`](#uuidv5name-namespace-buffer-offset) | Create a version 5 (namespace w/ SHA-1) UUID | |
  44. | [`uuid.validate()`](#uuidvalidatestr) | Test a string to see if it is a valid UUID | New in `uuid@8.3` |
  45. | [`uuid.version()`](#uuidversionstr) | Detect RFC version of a UUID | New in `uuid@8.3` |
  46. ## API
  47. ### uuid.NIL
  48. The nil UUID string (all zeros).
  49. Example:
  50. ```javascript
  51. import { NIL as NIL_UUID } from 'uuid';
  52. NIL_UUID; // ⇨ '00000000-0000-0000-0000-000000000000'
  53. ```
  54. ### uuid.parse(str)
  55. Convert UUID string to array of bytes
  56. | | |
  57. | --------- | ---------------------------------------- |
  58. | `str` | A valid UUID `String` |
  59. | _returns_ | `Uint8Array[16]` |
  60. | _throws_ | `TypeError` if `str` is not a valid UUID |
  61. Note: Ordering of values in the byte arrays used by `parse()` and `stringify()` follows the left &Rarr; right order of hex-pairs in UUID strings. As shown in the example below.
  62. Example:
  63. ```javascript
  64. import { parse as uuidParse } from 'uuid';
  65. // Parse a UUID
  66. const bytes = uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b');
  67. // Convert to hex strings to show byte order (for documentation purposes)
  68. [...bytes].map((v) => v.toString(16).padStart(2, '0')); // ⇨
  69. // [
  70. // '6e', 'c0', 'bd', '7f',
  71. // '11', 'c0', '43', 'da',
  72. // '97', '5e', '2a', '8a',
  73. // 'd9', 'eb', 'ae', '0b'
  74. // ]
  75. ```
  76. ### uuid.stringify(arr[, offset])
  77. Convert array of bytes to UUID string
  78. | | |
  79. | -------------- | ---------------------------------------------------------------------------- |
  80. | `arr` | `Array`-like collection of 16 values (starting from `offset`) between 0-255. |
  81. | [`offset` = 0] | `Number` Starting index in the Array |
  82. | _returns_ | `String` |
  83. | _throws_ | `TypeError` if a valid UUID string cannot be generated |
  84. Note: Ordering of values in the byte arrays used by `parse()` and `stringify()` follows the left &Rarr; right order of hex-pairs in UUID strings. As shown in the example below.
  85. Example:
  86. ```javascript
  87. import { stringify as uuidStringify } from 'uuid';
  88. const uuidBytes = [
  89. 0x6e,
  90. 0xc0,
  91. 0xbd,
  92. 0x7f,
  93. 0x11,
  94. 0xc0,
  95. 0x43,
  96. 0xda,
  97. 0x97,
  98. 0x5e,
  99. 0x2a,
  100. 0x8a,
  101. 0xd9,
  102. 0xeb,
  103. 0xae,
  104. 0x0b,
  105. ];
  106. uuidStringify(uuidBytes); // ⇨ '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'
  107. ```
  108. ### uuid.v1([options[, buffer[, offset]]])
  109. Create an RFC version 1 (timestamp) UUID
  110. | | |
  111. | --- | --- |
  112. | [`options`] | `Object` with one or more of the following properties: |
  113. | [`options.node` ] | RFC "node" field as an `Array[6]` of byte values (per 4.1.6) |
  114. | [`options.clockseq`] | RFC "clock sequence" as a `Number` between 0 - 0x3fff |
  115. | [`options.msecs`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) |
  116. | [`options.nsecs`] | RFC "timestamp" field (`Number` of nanseconds to add to `msecs`, should be 0-10,000) |
  117. | [`options.random`] | `Array` of 16 random bytes (0-255) |
  118. | [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
  119. | [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
  120. | [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
  121. | _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
  122. | _throws_ | `Error` if more than 10M UUIDs/sec are requested |
  123. Note: The default [node id](https://tools.ietf.org/html/rfc4122#section-4.1.6) (the last 12 digits in the UUID) is generated once, randomly, on process startup, and then remains unchanged for the duration of the process.
  124. Note: `options.random` and `options.rng` are only meaningful on the very first call to `v1()`, where they may be passed to initialize the internal `node` and `clockseq` fields.
  125. Example:
  126. ```javascript
  127. import { v1 as uuidv1 } from 'uuid';
  128. uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d'
  129. ```
  130. Example using `options`:
  131. ```javascript
  132. import { v1 as uuidv1 } from 'uuid';
  133. const v1options = {
  134. node: [0x01, 0x23, 0x45, 0x67, 0x89, 0xab],
  135. clockseq: 0x1234,
  136. msecs: new Date('2011-11-01').getTime(),
  137. nsecs: 5678,
  138. };
  139. uuidv1(v1options); // ⇨ '710b962e-041c-11e1-9234-0123456789ab'
  140. ```
  141. ### uuid.v3(name, namespace[, buffer[, offset]])
  142. Create an RFC version 3 (namespace w/ MD5) UUID
  143. API is identical to `v5()`, but uses "v3" instead.
  144. &#x26a0;&#xfe0f; Note: Per the RFC, "_If backward compatibility is not an issue, SHA-1 [Version 5] is preferred_."
  145. ### uuid.v4([options[, buffer[, offset]]])
  146. Create an RFC version 4 (random) UUID
  147. | | |
  148. | --- | --- |
  149. | [`options`] | `Object` with one or more of the following properties: |
  150. | [`options.random`] | `Array` of 16 random bytes (0-255) |
  151. | [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
  152. | [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
  153. | [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
  154. | _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
  155. Example:
  156. ```javascript
  157. import { v4 as uuidv4 } from 'uuid';
  158. uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
  159. ```
  160. Example using predefined `random` values:
  161. ```javascript
  162. import { v4 as uuidv4 } from 'uuid';
  163. const v4options = {
  164. random: [
  165. 0x10,
  166. 0x91,
  167. 0x56,
  168. 0xbe,
  169. 0xc4,
  170. 0xfb,
  171. 0xc1,
  172. 0xea,
  173. 0x71,
  174. 0xb4,
  175. 0xef,
  176. 0xe1,
  177. 0x67,
  178. 0x1c,
  179. 0x58,
  180. 0x36,
  181. ],
  182. };
  183. uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836'
  184. ```
  185. ### uuid.v5(name, namespace[, buffer[, offset]])
  186. Create an RFC version 5 (namespace w/ SHA-1) UUID
  187. | | |
  188. | --- | --- |
  189. | `name` | `String \| Array` |
  190. | `namespace` | `String \| Array[16]` Namespace UUID |
  191. | [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
  192. | [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
  193. | _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
  194. Note: The RFC `DNS` and `URL` namespaces are available as `v5.DNS` and `v5.URL`.
  195. Example with custom namespace:
  196. ```javascript
  197. import { v5 as uuidv5 } from 'uuid';
  198. // Define a custom namespace. Readers, create your own using something like
  199. // https://www.uuidgenerator.net/
  200. const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
  201. uuidv5('Hello, World!', MY_NAMESPACE); // ⇨ '630eb68f-e0fa-5ecc-887a-7c7a62614681'
  202. ```
  203. Example with RFC `URL` namespace:
  204. ```javascript
  205. import { v5 as uuidv5 } from 'uuid';
  206. uuidv5('https://www.w3.org/', uuidv5.URL); // ⇨ 'c106a26a-21bb-5538-8bf2-57095d1976c1'
  207. ```
  208. ### uuid.validate(str)
  209. Test a string to see if it is a valid UUID
  210. | | |
  211. | --------- | --------------------------------------------------- |
  212. | `str` | `String` to validate |
  213. | _returns_ | `true` if string is a valid UUID, `false` otherwise |
  214. Example:
  215. ```javascript
  216. import { validate as uuidValidate } from 'uuid';
  217. uuidValidate('not a UUID'); // ⇨ false
  218. uuidValidate('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ true
  219. ```
  220. Using `validate` and `version` together it is possible to do per-version validation, e.g. validate for only v4 UUIds.
  221. ```javascript
  222. import { version as uuidVersion } from 'uuid';
  223. import { validate as uuidValidate } from 'uuid';
  224. function uuidValidateV4(uuid) {
  225. return uuidValidate(uuid) && uuidVersion(uuid) === 4;
  226. }
  227. const v1Uuid = 'd9428888-122b-11e1-b85c-61cd3cbb3210';
  228. const v4Uuid = '109156be-c4fb-41ea-b1b4-efe1671c5836';
  229. uuidValidateV4(v4Uuid); // ⇨ true
  230. uuidValidateV4(v1Uuid); // ⇨ false
  231. ```
  232. ### uuid.version(str)
  233. Detect RFC version of a UUID
  234. | | |
  235. | --------- | ---------------------------------------- |
  236. | `str` | A valid UUID `String` |
  237. | _returns_ | `Number` The RFC version of the UUID |
  238. | _throws_ | `TypeError` if `str` is not a valid UUID |
  239. Example:
  240. ```javascript
  241. import { version as uuidVersion } from 'uuid';
  242. uuidVersion('45637ec4-c85f-11ea-87d0-0242ac130003'); // ⇨ 1
  243. uuidVersion('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ 4
  244. ```
  245. ## Command Line
  246. UUIDs can be generated from the command line using `uuid`.
  247. ```shell
  248. $ uuid
  249. ddeb27fb-d9a0-4624-be4d-4615062daed4
  250. ```
  251. The default is to generate version 4 UUIDS, however the other versions are supported. Type `uuid --help` for details:
  252. ```shell
  253. $ uuid --help
  254. Usage:
  255. uuid
  256. uuid v1
  257. uuid v3 <name> <namespace uuid>
  258. uuid v4
  259. uuid v5 <name> <namespace uuid>
  260. uuid --help
  261. Note: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs
  262. defined by RFC4122
  263. ```
  264. ## ECMAScript Modules
  265. This library comes with [ECMAScript Modules](https://www.ecma-international.org/ecma-262/6.0/#sec-modules) (ESM) support for Node.js versions that support it ([example](./examples/node-esmodules/)) as well as bundlers like [rollup.js](https://rollupjs.org/guide/en/#tree-shaking) ([example](./examples/browser-rollup/)) and [webpack](https://webpack.js.org/guides/tree-shaking/) ([example](./examples/browser-webpack/)) (targeting both, Node.js and browser environments).
  266. ```javascript
  267. import { v4 as uuidv4 } from 'uuid';
  268. uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
  269. ```
  270. To run the examples you must first create a dist build of this library in the module root:
  271. ```shell
  272. npm run build
  273. ```
  274. ## CDN Builds
  275. ### ECMAScript Modules
  276. To load this module directly into modern browsers that [support loading ECMAScript Modules](https://caniuse.com/#feat=es6-module) you can make use of [jspm](https://jspm.org/):
  277. ```html
  278. <script type="module">
  279. import { v4 as uuidv4 } from 'https://jspm.dev/uuid';
  280. console.log(uuidv4()); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
  281. </script>
  282. ```
  283. ### UMD
  284. To load this module directly into older browsers you can use the [UMD (Universal Module Definition)](https://github.com/umdjs/umd) builds from any of the following CDNs:
  285. **Using [UNPKG](https://unpkg.com/uuid@latest/dist/umd/)**:
  286. ```html
  287. <script src="https://unpkg.com/uuid@latest/dist/umd/uuidv4.min.js"></script>
  288. ```
  289. **Using [jsDelivr](https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/)**:
  290. ```html
  291. <script src="https://cdn.jsdelivr.net/npm/uuid@latest/dist/umd/uuidv4.min.js"></script>
  292. ```
  293. **Using [cdnjs](https://cdnjs.com/libraries/uuid)**:
  294. ```html
  295. <script src="https://cdnjs.cloudflare.com/ajax/libs/uuid/8.1.0/uuidv4.min.js"></script>
  296. ```
  297. These CDNs all provide the same [`uuidv4()`](#uuidv4options-buffer-offset) method:
  298. ```html
  299. <script>
  300. uuidv4(); // ⇨ '55af1e37-0734-46d8-b070-a1e42e4fc392'
  301. </script>
  302. ```
  303. Methods for the other algorithms ([`uuidv1()`](#uuidv1options-buffer-offset), [`uuidv3()`](#uuidv3name-namespace-buffer-offset) and [`uuidv5()`](#uuidv5name-namespace-buffer-offset)) are available from the files `uuidv1.min.js`, `uuidv3.min.js` and `uuidv5.min.js` respectively.
  304. ## "getRandomValues() not supported"
  305. This error occurs in environments where the standard [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) API is not supported. This issue can be resolved by adding an appropriate polyfill:
  306. ### React Native / Expo
  307. 1. Install [`react-native-get-random-values`](https://github.com/LinusU/react-native-get-random-values#readme)
  308. 1. Import it _before_ `uuid`. Since `uuid` might also appear as a transitive dependency of some other imports it's safest to just import `react-native-get-random-values` as the very first thing in your entry point:
  309. ```javascript
  310. import 'react-native-get-random-values';
  311. import { v4 as uuidv4 } from 'uuid';
  312. ```
  313. Note: If you are using Expo, you must be using at least `react-native-get-random-values@1.5.0` and `expo@39.0.0`.
  314. ### Web Workers / Service Workers (Edge <= 18)
  315. [In Edge <= 18, Web Crypto is not supported in Web Workers or Service Workers](https://caniuse.com/#feat=cryptography) and we are not aware of a polyfill (let us know if you find one, please).
  316. ## Upgrading From `uuid@7.x`
  317. ### Only Named Exports Supported When Using with Node.js ESM
  318. `uuid@7.x` did not come with native ECMAScript Module (ESM) support for Node.js. Importing it in Node.js ESM consequently imported the CommonJS source with a default export. This library now comes with true Node.js ESM support and only provides named exports.
  319. Instead of doing:
  320. ```javascript
  321. import uuid from 'uuid';
  322. uuid.v4();
  323. ```
  324. you will now have to use the named exports:
  325. ```javascript
  326. import { v4 as uuidv4 } from 'uuid';
  327. uuidv4();
  328. ```
  329. ### Deep Requires No Longer Supported
  330. Deep requires like `require('uuid/v4')` [which have been deprecated in `uuid@7.x`](#deep-requires-now-deprecated) are no longer supported.
  331. ## Upgrading From `uuid@3.x`
  332. "_Wait... what happened to `uuid@4.x` - `uuid@6.x`?!?_"
  333. In order to avoid confusion with RFC [version 4](#uuidv4options-buffer-offset) and [version 5](#uuidv5name-namespace-buffer-offset) UUIDs, and a possible [version 6](http://gh.peabody.io/uuidv6/), releases 4 thru 6 of this module have been skipped.
  334. ### Deep Requires Now Deprecated
  335. `uuid@3.x` encouraged the use of deep requires to minimize the bundle size of browser builds:
  336. ```javascript
  337. const uuidv4 = require('uuid/v4'); // <== NOW DEPRECATED!
  338. uuidv4();
  339. ```
  340. As of `uuid@7.x` this library now provides ECMAScript modules builds, which allow packagers like Webpack and Rollup to do "tree-shaking" to remove dead code. Instead, use the `import` syntax:
  341. ```javascript
  342. import { v4 as uuidv4 } from 'uuid';
  343. uuidv4();
  344. ```
  345. ... or for CommonJS:
  346. ```javascript
  347. const { v4: uuidv4 } = require('uuid');
  348. uuidv4();
  349. ```
  350. ### Default Export Removed
  351. `uuid@3.x` was exporting the Version 4 UUID method as a default export:
  352. ```javascript
  353. const uuid = require('uuid'); // <== REMOVED!
  354. ```
  355. This usage pattern was already discouraged in `uuid@3.x` and has been removed in `uuid@7.x`.
  356. ----
  357. Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd)