Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: ci

env:
DENO_VERSION: 2.x
DENO_TLS_CA_STORE: system

on: [push, pull_request]

Expand Down
28 changes: 26 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: publish

env:
DENO_VERSION: 2.x
NODE_VERSION: 20.x
DENO_TLS_CA_STORE: system

on:
push:
Expand All @@ -14,13 +16,35 @@ permissions:
id-token: write

jobs:
publish:
publish-jsr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}
cache: true
- name: Publish on tag
- name: Publish to JSR
run: deno run --allow-env --allow-run=deno --allow-read --allow-write=deno.jsonc jsr:@david/publish-on-tag@0.1.4

publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: ${{ env.DENO_VERSION }}
cache: true
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"
- name: Build npm package
run: deno task npm:build
env:
VERSION: ${{ github.ref_name }}
- name: Publish to npm
run: npm publish --provenance --access=public
working-directory: ./npm
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/udd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: update

env:
DENO_VERSION: 2.x
DENO_TLS_CA_STORE: system

on:
schedule:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local_test/
coverage/
docs/
npm/
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# scrapbox-userscript-std

[![JSR](https://jsr.io/badges/@cosense/std)](https://jsr.io/@cosense/std)
[![npm](https://img.shields.io/npm/v/@cosense/std)](https://www.npmjs.com/package/@cosense/std)
[![test](https://github.com/takker99/scrapbox-userscript-std/workflows/ci/badge.svg)](https://github.com/takker99/scrapbox-userscript-std/actions?query=workflow%3Aci)

UNOFFICIAL standard module for Scrapbox UserScript

> **Node.js & npm Notice (since vX.Y.Z)**
>
> Now also published on **[npm](https://www.npmjs.com/package/@cosense/std)**.
>
> Node.js support is **experimental**: I mainly target Deno and browsers, so I
> don't actively maintain Node.js compatibility. Some tests run, but there may
> still be runtime or type gaps remaining. Please use it with that
> understanding.
>
> That said, **issues / PRs to improve Node support are very welcome!**
>
> If you don't need a public npm package, you can consume the JSR version
> directly—`npm` via a custom registry in `.npmrc`; `yarn` or `pnpm` need no
> extra config. See the
> [JSR docs](https://jsr.io/docs/using-packages#adding-a-package).

## Getting Started

This library serves as an unofficial standard library for developing Scrapbox
Expand All @@ -14,6 +31,11 @@ common utilities.

### Installation

This library supports both JSR (JavaScript Registry) and npm installation
methods.

#### Option 1: JSR (Recommended for Deno projects)

1. Bundler Configuration This library is distributed through JSR (JavaScript
Registry) and requires a bundler configuration. Follow these steps:

Expand All @@ -35,6 +57,24 @@ import { press } from "jsr:@cosense/std/browser/dom";
import { getLines } from "jsr:@cosense/std/browser/dom";
```

#### Option 2: npm (For Node.js projects)

1. Install via npm:

```bash
npm install @cosense/std
```

2. Import the library:

**Only ESM syntax is supported.**

```typescript
// ESM syntax
import { getPage } from "@cosense/std/rest";
import { parseAbsoluteLink } from "@cosense/std";
```

2. Module Organization The library is organized into the following main modules:

- `rest/`: API operations for Scrapbox REST endpoints
Expand All @@ -58,7 +98,10 @@ import { getLines } from "jsr:@cosense/std/browser/dom";

```typescript
// Get page content and metadata
// JSR import
import { getPage } from "jsr:@cosense/std/rest";
// npm import
// import { getPage } from "@cosense/std/rest";

const result = await getPage("projectName", "pageName");
if (result.ok) {
Expand All @@ -73,7 +116,10 @@ if (result.ok) {

```typescript
// Interact with the current page's content
// JSR import
import { getLines, press } from "jsr:@cosense/std/browser/dom";
// npm import
// import { getLines, press } from "@cosense/std/browser/dom";

// Get all lines from the current page
const lines = getLines();
Expand All @@ -88,8 +134,12 @@ await press("Tab"); // Indent the line

```typescript
// Parse external links (YouTube, Spotify, etc.)
// JSR import
import { parseAbsoluteLink } from "jsr:@cosense/std";
import type { LinkNode } from "@progfay/scrapbox-parser";
// npm import
// import { parseAbsoluteLink } from "@cosense/std";
// import type { LinkNode } from "@progfay/scrapbox-parser";

// Create a link node with absolute path type
const link = {
Expand Down
4 changes: 2 additions & 2 deletions api/pages/project.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type {
BasePage,
NotFoundError,
NotLoggedInError,
NotMemberError,
PageList,
PageSummary,
} from "@cosense/types/rest";
import { type BaseOptions, setDefaults } from "../../util.ts";
import { cookie } from "../../rest/auth.ts";
Expand Down Expand Up @@ -150,7 +150,7 @@ export interface ListPagesStreamOption<R extends Response | undefined>
export async function* listPagesStream(
project: string,
options?: ListPagesStreamOption<Response>,
): AsyncGenerator<BasePage, void, unknown> {
): AsyncGenerator<PageSummary, void, unknown> {
const props = {
...(options ?? {}),
skip: options?.skip ?? 0,
Expand Down
32 changes: 19 additions & 13 deletions deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"exclude": [
"coverage/",
"docs/"
"docs/",
"npm/"
],
"exports": {
".": "./mod.ts",
Expand All @@ -20,7 +21,6 @@
"./rest": "./rest/mod.ts",
"./text": "./text.ts",
"./title": "./title.ts",
"./websocket": "./websocket/mod.ts",
"./unstable-api": "./api.ts",
"./unstable-api/pages": "./api/pages.ts",
"./unstable-api/pages/project": "./api/pages/project.ts",
Expand All @@ -30,36 +30,35 @@
"./unstable-api/pages/project/search/query": "./api/pages/project/search/query.ts",
"./unstable-api/pages/project/search/titles": "./api/pages/project/search/titles.ts",
"./unstable-api/pages/project/title": "./api/pages/project/title.ts",
"./unstable-api/pages/project/title/icon": "./api/pages/project/title/icon.ts",
"./unstable-api/pages/project/title/text": "./api/pages/project/title/text.ts",
"./unstable-api/pages/projects": "./api/projects.ts",
"./unstable-api/pages/projects/project": "./api/projects/project.ts",
"./unstable-api/pages/project/title/text": "./api/pages/project/title/text.ts",
"./unstable-api/pages/project/title/icon": "./api/pages/project/title/icon.ts",
"./unstable-api/pages/smart-context": "./api/smart-context.ts",
"./unstable-api/pages/smart-context/export-1hop-links": "./api/smart-context/export-1hop-links/project.ts",
"./unstable-api/pages/smart-context/export-2hop-links": "./api/smart-context/export-2hop-links/project.ts",
"./unstable-api/users": "./api/users.ts",
"./unstable-api/users/me": "./api/users/me.ts"
"./unstable-api/users/me": "./api/users/me.ts",
"./websocket": "./websocket/mod.ts"
},
"imports": {
"@core/iterutil": "jsr:@core/iterutil@^0.9.0",
"@core/unknownutil": "jsr:@core/unknownutil@^4.0.0",
"@cosense/std/browser/websocket": "./websocket/mod.ts",
"@cosense/std/rest": "./rest/mod.ts",
"@cosense/std/websocket": "./websocket/mod.ts",
"@cosense/types": "jsr:@cosense/types@^0.10.7",
"@cosense/types/rest": "jsr:@cosense/types@0.10/rest",
"@cosense/types/userscript": "jsr:@cosense/types@0.10/userscript",
"@progfay/scrapbox-parser": "jsr:@progfay/scrapbox-parser@9",
"@cosense/types": "jsr:@cosense/types@^0.11.0",
"@deno/dnt": "jsr:@deno/dnt@^0.42.3",
"@progfay/scrapbox-parser": "jsr:@progfay/scrapbox-parser@^10.0.1",
"@std/assert": "jsr:@std/assert@1",
"@std/async": "jsr:@std/async@^1.0.11",
"@std/async": "jsr:@std/async@^1.0.14",
"@std/encoding": "jsr:@std/encoding@1",
"@std/http": "jsr:@std/http@^1.0.13",
"@std/json": "jsr:@std/json@^1.0.0",
"@std/testing": "jsr:@std/testing@^1.0.9",
"@std/testing/snapshot": "jsr:@std/testing@1/snapshot",
"@takker/md5": "jsr:@takker/md5@0.1",
"@takker/onp": "./vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts",
"option-t": "npm:option-t@^51.0.0",
"option-t": "npm:option-t@53",
"socket.io-client": "npm:socket.io-client@^4.7.5"
},
"lint": {
Expand All @@ -76,7 +75,7 @@
"test"
]
},
"coverage": "deno test --allow-read=./ --parallel --shuffle --coverage --no-check && deno coverage --html",
"coverage": "deno test --allow-read=./ --doc --parallel --shuffle --coverage --no-check && deno coverage --html",
"doc": "deno doc --html mod.ts",
"fix": {
"command": "deno fmt && deno lint --fix && deno publish --dry-run --allow-dirty",
Expand All @@ -85,6 +84,13 @@
"test"
]
},
"npm:build": "deno run -A scripts/build_npm.ts",
"npm:check": {
"command": "cd npm && npm publish --provenance --access=public --dry-run",
"dependencies": [
"npm:build"
]
},
"test": "deno test --allow-read=./ --doc --parallel --shuffle --no-check",
"type-check": "deno check --remote **/*.ts",
// from https://github.com/jsr-core/unknownutil/blob/v4.2.2/deno.jsonc#L84-L85
Expand Down
Loading