Stay organized with collections
Save and categorize content based on your preferences.
blockly > Names > getDistinctName
Names.getDistinctName() method
Convert a Blockly entity name to a legal exportable entity name. Ensure that this is a new name not overlapping any previously defined name. Also check against list of reserved words for the current language and ensure name doesn't collide.
Signature:
getDistinctName(name: string, type: NameType | string): string;
Parameters
Parameter |
Type |
Description |
name |
string |
The Blockly entity name (no constraints). |
type |
NameType | string |
The type of entity in Blockly ('VARIABLE', 'PROCEDURE', 'DEVELOPER_VARIABLE', etc...). |
Returns:
string
An entity name that is legal in the exported language.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["`Names.getDistinctName()` converts a Blockly entity name into a legal, unique exportable name."],["The method ensures the name is distinct, avoiding conflicts with existing names and reserved words."],["It requires the original name and the entity type as input and returns a safe, exportable name."]]],["The `getDistinctName` method converts a Blockly entity name into a legal, exportable name. It ensures the new name is unique, avoiding overlaps with previously defined names and reserved words of the target language. The method takes the original `name` (a string) and its `type` (either `NameType` or a string, e.g., 'VARIABLE') as input and returns a valid, unique string name suitable for export.\n"]]