{"id":13673259,"url":"https://github.com/hayd/deno-using","last_synced_at":"2025-04-13T23:32:44.434Z","repository":{"id":62421488,"uuid":"171204288","full_name":"hayd/deno-using","owner":"hayd","description":"python-style with statements for deno","archived":false,"fork":false,"pushed_at":"2020-05-10T07:10:57.000Z","size":16,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T13:45:57.976Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hayd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-18T02:55:02.000Z","updated_at":"2022-07-30T00:41:37.000Z","dependencies_parsed_at":"2022-11-01T17:32:25.258Z","dependency_job_id":null,"html_url":"https://github.com/hayd/deno-using","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayd%2Fdeno-using","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayd%2Fdeno-using/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayd%2Fdeno-using/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hayd%2Fdeno-using/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hayd","download_url":"https://codeload.github.com/hayd/deno-using/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248796915,"owners_count":21163051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T10:00:32.132Z","updated_at":"2025-04-13T23:32:44.171Z","avatar_url":"https://github.com/hayd.png","language":"TypeScript","readme":"# deno-using\n\nA python-style with statement for deno.\n\nComes with some `Using` types, e.g. `Open`, `ChDir`, `TempDir`, and `Timeout`.\n\n## Example:\n\n```ts\nimport { using, Open } from \"htps://deno.land/x/using/mod.ts\";\n\nconst enc = new TextEncoder();\nconst dec = new TextDecoder();\n\nawait using(new Open(\"file\", \"w\"), async (f: Deno.File) =\u003e {\n  const data = enc.encode(\"Hello world!\\n\");\n  await f.write(data);\n});\nawait using(new Open(\"file\", \"r\"), async (f: Deno.File) =\u003e {\n  const data = new Uint8Array(20);\n  await f.read(data);\n  const text = dec.decode(data);\n  console.log(text);\n});\n```\n\nThere is also a corresponding sync version `UsingSync`.\n\n## Custom types\n\nYou can define your own `Using` types by creating a class which implements `Using`:\n\n```ts\nexport class Open implements Using\u003cDeno.File\u003e {\n  constructor(filename: string, mode?: Deno.OpenMode) {\n    this.filename = filename;\n    this.mode = mode;\n  }\n  public async _aenter() {\n    this.file = await Deno.open(this.filename, this.mode);\n    return this.file;\n  }\n  public async _aexit(e) {\n    this.file.close();\n  }\n  private file: Deno.File;\n  private filename: string;\n  private mode: Deno.OpenMode;\n}\n```\n","funding_links":[],"categories":["基础设施","Uncategorized","Modules"],"sub_categories":["JAM Stack/静态站点","Uncategorized","Online Playgrounds","Utils","Assistants"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayd%2Fdeno-using","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhayd%2Fdeno-using","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhayd%2Fdeno-using/lists"}