{
  "url": "https://unifast.dev/tr/docs/packages/core/visit-hast/",
  "locale": "tr",
  "title": "visitHast()",
  "description": "Bir ziyaretçi fonksiyonu kullanarak bir HAST ağacında dolaşın ve dönüşüm uygulayın.",
  "section": "packages",
  "body": "```ts\nimport { visitHast } from \"@unifast/core\";\n```\n\n## İmza\n\n```ts\nfunction visitHast(node: HastNode, visitor: (node: HastNode) => HastNode | void): HastNode\n```\n\n## Parametreler\n\n### node\n\n| Özellik | Tür | Varsayılan | Açıklama |\n|---------|-----|------------|----------|\n| `type` | `string` | — | Düğüm türü (`\"root\"`, `\"element\"`, `\"text\"`, vb.) |\n| `children` | `HastNode[]` | — | Alt düğümler (`\"root\"` ve `\"element\"` türleri için) |\n\n### visitor\n\n| Özellik | Tür | Varsayılan | Açıklama |\n|---------|-----|------------|----------|\n| `visitor` | `(node: HastNode) => HastNode \\| void` | — | Her düğüm için çağrılan fonksiyon; orijinali değiştirmek için bir düğüm döndürün veya korumak için `void` döndürün |\n\n## Dönüş Değeri\n\n`HastNode` — Ziyaretçi fonksiyonu tarafından uygulanan dönüşümler içeren yeni bir ağaç.\n\n## Kullanım\n\n```ts\nimport { visitHast } from \"@unifast/core\";\nimport type { HastNode, HastRoot } from \"@unifast/core\";\n\nconst tree: HastRoot = {\n  type: \"root\",\n  children: [\n    {\n      type: \"element\",\n      tagName: \"p\",\n      properties: {},\n      children: [{ type: \"text\", value: \"Hello world\" }],\n    },\n  ],\n};\n\nconst result = visitHast(tree, (node) => {\n  if (node.type === \"text\") {\n    return { type: \"text\", value: node.value.toUpperCase() };\n  }\n});\n\nconsole.log(result);\n// \"HELLO WORLD\" metnine sahip ağaç\n```\n\n## Örnekler\n\n### Tüm paragraflara bir sınıf ekleme\n\n```ts\nimport { visitHast } from \"@unifast/core\";\nimport type { HastRoot } from \"@unifast/core\";\n\nconst tree: HastRoot = {\n  type: \"root\",\n  children: [\n    {\n      type: \"element\",\n      tagName: \"p\",\n      properties: {},\n      children: [{ type: \"text\", value: \"First paragraph.\" }],\n    },\n    {\n      type: \"element\",\n      tagName: \"p\",\n      properties: {},\n      children: [{ type: \"text\", value: \"Second paragraph.\" }],\n    },\n  ],\n};\n\nconst result = visitHast(tree, (node) => {\n  if (node.type === \"element\" && node.tagName === \"p\") {\n    return {\n      ...node,\n      properties: { ...node.properties, className: [\"prose\"] },\n    };\n  }\n});\n\n// Her iki <p> elemanı artık className: [\"prose\"] değerine sahip\n```\n\n### Tüm görselleri kaldırma\n\n```ts\nimport { visitHast } from \"@unifast/core\";\nimport type { HastRoot } from \"@unifast/core\";\n\nconst tree: HastRoot = {\n  type: \"root\",\n  children: [\n    {\n      type: \"element\",\n      tagName: \"p\",\n      properties: {},\n      children: [\n        { type: \"text\", value: \"See the photo: \" },\n        {\n          type: \"element\",\n          tagName: \"img\",\n          properties: { src: \"photo.jpg\", alt: \"A photo\" },\n          children: [],\n        },\n      ],\n    },\n  ],\n};\n\nconst result = visitHast(tree, (node) => {\n  if (node.type === \"element\" && (node.tagName === \"p\" || node.tagName === \"div\")) {\n    return {\n      ...node,\n      children: node.children.filter(\n        (child) => !(child.type === \"element\" && child.tagName === \"img\"),\n      ),\n    };\n  }\n});\n\n// <img> elemanı ağaçtan kaldırıldı\n```\n\n### Tüm bağlantıları toplama\n\n```ts\nimport { visitHast } from \"@unifast/core\";\nimport type { HastRoot } from \"@unifast/core\";\n\nconst tree: HastRoot = {\n  type: \"root\",\n  children: [\n    {\n      type: \"element\",\n      tagName: \"p\",\n      properties: {},\n      children: [\n        { type: \"text\", value: \"Visit \" },\n        {\n          type: \"element\",\n          tagName: \"a\",\n          properties: { href: \"https://example.com\" },\n          children: [{ type: \"text\", value: \"Example\" }],\n        },\n        { type: \"text\", value: \" and \" },\n        {\n          type: \"element\",\n          tagName: \"a\",\n          properties: { href: \"https://docs.example.com\" },\n          children: [{ type: \"text\", value: \"Docs\" }],\n        },\n      ],\n    },\n  ],\n};\n\nconst links: string[] = [];\n\nvisitHast(tree, (node) => {\n  if (node.type === \"element\" && node.tagName === \"a\") {\n    const href = node.properties.href;\n    if (typeof href === \"string\") {\n      links.push(href);\n    }\n  }\n});\n\nconsole.log(links);\n// [\"https://example.com\", \"https://docs.example.com\"]\n```\n\n### Kod bloklarını bir kapsayıcıya sarma\n\n```ts\nimport { visitHast } from \"@unifast/core\";\nimport type { HastNode, HastRoot } from \"@unifast/core\";\n\nconst tree: HastRoot = {\n  type: \"root\",\n  children: [\n    {\n      type: \"element\",\n      tagName: \"pre\",\n      properties: {},\n      children: [\n        {\n          type: \"element\",\n          tagName: \"code\",\n          properties: { className: [\"language-js\"] },\n          children: [{ type: \"text\", value: \"const x = 1;\" }],\n        },\n      ],\n    },\n  ],\n};\n\nconst result = visitHast(tree, (node) => {\n  if (node.type === \"element\" && node.tagName === \"pre\") {\n    return {\n      type: \"element\",\n      tagName: \"div\",\n      properties: { className: [\"code-block\"] },\n      children: [node],\n    } as HastNode;\n  }\n});\n\n// <pre> artık <div class=\"code-block\"> içine sarmalandı\n```\n\n## Davranış\n\n- **Değiştirilemez:** Yeni bir ağaç döndürür; orijinal ağaç değiştirilmez\n- **Yukarıdan aşağıya dolaşım:** Ziyaretçi, alt düğümler ziyaret edilmeden önce üst düğüm için çağrılır\n- **Değiştirme:** Ziyaretçi bir düğüm döndürürse, alt düğümler dolaşılmadan önce geçerli düğümü değiştirir\n- **İşlem yok:** Ziyaretçi `void` (veya `undefined`) döndürürse, orijinal düğüm korunur\n- **Özyinelemeli:** `\"root\"` ve `\"element\"` düğümlerinin alt düğümleri özyinelemeli olarak ziyaret edilir",
  "alternates": [
    {
      "locale": "en",
      "url": "https://unifast.dev/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "ja",
      "url": "https://unifast.dev/ja/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/ja/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "zh-CN",
      "url": "https://unifast.dev/zh-CN/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/zh-CN/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "zh-TW",
      "url": "https://unifast.dev/zh-TW/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/zh-TW/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "ko",
      "url": "https://unifast.dev/ko/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/ko/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "fr",
      "url": "https://unifast.dev/fr/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/fr/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "it",
      "url": "https://unifast.dev/it/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/it/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "es",
      "url": "https://unifast.dev/es/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/es/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "pt-BR",
      "url": "https://unifast.dev/pt-BR/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/pt-BR/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "de",
      "url": "https://unifast.dev/de/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/de/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "ru",
      "url": "https://unifast.dev/ru/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/ru/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "hi",
      "url": "https://unifast.dev/hi/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/hi/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "id",
      "url": "https://unifast.dev/id/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/id/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "tr",
      "url": "https://unifast.dev/tr/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/tr/docs/packages/core/visit-hast.json"
    },
    {
      "locale": "vi",
      "url": "https://unifast.dev/vi/docs/packages/core/visit-hast/",
      "api": "https://unifast.dev//api/vi/docs/packages/core/visit-hast.json"
    }
  ]
}
