This little gotcha might help you to decide whether you item is a content item, or a content component. What is that good for? Content components are always returned as a part of the parent item and can't be fetched solely. This condition can help you i.e. with caching.
Do you want to cache content items and you are not sure which ones are content components and which are linked items?
You can use a little hack - the third segment of content components always starts with 01
. This effectively prevents you from doing one round trip to the server to check if the item is a component or not (by using get items and specifying the ID and checking if you get the item in the response). Or parsing the rich text element to get the information whether the linked item is a component, or linked item.
Here is a C# snippet using Guid
private static bool IsComponent(JProperty property)
{
// Components have substring 01 in its id starting at position 14.
// xxxxxxxx-xxxx-01xx-xxxx-xxxxxxxxxxxx
var id = property?.Value?["system"]?["id"]?.Value<string>();
return id != null && (Guid.TryParse(id, out _) && id.Substring(14, 2).Equals("01", StringComparison.Ordinal));
}
And here a Typescript showcase using regular expressions to do the same:
private static isComponent(property: any): boolean {
// Components have substring '01' in its id starting at position 14.
// xxxxxxxx-xxxx-01xx-xxxx-xxxxxxxxxxxx
const id = property?.Value?.["system"]?.["id"] as string | undefined;
if (!id) return false;
// Validate GUID format
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
if (!guidRegex.test(id)) return false;
return id.substring(14, 16) === "01";
}