How are Windows Runtime GUIDs represented in JavaScript?

Raymond Chen

One of the fundamental data types in the Windows Runtime is the Guid. In most languages, it is represented as a binary-formatted data type like System.Guid or winrt::guid. But JavaScript doesn’t have a corresponding data type. So how are Windows Runtime Guids represented in JavaScript?

As strings.

But strings in a special format.

If a Windows Runtime function accepts a Guid, the JavaScript projection accepts a string in one of the following formats:

Format Description
aaaaaaaabbbbccccddeeffgghhiijjkk Raw hex
aaaaaaaa-bbbb-cccc-ddee-ffgghhiijjkk Hex with dashes
(aaaaaaaa-bbbb-cccc-ddee-ffgghhiijjkk) Hex with dashes enclosed in parentheses
{aaaaaaaa-bbbb-cccc-ddee-ffgghhiijjkk} Hex with dashes enclosed in braces
{ 0xaaaaaaaa, 0xbbbb, 0xcccc,
{ 0xdd, 0xee, 0xff, 0xgg, 0xhh, 0xii, 0xjj, 0xkk } }
C initializer

Letters a through k represent any hexadecimal digit. All parsing is case-insensitive. (That includes the x in the 0x of the C initializer format.)

In all cases, leading and trailing whitespace are ignored. A whitespace character is one which is classified as whitespace in Unicode version 6.2, which was the latest version of Unicode at the time JavaScript support was implemented.

Character Code point
CHARACTER TABULATION U+0009
LINE FEED U+000A
LINE TABULATION U+000B
FORM FEED U+000C
CARRIAGE RETURN U+000D
SPACE U+0020
NEXT LINE U+0085
NO-BREAK SPACE U+00A0
OGHAM SPACE MARK U+1680
MONGOLIAN VOWEL SEPARATOR U+180E
EN QUAD U+2000
EM QUAD U+2001
EN SPACE U+2002
EM SPACE U+2003
THREE-PER-EM SPACE U+2004
FOUR-PER-EM SPACE U+2005
IX-PER-EM SPACE U+2006
FIGURE SPACE U+2007
PUNCTUATION SPACE U+2008
THIN SPACE U+2009
HAIR SPACE U+200A
LINE SEPARATOR U+2028
PARAGRAPH SEPARATOR U+2029
NARROW NO-BREAK SPACE U+202F
MEDIUM MATHEMATICAL SPACE U+205F
IDEOGRAPHIC SPACE U+3000

The MONGOLIAN VOWEL SEPARATOR is the odd one out: It was originally classified as whitespace but lost that status in Unicode 6.3.

Whitespace is permitted in the C initializer format anywhere, not just after commas. Strange but true.

Going the other way is much simpler: If a Windows Runtime function returns a Guid, the JavaScript version returns lowercase hex with dashes (no braces or parentheses).

0 comments

Discussion is closed.

Feedback usabilla icon