Provide usage examples

Đang mở
#97 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
48/100
Loại issue
Tài liệu
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
node.js, typescript
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu với ví dụ TypeScript trong issue và xem xét các entry point công khai parse, modify và applyEdits của thư viện. Hoàn thành nghĩa là thêm một vài ví dụ rõ ràng bao quát việc tải, phân tích cú pháp và ghi các tệp JSONC, bao gồm cả quy trình định dạng và chỉnh sửa được trình bày.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Already asked in https://github.com/microsoft/node-jsonc-parser/issues/74, but it was closed by the author.

The request still stands, it would be great to have a few examples to use the library to load/parse/write JSONC files.

I shouldn't need to ask LLMs how to use something, but thankfully it helped. Here's my tsconfig.json reference sorter:

import { readFile, writeFile } from "node:fs/promises";
import * as jsonc from "jsonc-parser";

const editsOptions = {
  formattingOptions: { tabSize: 2, insertSpaces: true },
};
async function sortReferences(filePath) {
  const contents = await readFile(filePath, "utf8");
  const json = jsonc.parse(contents);

  if (!json.references) {
    return;
  }

  json.references.sort((a, b) => a.path.localeCompare(b.path));

  const edits = jsonc.modify(
    contents,
    ["references"],
    json.references,
    editsOptions,
  );

  const newContents = jsonc.applyEdits(contents, edits);

  if (contents !== newContents) {
    await writeFile(filePath, newContents);
    console.log(`Sorted: ${filePath}`);
  }
}

for (const filePath of process.argv.slice(2)) {
  void sortReferences(filePath).catch((error) => {
    throw new Error(`Error sorting references in ${filePath}`, {
      cause: error,
    });
  });
}

Ngôn ngữ chính
TypeScript
Star
759
Fork
66
Merge trung bình
5 ngày 10 giờ
Pull request đã merge (30 ngày)
7

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/node-jsonc-parser

Tất cả issue của microsoft/node-jsonc-parser

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.