tinker-agent 1.0.65 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/LICENSE +201 -0
- package/NOTICE +6 -0
- package/README.md +90 -9
- package/bin/tinker.js +39 -0
- package/node_modules/ansi-regex/index.d.ts +33 -0
- package/node_modules/ansi-regex/index.js +14 -0
- package/node_modules/ansi-regex/license +9 -0
- package/node_modules/ansi-regex/package.json +61 -0
- package/node_modules/ansi-regex/readme.md +66 -0
- package/node_modules/ansi-styles/index.d.ts +236 -0
- package/node_modules/ansi-styles/index.js +223 -0
- package/node_modules/ansi-styles/license +9 -0
- package/node_modules/ansi-styles/package.json +54 -0
- package/node_modules/ansi-styles/readme.md +173 -0
- package/node_modules/chalk/license +9 -0
- package/node_modules/chalk/package.json +83 -0
- package/node_modules/chalk/readme.md +297 -0
- package/node_modules/chalk/source/index.d.ts +325 -0
- package/node_modules/chalk/source/index.js +225 -0
- package/node_modules/chalk/source/utilities.js +33 -0
- package/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
- package/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
- package/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
- package/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
- package/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
- package/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
- package/node_modules/character-entities/index.d.ts +6 -0
- package/node_modules/character-entities/index.js +2132 -0
- package/node_modules/character-entities/license +22 -0
- package/node_modules/character-entities/package.json +78 -0
- package/node_modules/character-entities/readme.md +152 -0
- package/node_modules/decode-named-character-reference/index.d.ts +13 -0
- package/node_modules/decode-named-character-reference/index.d.ts.map +1 -0
- package/node_modules/decode-named-character-reference/index.dom.d.ts +6 -0
- package/node_modules/decode-named-character-reference/index.dom.d.ts.map +1 -0
- package/node_modules/decode-named-character-reference/index.dom.js +32 -0
- package/node_modules/decode-named-character-reference/index.js +19 -0
- package/node_modules/decode-named-character-reference/license +22 -0
- package/node_modules/decode-named-character-reference/package.json +90 -0
- package/node_modules/decode-named-character-reference/readme.md +136 -0
- package/node_modules/get-east-asian-width/index.d.ts +60 -0
- package/node_modules/get-east-asian-width/index.js +30 -0
- package/node_modules/get-east-asian-width/license +9 -0
- package/node_modules/get-east-asian-width/lookup-data.js +21 -0
- package/node_modules/get-east-asian-width/lookup.js +138 -0
- package/node_modules/get-east-asian-width/package.json +71 -0
- package/node_modules/get-east-asian-width/readme.md +65 -0
- package/node_modules/get-east-asian-width/utilities.js +24 -0
- package/node_modules/has-flag/index.d.ts +39 -0
- package/node_modules/has-flag/index.js +8 -0
- package/node_modules/has-flag/license +9 -0
- package/node_modules/has-flag/package.json +49 -0
- package/node_modules/has-flag/readme.md +74 -0
- package/node_modules/is-fullwidth-code-point/index.d.ts +17 -0
- package/node_modules/is-fullwidth-code-point/index.js +12 -0
- package/node_modules/is-fullwidth-code-point/license +9 -0
- package/node_modules/is-fullwidth-code-point/package.json +53 -0
- package/node_modules/is-fullwidth-code-point/readme.md +31 -0
- package/node_modules/markdansi/LICENSE +21 -0
- package/node_modules/markdansi/README.md +167 -0
- package/node_modules/markdansi/dist/ast.d.ts +99 -0
- package/node_modules/markdansi/dist/ast.js +1 -0
- package/node_modules/markdansi/dist/cli.d.ts +17 -0
- package/node_modules/markdansi/dist/cli.js +208 -0
- package/node_modules/markdansi/dist/hyperlink.d.ts +9 -0
- package/node_modules/markdansi/dist/hyperlink.js +26 -0
- package/node_modules/markdansi/dist/index.d.ts +10 -0
- package/node_modules/markdansi/dist/index.js +16 -0
- package/node_modules/markdansi/dist/parser.d.ts +2 -0
- package/node_modules/markdansi/dist/parser.js +205 -0
- package/node_modules/markdansi/dist/render.d.ts +9 -0
- package/node_modules/markdansi/dist/render.js +680 -0
- package/node_modules/markdansi/dist/stream.d.ts +39 -0
- package/node_modules/markdansi/dist/stream.js +192 -0
- package/node_modules/markdansi/dist/theme.d.ts +18 -0
- package/node_modules/markdansi/dist/theme.js +105 -0
- package/node_modules/markdansi/dist/types.d.ts +58 -0
- package/node_modules/markdansi/dist/types.js +1 -0
- package/node_modules/markdansi/dist/wrap.d.ts +10 -0
- package/node_modules/markdansi/dist/wrap.js +73 -0
- package/node_modules/markdansi/docs/spec.md +110 -0
- package/node_modules/markdansi/package.json +78 -0
- package/node_modules/markdansi/tsconfig.json +18 -0
- package/node_modules/marked/LICENSE +44 -0
- package/node_modules/marked/README.md +115 -0
- package/node_modules/marked/bin/main.js +284 -0
- package/node_modules/marked/bin/marked.js +16 -0
- package/node_modules/marked/lib/marked.d.ts +760 -0
- package/node_modules/marked/lib/marked.esm.js +77 -0
- package/node_modules/marked/lib/marked.esm.js.map +7 -0
- package/node_modules/marked/lib/marked.umd.js +79 -0
- package/node_modules/marked/lib/marked.umd.js.map +7 -0
- package/node_modules/marked/man/marked.1 +113 -0
- package/node_modules/marked/man/marked.1.md +93 -0
- package/node_modules/marked/package.json +103 -0
- package/node_modules/slice-ansi/index.d.ts +19 -0
- package/node_modules/slice-ansi/index.js +317 -0
- package/node_modules/slice-ansi/license +10 -0
- package/node_modules/slice-ansi/package.json +59 -0
- package/node_modules/slice-ansi/readme.md +55 -0
- package/node_modules/slice-ansi/tokenize-ansi.js +752 -0
- package/node_modules/string-width/index.d.ts +39 -0
- package/node_modules/string-width/index.js +203 -0
- package/node_modules/string-width/license +9 -0
- package/node_modules/string-width/package.json +65 -0
- package/node_modules/string-width/readme.md +66 -0
- package/node_modules/strip-ansi/index.d.ts +15 -0
- package/node_modules/strip-ansi/index.js +19 -0
- package/node_modules/strip-ansi/license +9 -0
- package/node_modules/strip-ansi/package.json +59 -0
- package/node_modules/strip-ansi/readme.md +37 -0
- package/node_modules/supports-color/browser.d.ts +1 -0
- package/node_modules/supports-color/browser.js +35 -0
- package/node_modules/supports-color/index.d.ts +55 -0
- package/node_modules/supports-color/index.js +202 -0
- package/node_modules/supports-color/license +9 -0
- package/node_modules/supports-color/package.json +64 -0
- package/node_modules/supports-color/readme.md +75 -0
- package/node_modules/supports-hyperlinks/browser.js +10 -0
- package/node_modules/supports-hyperlinks/index.d.ts +25 -0
- package/node_modules/supports-hyperlinks/index.js +163 -0
- package/node_modules/supports-hyperlinks/license +10 -0
- package/node_modules/supports-hyperlinks/package.json +47 -0
- package/node_modules/supports-hyperlinks/readme.md +45 -0
- package/package.json +41 -10
- package/patches/markdansi@0.3.2.patch +22 -2
- package/src/agent/context-builder.ts +24 -10
- package/src/agent/context-meter.ts +89 -5
- package/src/agent/loop.ts +107 -10
- package/src/agent/runtime-session.ts +1437 -82
- package/src/agent/session-ledger.ts +169 -29
- package/src/agent/types.ts +12 -1
- package/src/agent/user-prompt-projection.ts +62 -0
- package/src/cli/config.ts +57 -14
- package/src/cli/model-profiles.ts +124 -0
- package/src/cli/run-runner.ts +4 -1
- package/src/cli/tui-runner.tsx +68 -30
- package/src/context/compiled-context-hash.ts +1 -1
- package/src/context/compiled-context-validator.ts +92 -15
- package/src/context/context-automation-policy.ts +121 -0
- package/src/context/context-manager.ts +390 -11
- package/src/context/context-policy.ts +8 -0
- package/src/context/context-protocol-validator.ts +11 -1
- package/src/context/context-revision-compiler.ts +190 -27
- package/src/context/context-revision.ts +105 -19
- package/src/context/context-surface.ts +329 -0
- package/src/context/prefix-retirement-planner.ts +570 -0
- package/src/context/protocol-frame.ts +30 -3
- package/src/context/recall-retirement-contract.ts +27 -0
- package/src/context/swap-planner.ts +34 -10
- package/src/events/observation-text-log.ts +3 -3
- package/src/events/stdout-event-printer.ts +39 -3
- package/src/events/types.ts +172 -35
- package/src/ids/runtime-id.ts +6 -0
- package/src/ids/uuid-v7.ts +7 -0
- package/src/image/image-asset-store.ts +319 -0
- package/src/image/image-input-policy.ts +14 -0
- package/src/image/image-probe.ts +233 -0
- package/src/image/image-types.ts +262 -0
- package/src/instructions/project-instructions.ts +4 -1
- package/src/mcp/mcp-manager.ts +83 -19
- package/src/model/fake-model-client.ts +9 -1
- package/src/model/input-token-estimator.ts +25 -0
- package/src/model/model-client.ts +60 -0
- package/src/model/model-request-preflight.ts +1 -0
- package/src/model/moonshot-input-token-estimator.ts +107 -0
- package/src/model/openai-chat-mapping.ts +77 -1
- package/src/model/openai-chat-model-client.ts +389 -59
- package/src/model/openai-chat-stream.ts +272 -0
- package/src/model/prompt-prefix-hash.ts +2 -4
- package/src/model/token-estimator.ts +4 -0
- package/src/observation/observation-builder.ts +29 -0
- package/src/session/resume-projection.ts +94 -34
- package/src/session/session-catalog.ts +4 -4
- package/src/session/session-errors.ts +1 -1
- package/src/session/session-history-reader.ts +151 -4
- package/src/session/session-last-response-reader.ts +189 -0
- package/src/session/session-schema.ts +349 -35
- package/src/session/session-store.ts +3266 -255
- package/src/session/sqlite-session-ledger.ts +9 -4
- package/src/skills/skill-catalog.ts +182 -0
- package/src/skills/skill-context.ts +364 -0
- package/src/skills/skill-loader.ts +779 -0
- package/src/skills/skill-tool.ts +297 -0
- package/src/tools/edit.ts +51 -64
- package/src/tools/ensure-parent-directory.ts +6 -0
- package/src/tools/read.ts +2 -2
- package/src/tools/recall.ts +43 -40
- package/src/tools/registry.ts +24 -3
- package/src/tools/ripgrep.ts +3 -2
- package/src/tools/types.ts +43 -4
- package/src/tools/write.ts +20 -31
- package/src/tui/app.tsx +333 -96
- package/src/tui/clipboard.ts +5 -0
- package/src/tui/components/mcp-panel.tsx +28 -0
- package/src/tui/components/prompt-input.tsx +790 -257
- package/src/tui/components/skills-panel.tsx +31 -0
- package/src/tui/components/timeline.tsx +30 -1
- package/src/tui/event-store.ts +85 -2
- package/src/tui/file-mention.ts +234 -0
- package/src/tui/line-editor.ts +1 -0
- package/src/tui/project-slash-commands.ts +229 -0
- package/src/tui/prompt-draft.ts +510 -0
- package/src/tui/prompt-history.ts +294 -22
- package/src/tui/slash-commands.ts +46 -2
- package/src/tui/tui-session-controller.ts +110 -48
- package/src/tui/workspace-file-search.ts +94 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Titus Wormer <tituswormer@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "character-entities",
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Map of named character references",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"html",
|
|
8
|
+
"entity",
|
|
9
|
+
"entities",
|
|
10
|
+
"character",
|
|
11
|
+
"reference",
|
|
12
|
+
"name",
|
|
13
|
+
"replacement"
|
|
14
|
+
],
|
|
15
|
+
"repository": "wooorm/character-entities",
|
|
16
|
+
"bugs": "https://github.com/wooorm/character-entities/issues",
|
|
17
|
+
"funding": {
|
|
18
|
+
"type": "github",
|
|
19
|
+
"url": "https://github.com/sponsors/wooorm"
|
|
20
|
+
},
|
|
21
|
+
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
|
22
|
+
"contributors": [
|
|
23
|
+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "index.js",
|
|
28
|
+
"types": "index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"index.d.ts",
|
|
31
|
+
"index.js"
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/tape": "^4.0.0",
|
|
35
|
+
"bail": "^2.0.0",
|
|
36
|
+
"c8": "^7.0.0",
|
|
37
|
+
"concat-stream": "^2.0.0",
|
|
38
|
+
"prettier": "^2.0.0",
|
|
39
|
+
"remark-cli": "^10.0.0",
|
|
40
|
+
"remark-preset-wooorm": "^9.0.0",
|
|
41
|
+
"rimraf": "^3.0.0",
|
|
42
|
+
"tape": "^5.0.0",
|
|
43
|
+
"type-coverage": "^2.0.0",
|
|
44
|
+
"typescript": "^4.0.0",
|
|
45
|
+
"xo": "^0.50.0"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"generate": "node build",
|
|
49
|
+
"prepublishOnly": "npm run build && npm run format",
|
|
50
|
+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
|
|
51
|
+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
|
52
|
+
"test-api": "node --conditions development test.js",
|
|
53
|
+
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
|
|
54
|
+
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
|
|
55
|
+
},
|
|
56
|
+
"prettier": {
|
|
57
|
+
"tabWidth": 2,
|
|
58
|
+
"useTabs": false,
|
|
59
|
+
"singleQuote": true,
|
|
60
|
+
"bracketSpacing": false,
|
|
61
|
+
"semi": false,
|
|
62
|
+
"trailingComma": "none"
|
|
63
|
+
},
|
|
64
|
+
"xo": {
|
|
65
|
+
"prettier": true
|
|
66
|
+
},
|
|
67
|
+
"remarkConfig": {
|
|
68
|
+
"plugins": [
|
|
69
|
+
"preset-wooorm"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"typeCoverage": {
|
|
73
|
+
"atLeast": 100,
|
|
74
|
+
"detail": true,
|
|
75
|
+
"strict": true,
|
|
76
|
+
"ignoreCatch": true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# character-entities
|
|
2
|
+
|
|
3
|
+
[![Build][build-badge]][build]
|
|
4
|
+
[![Coverage][coverage-badge]][coverage]
|
|
5
|
+
[![Downloads][downloads-badge]][downloads]
|
|
6
|
+
[![Size][size-badge]][size]
|
|
7
|
+
|
|
8
|
+
Map of named character references.
|
|
9
|
+
|
|
10
|
+
## Contents
|
|
11
|
+
|
|
12
|
+
* [What is this?](#what-is-this)
|
|
13
|
+
* [When should I use this?](#when-should-i-use-this)
|
|
14
|
+
* [Install](#install)
|
|
15
|
+
* [Use](#use)
|
|
16
|
+
* [API](#api)
|
|
17
|
+
* [characterEntities](#characterentities)
|
|
18
|
+
* [Types](#types)
|
|
19
|
+
* [Compatibility](#compatibility)
|
|
20
|
+
* [Security](#security)
|
|
21
|
+
* [Related](#related)
|
|
22
|
+
* [Contribute](#contribute)
|
|
23
|
+
* [License](#license)
|
|
24
|
+
|
|
25
|
+
## What is this?
|
|
26
|
+
|
|
27
|
+
This is a map of named character references in HTML (latest) to the characters
|
|
28
|
+
they represent.
|
|
29
|
+
|
|
30
|
+
## When should I use this?
|
|
31
|
+
|
|
32
|
+
Maybe when you’re writing an HTML parser or minifier, but otherwise probably
|
|
33
|
+
never!
|
|
34
|
+
Even then, it might be better to use [`parse-entities`][parse-entities] or
|
|
35
|
+
[`stringify-entities`][stringify-entities].
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
This package is [ESM only][esm].
|
|
40
|
+
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
npm install character-entities
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
In Deno with [`esm.sh`][esmsh]:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import {characterEntities} from 'https://esm.sh/character-entities@2'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
In browsers with [`esm.sh`][esmsh]:
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<script type="module">
|
|
56
|
+
import {characterEntities} from 'https://esm.sh/character-entities@2?bundle'
|
|
57
|
+
</script>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Use
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import {characterEntities} from 'character-entities'
|
|
64
|
+
|
|
65
|
+
console.log(characterEntities.AElig) // => 'Æ'
|
|
66
|
+
console.log(characterEntities.aelig) // => 'æ'
|
|
67
|
+
console.log(characterEntities.amp) // => '&'
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API
|
|
71
|
+
|
|
72
|
+
This package exports the identifier `characterEntities`.
|
|
73
|
+
There is no default export.
|
|
74
|
+
|
|
75
|
+
### characterEntities
|
|
76
|
+
|
|
77
|
+
Mapping between (case-sensitive) character entity names to replacements.
|
|
78
|
+
See [`html.spec.whatwg.org`][html] for more info.
|
|
79
|
+
|
|
80
|
+
## Types
|
|
81
|
+
|
|
82
|
+
This package is fully typed with [TypeScript][].
|
|
83
|
+
|
|
84
|
+
## Compatibility
|
|
85
|
+
|
|
86
|
+
This package is at least compatible with all maintained versions of Node.js.
|
|
87
|
+
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+.
|
|
88
|
+
It also works in Deno and modern browsers.
|
|
89
|
+
|
|
90
|
+
## Security
|
|
91
|
+
|
|
92
|
+
This package is safe.
|
|
93
|
+
|
|
94
|
+
## Related
|
|
95
|
+
|
|
96
|
+
* [`wooorm/parse-entities`](https://github.com/wooorm/parse-entities)
|
|
97
|
+
— parse (decode) character references
|
|
98
|
+
* [`wooorm/stringify-entities`](https://github.com/wooorm/stringify-entities)
|
|
99
|
+
— serialize (encode) character references
|
|
100
|
+
* [`wooorm/character-entities-html4`](https://github.com/wooorm/character-entities-html4)
|
|
101
|
+
— info on named character references in HTML 4
|
|
102
|
+
* [`character-reference-invalid`](https://github.com/wooorm/character-reference-invalid)
|
|
103
|
+
— info on invalid numeric character references
|
|
104
|
+
* [`character-entities-legacy`](https://github.com/wooorm/character-entities-legacy)
|
|
105
|
+
— info on legacy named character references
|
|
106
|
+
|
|
107
|
+
## Contribute
|
|
108
|
+
|
|
109
|
+
Yes please!
|
|
110
|
+
See [How to Contribute to Open Source][contribute].
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
[MIT][license] © [Titus Wormer][author]
|
|
115
|
+
|
|
116
|
+
<!-- Definitions -->
|
|
117
|
+
|
|
118
|
+
[build-badge]: https://github.com/wooorm/character-entities/workflows/main/badge.svg
|
|
119
|
+
|
|
120
|
+
[build]: https://github.com/wooorm/character-entities/actions
|
|
121
|
+
|
|
122
|
+
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/character-entities.svg
|
|
123
|
+
|
|
124
|
+
[coverage]: https://codecov.io/github/wooorm/character-entities
|
|
125
|
+
|
|
126
|
+
[downloads-badge]: https://img.shields.io/npm/dm/character-entities.svg
|
|
127
|
+
|
|
128
|
+
[downloads]: https://www.npmjs.com/package/character-entities
|
|
129
|
+
|
|
130
|
+
[size-badge]: https://img.shields.io/bundlephobia/minzip/character-entities.svg
|
|
131
|
+
|
|
132
|
+
[size]: https://bundlephobia.com/result?p=character-entities
|
|
133
|
+
|
|
134
|
+
[npm]: https://docs.npmjs.com/cli/install
|
|
135
|
+
|
|
136
|
+
[esmsh]: https://esm.sh
|
|
137
|
+
|
|
138
|
+
[license]: license
|
|
139
|
+
|
|
140
|
+
[author]: https://wooorm.com
|
|
141
|
+
|
|
142
|
+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
143
|
+
|
|
144
|
+
[typescript]: https://www.typescriptlang.org
|
|
145
|
+
|
|
146
|
+
[contribute]: https://opensource.guide/how-to-contribute/
|
|
147
|
+
|
|
148
|
+
[parse-entities]: https://github.com/wooorm/parse-entities
|
|
149
|
+
|
|
150
|
+
[stringify-entities]: https://github.com/wooorm/stringify-entities
|
|
151
|
+
|
|
152
|
+
[html]: https://html.spec.whatwg.org/multipage/syntax.html#named-character-references
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode a single character reference (without the `&` or `;`).
|
|
3
|
+
* You probably only need this when you’re building parsers yourself that follow
|
|
4
|
+
* different rules compared to HTML.
|
|
5
|
+
* This is optimized to be tiny in browsers.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} value
|
|
8
|
+
* `notin` (named), `#123` (deci), `#x123` (hexa).
|
|
9
|
+
* @returns {string|false}
|
|
10
|
+
* Decoded reference.
|
|
11
|
+
*/
|
|
12
|
+
export function decodeNamedCharacterReference(value: string): string | false;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,qDALW,MAAM,GAEJ,MAAM,GAAC,KAAK,CAKxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.dom.d.ts","sourceRoot":"","sources":["index.dom.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH,qDAHW,MAAM,GACJ,MAAM,GAAG,KAAK,CAuB1B"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
|
|
3
|
+
/* global document */
|
|
4
|
+
|
|
5
|
+
const element = document.createElement('i')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} value
|
|
9
|
+
* @returns {string | false}
|
|
10
|
+
*/
|
|
11
|
+
export function decodeNamedCharacterReference(value) {
|
|
12
|
+
const characterReference = '&' + value + ';'
|
|
13
|
+
element.innerHTML = characterReference
|
|
14
|
+
const character = element.textContent
|
|
15
|
+
|
|
16
|
+
// Some named character references do not require the closing semicolon
|
|
17
|
+
// (`¬`, for instance), which leads to situations where parsing the assumed
|
|
18
|
+
// named reference of `¬it;` will result in the string `¬it;`.
|
|
19
|
+
// When we encounter a trailing semicolon after parsing, and the character
|
|
20
|
+
// reference to decode was not a semicolon (`;`), we can assume that the
|
|
21
|
+
// matching was not complete.
|
|
22
|
+
if (
|
|
23
|
+
character.charCodeAt(character.length - 1) === 59 /* `;` */ &&
|
|
24
|
+
value !== 'semi'
|
|
25
|
+
) {
|
|
26
|
+
return false
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// If the decoded string is equal to the input, the character reference was
|
|
30
|
+
// not valid.
|
|
31
|
+
return character === characterReference ? false : character
|
|
32
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {characterEntities} from 'character-entities'
|
|
2
|
+
|
|
3
|
+
// To do: next major: use `Object.hasOwn`.
|
|
4
|
+
const own = {}.hasOwnProperty
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Decode a single character reference (without the `&` or `;`).
|
|
8
|
+
* You probably only need this when you’re building parsers yourself that follow
|
|
9
|
+
* different rules compared to HTML.
|
|
10
|
+
* This is optimized to be tiny in browsers.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} value
|
|
13
|
+
* `notin` (named), `#123` (deci), `#x123` (hexa).
|
|
14
|
+
* @returns {string|false}
|
|
15
|
+
* Decoded reference.
|
|
16
|
+
*/
|
|
17
|
+
export function decodeNamedCharacterReference(value) {
|
|
18
|
+
return own.call(characterEntities, value) ? characterEntities[value] : false
|
|
19
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Titus Wormer <tituswormer@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
|
3
|
+
"bugs": "https://github.com/wooorm/decode-named-character-reference/issues",
|
|
4
|
+
"contributors": [
|
|
5
|
+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
|
6
|
+
],
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"character-entities": "^2.0.0"
|
|
9
|
+
},
|
|
10
|
+
"description": "Decode named character references",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/node": "^25.0.0",
|
|
13
|
+
"c8": "^10.0.0",
|
|
14
|
+
"prettier": "^3.0.0",
|
|
15
|
+
"remark-cli": "^12.0.0",
|
|
16
|
+
"remark-preset-wooorm": "^11.0.0",
|
|
17
|
+
"type-coverage": "^2.0.0",
|
|
18
|
+
"typescript": "^5.0.0",
|
|
19
|
+
"xo": "^1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
"convex": "./index.js",
|
|
23
|
+
"deno": "./index.js",
|
|
24
|
+
"edge-light": "./index.js",
|
|
25
|
+
"react-native": "./index.js",
|
|
26
|
+
"worker": "./index.js",
|
|
27
|
+
"workerd": "./index.js",
|
|
28
|
+
"browser": "./index.dom.js",
|
|
29
|
+
"default": "./index.js"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"index.d.ts.map",
|
|
33
|
+
"index.d.ts",
|
|
34
|
+
"index.dom.d.ts.map",
|
|
35
|
+
"index.dom.d.ts",
|
|
36
|
+
"index.dom.js",
|
|
37
|
+
"index.js"
|
|
38
|
+
],
|
|
39
|
+
"funding": {
|
|
40
|
+
"type": "github",
|
|
41
|
+
"url": "https://github.com/sponsors/wooorm"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"character",
|
|
45
|
+
"decode",
|
|
46
|
+
"named",
|
|
47
|
+
"references"
|
|
48
|
+
],
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"main#": "to do: next major: remove field",
|
|
51
|
+
"main": "index.js",
|
|
52
|
+
"name": "decode-named-character-reference",
|
|
53
|
+
"prettier": {
|
|
54
|
+
"bracketSpacing": false,
|
|
55
|
+
"semi": false,
|
|
56
|
+
"singleQuote": true,
|
|
57
|
+
"tabWidth": 2,
|
|
58
|
+
"trailingComma": "none",
|
|
59
|
+
"useTabs": false
|
|
60
|
+
},
|
|
61
|
+
"remarkConfig": {
|
|
62
|
+
"plugins": [
|
|
63
|
+
"remark-preset-wooorm"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"repository": "wooorm/decode-named-character-reference",
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "tsc --build --clean && tsc --build && type-coverage",
|
|
69
|
+
"format": "remark --frail --output --quiet -- . && prettier --log-level warn --write -- . && xo --fix",
|
|
70
|
+
"test-api": "node --conditions development test.js",
|
|
71
|
+
"test-coverage": "c8 --100 --reporter lcov -- npm run test-api",
|
|
72
|
+
"test": "npm run build && npm run format && npm run test-coverage"
|
|
73
|
+
},
|
|
74
|
+
"sideEffects": false,
|
|
75
|
+
"typeCoverage": {
|
|
76
|
+
"atLeast": 100,
|
|
77
|
+
"ignoreCatch": true
|
|
78
|
+
},
|
|
79
|
+
"types#": "to do: next major: remove field",
|
|
80
|
+
"types": "index.d.ts",
|
|
81
|
+
"type": "module",
|
|
82
|
+
"version": "1.3.0",
|
|
83
|
+
"xo": {
|
|
84
|
+
"prettier": true,
|
|
85
|
+
"rules": {
|
|
86
|
+
"unicorn/prefer-code-point": "off"
|
|
87
|
+
},
|
|
88
|
+
"space": true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# decode-named-character-reference
|
|
2
|
+
|
|
3
|
+
[![Build Status][build-badge]][build]
|
|
4
|
+
[![Coverage Status][coverage-badge]][coverage]
|
|
5
|
+
[![Downloads][downloads-badge]][downloads]
|
|
6
|
+
[![Size][size-badge]][size]
|
|
7
|
+
|
|
8
|
+
Decode named character references.
|
|
9
|
+
|
|
10
|
+
## Contents
|
|
11
|
+
|
|
12
|
+
* [What is this?](#what-is-this)
|
|
13
|
+
* [When should I use this?](#when-should-i-use-this)
|
|
14
|
+
* [Install](#install)
|
|
15
|
+
* [Use](#use)
|
|
16
|
+
* [API](#api)
|
|
17
|
+
* [`decodeNamedCharacterReference(value)`](#decodenamedcharacterreferencevalue)
|
|
18
|
+
* [Types](#types)
|
|
19
|
+
* [Compatibility](#compatibility)
|
|
20
|
+
* [Security](#security)
|
|
21
|
+
* [Related](#related)
|
|
22
|
+
* [Contribute](#contribute)
|
|
23
|
+
* [License](#license)
|
|
24
|
+
|
|
25
|
+
## What is this?
|
|
26
|
+
|
|
27
|
+
A workaround for webpack.
|
|
28
|
+
|
|
29
|
+
## When should I use this?
|
|
30
|
+
|
|
31
|
+
Never use this.
|
|
32
|
+
Use [`parse-entities`][parse-entities].
|
|
33
|
+
It uses this.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
This package is [ESM only][esm].
|
|
38
|
+
In Node.js (version 14.14+, 16.0+), install with [npm][]:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npm install decode-named-character-reference
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In Deno with [`esm.sh`][esmsh]:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import {decodeNamedCharacterReference} from 'https://esm.sh/decode-named-character-reference@1'
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
In browsers with [`esm.sh`][esmsh]:
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<script type="module">
|
|
54
|
+
import {decodeNamedCharacterReference} from 'https://esm.sh/decode-named-character-reference@1?bundle'
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Use
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import {decodeNamedCharacterReference} from 'decode-named-character-reference'
|
|
62
|
+
|
|
63
|
+
decodeNamedCharacterReference('amp') //=> '&'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API
|
|
67
|
+
|
|
68
|
+
This package exports the identifier `decodeNamedCharacterReference`.
|
|
69
|
+
There is no default export.
|
|
70
|
+
|
|
71
|
+
### `decodeNamedCharacterReference(value)`
|
|
72
|
+
|
|
73
|
+
Again, use [`parse-entities`][parse-entities].
|
|
74
|
+
|
|
75
|
+
## Types
|
|
76
|
+
|
|
77
|
+
This package is fully typed with [TypeScript][].
|
|
78
|
+
It exports no additional types.
|
|
79
|
+
|
|
80
|
+
## Compatibility
|
|
81
|
+
|
|
82
|
+
This package is at least compatible with all maintained versions of Node.js.
|
|
83
|
+
As of now, that is Node.js 14.14+ and 16.0+.
|
|
84
|
+
It also works in Deno and modern browsers.
|
|
85
|
+
|
|
86
|
+
## Security
|
|
87
|
+
|
|
88
|
+
This package is safe.
|
|
89
|
+
|
|
90
|
+
## Related
|
|
91
|
+
|
|
92
|
+
* [`parse-entities`][parse-entities]
|
|
93
|
+
— parse (decode) HTML character references
|
|
94
|
+
|
|
95
|
+
## Contribute
|
|
96
|
+
|
|
97
|
+
Yes please!
|
|
98
|
+
See [How to Contribute to Open Source][contribute].
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
[MIT][license] © [Titus Wormer][author]
|
|
103
|
+
|
|
104
|
+
<!-- Definitions -->
|
|
105
|
+
|
|
106
|
+
[author]: https://wooorm.com
|
|
107
|
+
|
|
108
|
+
[build]: https://github.com/wooorm/decode-named-character-reference/actions
|
|
109
|
+
|
|
110
|
+
[build-badge]: https://github.com/wooorm/decode-named-character-reference/workflows/main/badge.svg
|
|
111
|
+
|
|
112
|
+
[contribute]: https://opensource.guide/how-to-contribute/
|
|
113
|
+
|
|
114
|
+
[coverage]: https://codecov.io/github/wooorm/decode-named-character-reference
|
|
115
|
+
|
|
116
|
+
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/decode-named-character-reference.svg
|
|
117
|
+
|
|
118
|
+
[downloads]: https://www.npmjs.com/package/decode-named-character-reference
|
|
119
|
+
|
|
120
|
+
[downloads-badge]: https://img.shields.io/npm/dm/decode-named-character-reference.svg
|
|
121
|
+
|
|
122
|
+
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
|
123
|
+
|
|
124
|
+
[esmsh]: https://esm.sh
|
|
125
|
+
|
|
126
|
+
[license]: license
|
|
127
|
+
|
|
128
|
+
[npm]: https://docs.npmjs.com/cli/install
|
|
129
|
+
|
|
130
|
+
[parse-entities]: https://github.com/wooorm/parse-entities
|
|
131
|
+
|
|
132
|
+
[size]: https://bundlephobia.com/result?p=decode-named-character-reference
|
|
133
|
+
|
|
134
|
+
[size-badge]: https://img.shields.io/bundlephobia/minzip/decode-named-character-reference.svg
|
|
135
|
+
|
|
136
|
+
[typescript]: https://www.typescriptlang.org
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
|
|
2
|
+
|
|
3
|
+
export type Options = {
|
|
4
|
+
/**
|
|
5
|
+
Whether to treat an `'ambiguous'` character as wide.
|
|
6
|
+
|
|
7
|
+
@default true
|
|
8
|
+
|
|
9
|
+
@example
|
|
10
|
+
```
|
|
11
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
12
|
+
|
|
13
|
+
const codePoint = '⛣'.codePointAt(0);
|
|
14
|
+
|
|
15
|
+
console.log(eastAsianWidth(codePoint));
|
|
16
|
+
//=> 1
|
|
17
|
+
|
|
18
|
+
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
|
|
19
|
+
//=> 2
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
|
|
23
|
+
> - http://www.unicode.org/reports/tr11/
|
|
24
|
+
*/
|
|
25
|
+
readonly ambiguousAsWide?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
Returns the width as a number for the given code point.
|
|
30
|
+
|
|
31
|
+
@param codePoint - A Unicode code point.
|
|
32
|
+
|
|
33
|
+
@example
|
|
34
|
+
```
|
|
35
|
+
import {eastAsianWidth} from 'get-east-asian-width';
|
|
36
|
+
|
|
37
|
+
const codePoint = '字'.codePointAt(0);
|
|
38
|
+
|
|
39
|
+
console.log(eastAsianWidth(codePoint));
|
|
40
|
+
//=> 2
|
|
41
|
+
```
|
|
42
|
+
*/
|
|
43
|
+
export function eastAsianWidth(codePoint: number, options?: Options): 1 | 2;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
Returns the type of “East Asian Width” for the given code point.
|
|
47
|
+
|
|
48
|
+
@param codePoint - A Unicode code point.
|
|
49
|
+
|
|
50
|
+
@example
|
|
51
|
+
```
|
|
52
|
+
import {eastAsianWidthType} from 'get-east-asian-width';
|
|
53
|
+
|
|
54
|
+
const codePoint = '字'.codePointAt(0);
|
|
55
|
+
|
|
56
|
+
console.log(eastAsianWidthType(codePoint));
|
|
57
|
+
//=> 'wide'
|
|
58
|
+
```
|
|
59
|
+
*/
|
|
60
|
+
export function eastAsianWidthType(codePoint: number): WidthType;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {getCategory, isAmbiguous, isFullWidth, isWide} from './lookup.js';
|
|
2
|
+
|
|
3
|
+
function validate(codePoint) {
|
|
4
|
+
if (!Number.isSafeInteger(codePoint)) {
|
|
5
|
+
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function eastAsianWidthType(codePoint) {
|
|
10
|
+
validate(codePoint);
|
|
11
|
+
|
|
12
|
+
return getCategory(codePoint);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
|
|
16
|
+
validate(codePoint);
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
isFullWidth(codePoint)
|
|
20
|
+
|| isWide(codePoint)
|
|
21
|
+
|| (ambiguousAsWide && isAmbiguous(codePoint))
|
|
22
|
+
) {
|
|
23
|
+
return 2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Private exports for https://github.com/sindresorhus/is-fullwidth-code-point
|
|
30
|
+
export {isFullWidth as _isFullWidth, isWide as _isWide} from './lookup.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|