@atproto/lex-data 0.0.2 → 0.0.4
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 +20 -0
- package/dist/blob.d.ts +6 -0
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +4 -1
- package/dist/blob.js.map +1 -1
- package/dist/cid.d.ts +2 -3
- package/dist/cid.d.ts.map +1 -1
- package/dist/cid.js.map +1 -1
- package/dist/language.d.ts +2 -2
- package/dist/language.d.ts.map +1 -1
- package/dist/language.js +4 -4
- package/dist/language.js.map +1 -1
- package/dist/lex.d.ts.map +1 -1
- package/dist/lex.js +49 -48
- package/dist/lex.js.map +1 -1
- package/dist/object.d.ts +13 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +15 -2
- package/dist/object.js.map +1 -1
- package/dist/uint8array-base64.d.ts +3 -0
- package/dist/uint8array-base64.d.ts.map +1 -0
- package/dist/uint8array-base64.js +3 -0
- package/dist/uint8array-base64.js.map +1 -0
- package/dist/uint8array-from-base64.d.ts +4 -3
- package/dist/uint8array-from-base64.d.ts.map +1 -1
- package/dist/uint8array-from-base64.js +9 -6
- package/dist/uint8array-from-base64.js.map +1 -1
- package/dist/uint8array-to-base64.d.ts +4 -3
- package/dist/uint8array-to-base64.d.ts.map +1 -1
- package/dist/uint8array-to-base64.js +7 -6
- package/dist/uint8array-to-base64.js.map +1 -1
- package/dist/uint8array.d.ts +6 -3
- package/dist/uint8array.d.ts.map +1 -1
- package/dist/uint8array.js +2 -1
- package/dist/uint8array.js.map +1 -1
- package/package.json +1 -1
- package/src/blob.ts +12 -1
- package/src/cid.ts +7 -7
- package/src/language.test.ts +33 -33
- package/src/language.ts +2 -2
- package/src/lex.test.ts +104 -1
- package/src/lex.ts +50 -43
- package/src/object.ts +16 -4
- package/src/uint8array-base64.ts +2 -0
- package/src/uint8array-from-base64.test.ts +33 -19
- package/src/uint8array-from-base64.ts +19 -6
- package/src/uint8array-to-base64.test.ts +170 -0
- package/src/uint8array-to-base64.ts +18 -8
- package/src/uint8array.ts +13 -5
- package/tsconfig.tests.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @atproto/lex-data
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use stack based approach in `isLexValue` allowing to be called with very deep structures;
|
|
8
|
+
|
|
9
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Do not throw an error from `isLexScalar` (return `false` instead)
|
|
10
|
+
|
|
11
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Forbid use of unsafe integers
|
|
12
|
+
|
|
13
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Expose `isPlainProto` utility to check if an object is a plain object.
|
|
14
|
+
|
|
15
|
+
- [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename `parseLanguage` and `isLanguage` exports to `parseLanguageString` and `isLanguageString` respectively
|
|
16
|
+
|
|
17
|
+
## 0.0.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#4422](https://github.com/bluesky-social/atproto/pull/4422) [`693784c`](https://github.com/bluesky-social/atproto/commit/693784c3a0dee4b6a29aa1e018fce682dcae148f) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add support for base64url encoding/decoding
|
|
22
|
+
|
|
3
23
|
## 0.0.2
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/blob.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Cid } from './cid.js';
|
|
2
|
+
/**
|
|
3
|
+
* @note {@link BlobRef} is just a {@link LexMap} with a specific shape.
|
|
4
|
+
*/
|
|
2
5
|
export type BlobRef = {
|
|
3
6
|
$type: 'blob';
|
|
4
7
|
mimeType: string;
|
|
@@ -8,6 +11,9 @@ export type BlobRef = {
|
|
|
8
11
|
export declare function isBlobRef(input: unknown, options?: {
|
|
9
12
|
strict?: boolean;
|
|
10
13
|
}): input is BlobRef;
|
|
14
|
+
/**
|
|
15
|
+
* @note {@link LegacyBlobRef} is just a {@link LexMap} with a specific shape.
|
|
16
|
+
*/
|
|
11
17
|
export type LegacyBlobRef = {
|
|
12
18
|
cid: string;
|
|
13
19
|
mimeType: string;
|
package/dist/blob.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAKJ,MAAM,UAAU,CAAA;AAGjB,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,KAAK,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"blob.d.ts","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAKJ,MAAM,UAAU,CAAA;AAGjB;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;IACR,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,wBAAgB,SAAS,CACvB,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,KAAK,IAAI,OAAO,CAyDlB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CA2BtE"}
|
package/dist/blob.js
CHANGED
|
@@ -16,7 +16,10 @@ function isBlobRef(input, options) {
|
|
|
16
16
|
if (typeof mimeType !== 'string' || !mimeType.includes('/')) {
|
|
17
17
|
return false;
|
|
18
18
|
}
|
|
19
|
-
if (typeof size !== 'number' ||
|
|
19
|
+
if (typeof size !== 'number' ||
|
|
20
|
+
size < 0 ||
|
|
21
|
+
!Number.isInteger(size) ||
|
|
22
|
+
!Number.isSafeInteger(size)) {
|
|
20
23
|
return false;
|
|
21
24
|
}
|
|
22
25
|
if (typeof ref !== 'object' || ref === null) {
|
package/dist/blob.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"blob.js","sourceRoot":"","sources":["../src/blob.ts"],"names":[],"mappings":";;AAmBA,8BA4DC;AAUD,0CA2BC;AApHD,qCAMiB;AACjB,2CAA2C;AAY3C,S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,CAAC,IAAI,KAAK,2BAAkB,EAAE,CAAC;YACpC,OAAO,KAAK,CAAA;QACd,CAAC;QACD,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,KAAK,gCAAuB,EAAE,CAAC;YACnD,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AAUD,SAAgB,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,IAAA,yBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAC/B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAA;IACd,CAAC;IAED,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;YACxC,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACH,IAAA,iBAAQ,EAAC,GAAG,CAAC,CAAA;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import {\n Cid,\n RAW_BIN_MULTICODEC,\n SHA2_256_MULTIHASH_CODE,\n asCid,\n parseCid,\n} from './cid.js'\nimport { isPlainObject } from './object.js'\n\n/**\n * @note {@link BlobRef} is just a {@link LexMap} with a specific shape.\n */\nexport type BlobRef = {\n $type: 'blob'\n mimeType: string\n ref: Cid\n size: number\n}\n\nexport function isBlobRef(\n input: unknown,\n options?: { strict?: boolean },\n): input is BlobRef {\n if (!isPlainObject(input)) {\n return false\n }\n\n if (input?.$type !== 'blob') {\n return false\n }\n\n const { mimeType, size, ref } = input\n // @NOTE Very basic mime validation\n if (typeof mimeType !== 'string' || !mimeType.includes('/')) {\n return false\n }\n\n if (\n typeof size !== 'number' ||\n size < 0 ||\n !Number.isInteger(size) ||\n !Number.isSafeInteger(size)\n ) {\n return false\n }\n\n if (typeof ref !== 'object' || ref === null) {\n return false\n }\n\n for (const key in input) {\n if (\n key !== '$type' &&\n key !== 'mimeType' &&\n key !== 'ref' &&\n key !== 'size'\n ) {\n return false\n }\n }\n\n const cid = asCid(ref)\n if (!cid) {\n return false\n }\n\n if (options?.strict) {\n if (cid.version !== 1) {\n return false\n }\n if (cid.code !== RAW_BIN_MULTICODEC) {\n return false\n }\n if (cid.multihash.code !== SHA2_256_MULTIHASH_CODE) {\n return false\n }\n }\n\n return true\n}\n\n/**\n * @note {@link LegacyBlobRef} is just a {@link LexMap} with a specific shape.\n */\nexport type LegacyBlobRef = {\n cid: string\n mimeType: string\n}\n\nexport function isLegacyBlobRef(input: unknown): input is LegacyBlobRef {\n if (!isPlainObject(input)) {\n return false\n }\n\n const { cid, mimeType } = input\n if (typeof cid !== 'string') {\n return false\n }\n\n if (typeof mimeType !== 'string') {\n return false\n }\n\n for (const key in input) {\n if (key !== 'cid' && key !== 'mimeType') {\n return false\n }\n }\n\n try {\n parseCid(cid)\n } catch {\n return false\n }\n\n return true\n}\n"]}
|
package/dist/cid.d.ts
CHANGED
|
@@ -18,15 +18,14 @@ declare module 'multiformats/cid' {
|
|
|
18
18
|
* `multiformats/cid` in dependent packages, and instead have them rely on the
|
|
19
19
|
* {@link Cid} interface from `@atproto/lex-data`. The {@link CID} class from
|
|
20
20
|
* `multiformats` version <10 has compatibility issues with certain TypeScript
|
|
21
|
-
*
|
|
22
|
-
* packages.
|
|
21
|
+
* configuration, which can lead to type errors in dependent packages.
|
|
23
22
|
*
|
|
24
23
|
* We are stuck with version 9 because `@atproto` packages did not drop
|
|
25
24
|
* CommonJS support yet, and multiformats version 10 only supports ES modules.
|
|
26
25
|
*
|
|
27
26
|
* In order to avoid compatibility issues, while preparing for future breaking
|
|
28
27
|
* changes (CID in multiformats v10+ has a slightly different interface), as
|
|
29
|
-
* we update or swap out `multiformats`, we provide our own stable
|
|
28
|
+
* we update or swap out `multiformats`, we provide our own stable {@link Cid}
|
|
30
29
|
* interface.
|
|
31
30
|
*/
|
|
32
31
|
interface CID {
|
package/dist/cid.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,eAAO,MAAM,mBAAmB,MAAO,CAAA;AACvC,eAAO,MAAM,kBAAkB,KAAO,CAAA;AAEtC,eAAO,MAAM,uBAAuB,KAAO,CAAA;AAE3C,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;IAC1D,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,OAAO,QAAQ,kBAAkB,CAAC;IAChC
|
|
1
|
+
{"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAEtC,eAAO,MAAM,mBAAmB,MAAO,CAAA;AACvC,eAAO,MAAM,kBAAkB,KAAO,CAAA;AAEtC,eAAO,MAAM,uBAAuB,KAAO,CAAA;AAE3C,MAAM,MAAM,eAAe,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;IAC1D,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,UAAU,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,CAAA;CAClB,CAAA;AAED,OAAO,QAAQ,kBAAkB,CAAC;IACh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AK,CAAA;AACpD,CAAC;AAED,SAAgB,cAAc,CAAC,KAAa;IAC1C,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,SAAgB,oBAAoB,CAAC,KAAa;IAChD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { CID } from 'multiformats/cid'\n\nexport const DAG_CBOR_MULTICODEC = 0x71\nexport const RAW_BIN_MULTICODEC = 0x55\n\nexport const SHA2_256_MULTIHASH_CODE = 0x12\n\nexport type MultihashDigest<Code extends number = number> = {\n code: Code\n digest: Uint8Array\n size: number\n bytes: Uint8Array\n}\n\ndeclare module 'multiformats/cid' {\n /**\n * @deprecated use the {@link Cid} interface from `@atproto/lex-data`, and\n * related helpers ({@link asCid}, {@link parseCid}, {@link decodeCid},\n * {@link createCid}, {@link isCid}), instead.\n *\n * This is marked as deprecated because we want to discourage direct usage of\n * `multiformats/cid` in dependent packages, and instead have them rely on the\n * {@link Cid} interface from `@atproto/lex-data`. The {@link CID} class from\n * `multiformats` version <10 has compatibility issues with certain TypeScript\n *
|
|
1
|
+
{"version":3,"file":"cid.js","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":";;;AAuEA,sBAEC;AAED,4BAEC;AAED,8BAEC;AAED,8BAEC;AAED,sBAsBC;AAED,8CAEC;AAED,wCAMC;AAED,oDAIC;AA/HD,0CAAsC;AAwD7B,oFAxDA,SAAG,OAwDA;AAtDC,QAAA,mBAAmB,GAAG,IAAI,CAAA;AAC1B,QAAA,kBAAkB,GAAG,IAAI,CAAA;AAEzB,QAAA,uBAAuB,GAAG,IAAI,CAAA;AAkE3C,SAAgB,KAAK,CAAC,KAAc;IAClC,OAAO,SAAG,CAAC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B,oBAAoB,CAAC,KAAa;IAChD,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;IACvC,CAAC;AACH,CAAC","sourcesContent":["import { CID } from 'multiformats/cid'\n\nexport const DAG_CBOR_MULTICODEC = 0x71\nexport const RAW_BIN_MULTICODEC = 0x55\n\nexport const SHA2_256_MULTIHASH_CODE = 0x12\n\nexport type MultihashDigest<Code extends number = number> = {\n code: Code\n digest: Uint8Array\n size: number\n bytes: Uint8Array\n}\n\ndeclare module 'multiformats/cid' {\n /**\n * @deprecated use the {@link Cid} interface from `@atproto/lex-data`, and\n * related helpers ({@link asCid}, {@link parseCid}, {@link decodeCid},\n * {@link createCid}, {@link isCid}), instead.\n *\n * This is marked as deprecated because we want to discourage direct usage of\n * `multiformats/cid` in dependent packages, and instead have them rely on the\n * {@link Cid} interface from `@atproto/lex-data`. The {@link CID} class from\n * `multiformats` version <10 has compatibility issues with certain TypeScript\n * configuration, which can lead to type errors in dependent packages.\n *\n * We are stuck with version 9 because `@atproto` packages did not drop\n * CommonJS support yet, and multiformats version 10 only supports ES modules.\n *\n * In order to avoid compatibility issues, while preparing for future breaking\n * changes (CID in multiformats v10+ has a slightly different interface), as\n * we update or swap out `multiformats`, we provide our own stable {@link Cid}\n * interface.\n */\n interface CID {}\n}\n\n// multiformats' CID class is not very portable because:\n//\n// - In dependent packages that use \"moduleResolution\" set to \"node16\",\n// \"nodenext\" or \"bundler\", TypeScript fails to properly resolve the\n// multiformats package when importing CID from @atproto/lex-data. This causes\n// type errors in those packages. This is caused by the fact that the\n// multiformats version <10 (which is the last version that supports CommonJS)\n// uses \"exports\" field in package.json, which do not contain \"types\"\n// entrypoints.\n// https://www.npmjs.com/package/multiformats/v/9.9.0?activeTab=code\n// - By defining our own interface and helper functions, we can have more\n// control over the public API exposed by this package.\n// - It allow us to have a stable interface in case we need to swap out, or\n// eventually update multiformats (should we choose to drop CommonJS support)\n// in the future.\n\n// @NOTE Even though it is not portable, we still re-export CID here so that\n// dependent packages where it can be used, have access to it (instead of\n// importing directly from \"multiformats\" or\"multiformats/cid\").\nexport { CID }\n\n/**\n * Interface for working with decoded CID string, compatible with\n * {@link CID} implementation.\n */\nexport interface Cid {\n version: 0 | 1\n code: number\n multihash: MultihashDigest\n bytes: Uint8Array\n equals(other: unknown): boolean\n toString(): string\n}\n\nexport function asCid(value: unknown): Cid | null {\n return CID.asCID(value)\n}\n\nexport function parseCid(input: string): Cid {\n return CID.parse(input)\n}\n\nexport function decodeCid(bytes: Uint8Array): Cid {\n return CID.decode(bytes)\n}\n\nexport function createCid(code: number, digest: MultihashDigest): Cid {\n return CID.createV1(code, digest)\n}\n\nexport function isCid(\n value: unknown,\n options?: { strict?: boolean },\n): value is Cid {\n const cid = asCid(value)\n if (!cid) {\n return false\n }\n\n if (options?.strict) {\n if (cid.version !== 1) {\n return false\n }\n if (cid.code !== RAW_BIN_MULTICODEC && cid.code !== DAG_CBOR_MULTICODEC) {\n return false\n }\n if (cid.multihash.code !== SHA2_256_MULTIHASH_CODE) {\n return false\n }\n }\n\n return true\n}\n\nexport function validateCidString(input: string): boolean {\n return parseCidString(input)?.toString() === input\n}\n\nexport function parseCidString(input: string): Cid | undefined {\n try {\n return parseCid(input)\n } catch {\n return undefined\n }\n}\n\nexport function ensureValidCidString(input: string): void {\n if (!validateCidString(input)) {\n throw new Error(`Invalid CID string`)\n }\n}\n"]}
|
package/dist/language.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ export type LanguageTag = {
|
|
|
8
8
|
extension?: string;
|
|
9
9
|
privateUse?: string;
|
|
10
10
|
};
|
|
11
|
-
export declare function
|
|
11
|
+
export declare function parseLanguageString(input: string): LanguageTag | null;
|
|
12
12
|
/**
|
|
13
13
|
* Validates well-formed BCP 47 syntax
|
|
14
14
|
*
|
|
15
15
|
* @see {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1}
|
|
16
16
|
*/
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function isLanguageString(input: string): boolean;
|
|
18
18
|
//# sourceMappingURL=language.d.ts.map
|
package/dist/language.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"language.d.ts","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAerE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvD"}
|
package/dist/language.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
3
|
+
exports.parseLanguageString = parseLanguageString;
|
|
4
|
+
exports.isLanguageString = isLanguageString;
|
|
5
5
|
const BCP47_REGEXP = /^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUseA>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUseB>x(-[A-Za-z0-9]{1,8})+))$/;
|
|
6
|
-
function
|
|
6
|
+
function parseLanguageString(input) {
|
|
7
7
|
const parsed = input.match(BCP47_REGEXP);
|
|
8
8
|
if (!parsed?.groups)
|
|
9
9
|
return null;
|
|
@@ -24,7 +24,7 @@ function parseLanguage(input) {
|
|
|
24
24
|
*
|
|
25
25
|
* @see {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1}
|
|
26
26
|
*/
|
|
27
|
-
function
|
|
27
|
+
function isLanguageString(input) {
|
|
28
28
|
return BCP47_REGEXP.test(input);
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=language.js.map
|
package/dist/language.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.js","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":";;AAcA,
|
|
1
|
+
{"version":3,"file":"language.js","sourceRoot":"","sources":["../src/language.ts"],"names":[],"mappings":";;AAcA,kDAeC;AAOD,4CAEC;AAtCD,MAAM,YAAY,GAChB,mlBAAmlB,CAAA;AAarlB,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;IACxC,IAAI,CAAC,MAAM,EAAE,MAAM;QAAE,OAAO,IAAI,CAAA;IAEhC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IACzB,OAAO;QACL,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,UAAU,EAAE,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW;KACrD,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACjC,CAAC","sourcesContent":["const BCP47_REGEXP =\n /^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUseA>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUseB>x(-[A-Za-z0-9]{1,8})+))$/\n\nexport type LanguageTag = {\n grandfathered?: string\n language?: string\n extlang?: string\n script?: string\n region?: string\n variant?: string\n extension?: string\n privateUse?: string\n}\n\nexport function parseLanguageString(input: string): LanguageTag | null {\n const parsed = input.match(BCP47_REGEXP)\n if (!parsed?.groups) return null\n\n const { groups } = parsed\n return {\n grandfathered: groups.grandfathered,\n language: groups.language,\n extlang: groups.extlang,\n script: groups.script,\n region: groups.region,\n variant: groups.variant,\n extension: groups.extension,\n privateUse: groups.privateUseA || groups.privateUseB,\n }\n}\n\n/**\n * Validates well-formed BCP 47 syntax\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1}\n */\nexport function isLanguageString(input: string): boolean {\n return BCP47_REGEXP.test(input)\n}\n"]}
|
package/dist/lex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lex.d.ts","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"lex.d.ts","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,UAAU,CAAA;AAGrC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,GAAG,GAAG,UAAU,CAAA;AAC3E,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,QAAQ,EAAE,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ;CAAE,CAAA;AAC5E,MAAM,MAAM,MAAM,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ;CAAE,CAAA;AACjD,MAAM,MAAM,QAAQ,GAAG,QAAQ,EAAE,CAAA;AAEjC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE5D;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAa9D;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CA8C5D;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AACpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,IAAI,WAAW,CAInE"}
|
package/dist/lex.js
CHANGED
|
@@ -8,74 +8,75 @@ exports.isTypedLexMap = isTypedLexMap;
|
|
|
8
8
|
const cid_js_1 = require("./cid.js");
|
|
9
9
|
const object_js_1 = require("./object.js");
|
|
10
10
|
function isLexMap(value) {
|
|
11
|
-
|
|
12
|
-
return false;
|
|
13
|
-
for (const key in value) {
|
|
14
|
-
if (!isLexValue(value[key]))
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
11
|
+
return (0, object_js_1.isPlainObject)(value) && Object.values(value).every(isLexValue);
|
|
18
12
|
}
|
|
19
13
|
function isLexArray(value) {
|
|
20
|
-
|
|
21
|
-
return false;
|
|
22
|
-
for (let i = 0; i < value.length; i++) {
|
|
23
|
-
if (!isLexValue(value[i]))
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
14
|
+
return Array.isArray(value) && value.every(isLexValue);
|
|
27
15
|
}
|
|
28
16
|
function isLexScalar(value) {
|
|
29
17
|
switch (typeof value) {
|
|
30
18
|
case 'object':
|
|
31
|
-
|
|
32
|
-
return true;
|
|
33
|
-
return value instanceof Uint8Array || (0, cid_js_1.isCid)(value);
|
|
19
|
+
return value === null || value instanceof Uint8Array || (0, cid_js_1.isCid)(value);
|
|
34
20
|
case 'string':
|
|
35
21
|
case 'boolean':
|
|
36
22
|
return true;
|
|
37
23
|
case 'number':
|
|
38
24
|
if (Number.isInteger(value))
|
|
39
25
|
return true;
|
|
40
|
-
|
|
26
|
+
// fallthrough
|
|
41
27
|
default:
|
|
42
|
-
|
|
28
|
+
return false;
|
|
43
29
|
}
|
|
44
30
|
}
|
|
45
31
|
function isLexValue(value) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
// Using a stack to avoid recursion depth issues.
|
|
33
|
+
const stack = [value];
|
|
34
|
+
// Cyclic structures are not valid LexValues as they cannot be serialized to
|
|
35
|
+
// JSON or CBOR. This also allows us to avoid infinite loops when traversing
|
|
36
|
+
// the structure.
|
|
37
|
+
const visited = new Set();
|
|
38
|
+
do {
|
|
39
|
+
const value = stack.pop();
|
|
40
|
+
// Optimization: we are not using `isLexScalar` here to avoid extra function
|
|
41
|
+
// calls, and to avoid computing `typeof value` multiple times.
|
|
42
|
+
switch (typeof value) {
|
|
43
|
+
case 'object':
|
|
44
|
+
if (value === null) {
|
|
45
|
+
// LexScalar
|
|
46
|
+
}
|
|
47
|
+
else if ((0, object_js_1.isPlainProto)(value)) {
|
|
48
|
+
if (visited.has(value))
|
|
60
49
|
return false;
|
|
50
|
+
visited.add(value);
|
|
51
|
+
stack.push(...Object.values(value));
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if ((0, object_js_1.isPlainObject)(value)) {
|
|
65
|
-
for (const key in value) {
|
|
66
|
-
if (!isLexValue(value[key]))
|
|
53
|
+
else if (Array.isArray(value)) {
|
|
54
|
+
if (visited.has(value))
|
|
67
55
|
return false;
|
|
56
|
+
visited.add(value);
|
|
57
|
+
stack.push(...value);
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
else if (value instanceof Uint8Array || (0, cid_js_1.isCid)(value)) {
|
|
60
|
+
// LexScalar
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'string':
|
|
67
|
+
case 'boolean':
|
|
68
|
+
break;
|
|
69
|
+
case 'number':
|
|
70
|
+
if (Number.isInteger(value))
|
|
71
|
+
break;
|
|
72
|
+
// fallthrough
|
|
73
|
+
default:
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
} while (stack.length > 0);
|
|
77
|
+
// Optimization: ease GC's work
|
|
78
|
+
visited.clear();
|
|
79
|
+
return true;
|
|
79
80
|
}
|
|
80
81
|
function isTypedLexMap(value) {
|
|
81
82
|
return (isLexMap(value) && typeof value.$type === 'string' && value.$type.length > 0);
|
package/dist/lex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lex.js","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"lex.js","sourceRoot":"","sources":["../src/lex.ts"],"names":[],"mappings":";;AAQA,4BAEC;AAED,gCAEC;AAED,kCAaC;AAED,gCA8CC;AAGD,sCAIC;AApFD,qCAAqC;AACrC,2CAAyD;AAOzD,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,IAAA,yBAAa,EAAC,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;AACvE,CAAC;AAED,SAAgB,UAAU,CAAC,KAAc;IACvC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CA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AG,CAAC,KAAK,CAAC;wBAAE,OAAO,KAAK,CAAA;oBACpC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;oBAClB,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;gBACtB,CAAC;qBAAM,IAAI,KAAK,YAAY,UAAU,IAAI,IAAA,cAAK,EAAC,KAAK,CAAC,EAAE,CAAC;oBACvD,YAAY;gBACd,CAAC;qBAAM,CAAC;oBACN,OAAO,KAAK,CAAA;gBACd,CAAC;gBACD,MAAK;YACP,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS;gBACZ,MAAK;YACP,KAAK,QAAQ;gBACX,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC;oBAAE,MAAK;YACpC,cAAc;YACd;gBACE,OAAO,KAAK,CAAA;QAChB,CAAC;IACH,CAAC,QAAQ,KAAK,CAAC,MAAM,GAAG,CAAC,EAAC;IAE1B,+BAA+B;IAC/B,OAAO,CAAC,KAAK,EAAE,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC;AAGD,SAAgB,aAAa,CAAC,KAAe;IAC3C,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAC7E,CAAA;AACH,CAAC","sourcesContent":["import { Cid, isCid } from './cid.js'\nimport { isPlainObject, isPlainProto } from './object.js'\n\nexport type LexScalar = number | string | boolean | null | Cid | Uint8Array\nexport type LexValue = LexScalar | LexValue[] | { [_ in string]?: LexValue }\nexport type LexMap = { [_ in string]?: LexValue }\nexport type LexArray = LexValue[]\n\nexport function isLexMap(value: unknown): value is LexMap {\n return isPlainObject(value) && Object.values(value).every(isLexValue)\n}\n\nexport function isLexArray(value: unknown): value is LexArray {\n return Array.isArray(value) && value.every(isLexValue)\n}\n\nexport function isLexScalar(value: unknown): value is LexScalar {\n switch (typeof value) {\n case 'object':\n return value === null || value instanceof Uint8Array || isCid(value)\n case 'string':\n case 'boolean':\n return true\n case 'number':\n if (Number.isInteger(value)) return true\n // fallthrough\n default:\n return false\n }\n}\n\nexport function isLexValue(value: unknown): value is LexValue {\n // Using a stack to avoid recursion depth issues.\n const stack: unknown[] = [value]\n // Cyclic structures are not valid LexValues as they cannot be serialized to\n // JSON or CBOR. This also allows us to avoid infinite loops when traversing\n // the structure.\n const visited = new Set<object>()\n\n do {\n const value = stack.pop()!\n\n // Optimization: we are not using `isLexScalar` here to avoid extra function\n // calls, and to avoid computing `typeof value` multiple times.\n switch (typeof value) {\n case 'object':\n if (value === null) {\n // LexScalar\n } else if (isPlainProto(value)) {\n if (visited.has(value)) return false\n visited.add(value)\n stack.push(...Object.values(value))\n } else if (Array.isArray(value)) {\n if (visited.has(value)) return false\n visited.add(value)\n stack.push(...value)\n } else if (value instanceof Uint8Array || isCid(value)) {\n // LexScalar\n } else {\n return false\n }\n break\n case 'string':\n case 'boolean':\n break\n case 'number':\n if (Number.isInteger(value)) break\n // fallthrough\n default:\n return false\n }\n } while (stack.length > 0)\n\n // Optimization: ease GC's work\n visited.clear()\n\n return true\n}\n\nexport type TypedLexMap = LexMap & { $type: string }\nexport function isTypedLexMap(value: LexValue): value is TypedLexMap {\n return (\n isLexMap(value) && typeof value.$type === 'string' && value.$type.length > 0\n )\n}\n"]}
|
package/dist/object.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the input is an object (not null).
|
|
3
|
+
*/
|
|
1
4
|
export declare function isObject(input: unknown): input is object;
|
|
2
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether the input is an object (not null) whose prototype is either
|
|
7
|
+
* null or `Object.prototype`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isPlainObject(input: unknown): input is Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Checks whether the prototype of the input object is either null or
|
|
12
|
+
* `Object.prototype`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPlainProto(input: object): input is Record<string, unknown>;
|
|
3
15
|
//# sourceMappingURL=object.d.ts.map
|
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAKD,wBAAgB,aAAa,
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAKD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,oCAE3C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAU5E"}
|
package/dist/object.js
CHANGED
|
@@ -2,14 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObject = isObject;
|
|
4
4
|
exports.isPlainObject = isPlainObject;
|
|
5
|
+
exports.isPlainProto = isPlainProto;
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether the input is an object (not null).
|
|
8
|
+
*/
|
|
5
9
|
function isObject(input) {
|
|
6
10
|
return input != null && typeof input === 'object';
|
|
7
11
|
}
|
|
8
12
|
const ObjectProto = Object.prototype;
|
|
9
13
|
const ObjectToString = Object.prototype.toString;
|
|
14
|
+
/**
|
|
15
|
+
* Checks whether the input is an object (not null) whose prototype is either
|
|
16
|
+
* null or `Object.prototype`.
|
|
17
|
+
*/
|
|
10
18
|
function isPlainObject(input) {
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
return isObject(input) && isPlainProto(input);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether the prototype of the input object is either null or
|
|
23
|
+
* `Object.prototype`.
|
|
24
|
+
*/
|
|
25
|
+
function isPlainProto(input) {
|
|
13
26
|
const proto = Object.getPrototypeOf(input);
|
|
14
27
|
if (proto === null)
|
|
15
28
|
return true;
|
package/dist/object.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;AAGA,4BAEC;AASD,sCAEC;AAMD,oCAUC;AAhCD;;GAEG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AACnD,CAAC;AAED,MAAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAA;AACpC,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAA;AAEhD;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAa;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC1C,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC/B,OAAO,CACL,CAAC,KAAK,KAAK,WAAW;QACpB,sEAAsE;QACtE,6BAA6B;QAC7B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;QACxC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,iBAAiB,CACjD,CAAA;AACH,CAAC","sourcesContent":["/**\n * Checks whether the input is an object (not null).\n */\nexport function isObject(input: unknown): input is object {\n return input != null && typeof input === 'object'\n}\n\nconst ObjectProto = Object.prototype\nconst ObjectToString = Object.prototype.toString\n\n/**\n * Checks whether the input is an object (not null) whose prototype is either\n * null or `Object.prototype`.\n */\nexport function isPlainObject(input: unknown) {\n return isObject(input) && isPlainProto(input)\n}\n\n/**\n * Checks whether the prototype of the input object is either null or\n * `Object.prototype`.\n */\nexport function isPlainProto(input: object): input is Record<string, unknown> {\n const proto = Object.getPrototypeOf(input)\n if (proto === null) return true\n return (\n (proto === ObjectProto ||\n // Needed to support NodeJS's `runInNewContext` which produces objects\n // with a different prototype\n Object.getPrototypeOf(proto) === null) &&\n ObjectToString.call(input) === '[object Object]'\n )\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint8array-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-base64.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uint8array-base64.js","sourceRoot":"","sources":["../src/uint8array-base64.ts"],"names":[],"mappings":"","sourcesContent":["/** @default 'base64' */\nexport type Base64Alphabet = 'base64' | 'base64url'\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Base64Alphabet } from './uint8array-base64.js';
|
|
1
2
|
declare global {
|
|
2
3
|
interface Uint8ArrayConstructor {
|
|
3
4
|
/**
|
|
@@ -10,7 +11,7 @@ declare global {
|
|
|
10
11
|
}) => Uint8Array;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
export declare const fromBase64Native: ((b64: string) => Uint8Array) | null;
|
|
14
|
-
export declare const fromBase64Node: ((b64: string) => Uint8Array) | null;
|
|
15
|
-
export declare function fromBase64Ponyfill(b64: string): Uint8Array;
|
|
14
|
+
export declare const fromBase64Native: ((b64: string, alphabet?: Base64Alphabet) => Uint8Array) | null;
|
|
15
|
+
export declare const fromBase64Node: ((b64: string, alphabet?: Base64Alphabet) => Uint8Array) | null;
|
|
16
|
+
export declare function fromBase64Ponyfill(b64: string, alphabet?: Base64Alphabet): Uint8Array;
|
|
16
17
|
//# sourceMappingURL=uint8array-from-base64.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-from-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uint8array-from-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B;;WAEG;QACH,UAAU,CAAC,EAAE,CACX,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;YACR,wBAAwB;YACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;YACjC,iBAAiB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,qBAAqB,CAAA;SAC/D,KACE,UAAU,CAAA;KAChB;CACF;AAED,eAAO,MAAM,gBAAgB,SAGhB,MAAM,aACD,cAAc,KACvB,UAAU,QAMT,CAAA;AAEV,eAAO,MAAM,cAAc,SAEhB,MAAM,aACD,cAAc,KACvB,UAAU,QAQT,CAAA;AAER,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,cAAyB,GAClC,UAAU,CAIZ"}
|
|
@@ -6,13 +6,16 @@ const from_string_1 = require("uint8arrays/from-string");
|
|
|
6
6
|
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
7
|
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
8
8
|
exports.fromBase64Native = typeof Uint8Array.fromBase64 === 'function'
|
|
9
|
-
? function fromBase64Native(b64) {
|
|
10
|
-
return Uint8Array.fromBase64(b64, {
|
|
9
|
+
? function fromBase64Native(b64, alphabet = 'base64') {
|
|
10
|
+
return Uint8Array.fromBase64(b64, {
|
|
11
|
+
alphabet,
|
|
12
|
+
lastChunkHandling: 'loose',
|
|
13
|
+
});
|
|
11
14
|
}
|
|
12
15
|
: null;
|
|
13
16
|
exports.fromBase64Node = Buffer
|
|
14
|
-
? function fromBase64Node(b64) {
|
|
15
|
-
const bytes = Buffer.from(b64,
|
|
17
|
+
? function fromBase64Node(b64, alphabet = 'base64') {
|
|
18
|
+
const bytes = Buffer.from(b64, alphabet);
|
|
16
19
|
verifyBase64ForBytes(b64, bytes);
|
|
17
20
|
// Convert to Uint8Array because even though Buffer is a sub class of
|
|
18
21
|
// Uint8Array, it serializes differently to Uint8Array (e.g. in JSON) and
|
|
@@ -20,8 +23,8 @@ exports.fromBase64Node = Buffer
|
|
|
20
23
|
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
21
24
|
}
|
|
22
25
|
: null;
|
|
23
|
-
function fromBase64Ponyfill(b64) {
|
|
24
|
-
const bytes = (0, from_string_1.fromString)(b64, '
|
|
26
|
+
function fromBase64Ponyfill(b64, alphabet = 'base64') {
|
|
27
|
+
const bytes = (0, from_string_1.fromString)(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet);
|
|
25
28
|
verifyBase64ForBytes(b64, bytes);
|
|
26
29
|
return bytes;
|
|
27
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-from-base64.js","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"uint8array-from-base64.js","sourceRoot":"","sources":["../src/uint8array-from-base64.ts"],"names":[],"mappings":";;;AAiDA,gDAOC;AAxDD,yDAAoD;AACpD,6DAAqD;AAGrD,MAAM,MAAM,GAAG,+BAAY,CAAA;AAkBd,QAAA,gBAAgB,GAC3B,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU;IACzC,CAAC,CAAC,SAAS,gBAAgB,CACvB,GAAW,EACX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AAC;YACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;QAC1C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { fromString } from 'uint8arrays/from-string'\nimport { NodeJSBuffer } from './lib/nodejs-buffer.js'\nimport { Base64Alphabet } from './uint8array-base64.js'\n\nconst Buffer = NodeJSBuffer\n\ndeclare global {\n interface Uint8ArrayConstructor {\n /**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/fromBase64 Uint8Array.fromBase64()}\n */\n fromBase64?: (\n b64: string,\n options?: {\n /** @default 'base64' */\n alphabet?: 'base64' | 'base64url'\n lastChunkHandling?: 'loose' | 'strict' | 'stop-before-partial'\n },\n ) => Uint8Array\n }\n}\n\nexport const fromBase64Native =\n typeof Uint8Array.fromBase64 === 'function'\n ? function fromBase64Native(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n return Uint8Array.fromBase64!(b64, {\n alphabet,\n lastChunkHandling: 'loose',\n })\n }\n : null\n\nexport const fromBase64Node = Buffer\n ? function fromBase64Node(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n ): Uint8Array {\n const bytes = Buffer.from(b64, alphabet)\n verifyBase64ForBytes(b64, bytes)\n // Convert to Uint8Array because even though Buffer is a sub class of\n // Uint8Array, it serializes differently to Uint8Array (e.g. in JSON) and\n // results in unexpected behavior downstream (e.g. in tests)\n return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n }\n : null\n\nexport function fromBase64Ponyfill(\n b64: string,\n alphabet: Base64Alphabet = 'base64',\n): Uint8Array {\n const bytes = fromString(b64, b64.endsWith('=') ? `${alphabet}pad` : alphabet)\n verifyBase64ForBytes(b64, bytes)\n return bytes\n}\n\n// @NOTE NodeJS will silently stop decoding at the first invalid character,\n// while \"uint8arrays/from-string\" will not validate that the padding is\n// correct. The following function performs basic validation to ensure that the\n// input was a valid base64 string. The availability of the \"bytes\" allows\n// to perform checks with O[1] complexity.\nfunction verifyBase64ForBytes(b64: string, bytes: Uint8Array): void {\n const paddingCount = b64.endsWith('==') ? 2 : b64.endsWith('=') ? 1 : 0\n const trimmedLength = b64.length - paddingCount\n const expectedByteLength = Math.floor((trimmedLength * 3) / 4)\n if (bytes.length !== expectedByteLength) {\n throw new Error('Invalid base64 string')\n }\n\n const expectedB64Length = (bytes.length / 3) * 4\n const expectedPaddingCount =\n expectedB64Length % 4 === 0 ? 0 : 4 - (expectedB64Length % 4)\n const expectedFullB64Length = expectedB64Length + expectedPaddingCount\n if (b64.length > expectedFullB64Length) {\n throw new Error('Invalid base64 string')\n }\n\n // The previous might still allow false positive if only the last few\n // chars are invalid.\n for (\n let i = Math.ceil(expectedB64Length);\n i < b64.length - paddingCount;\n i++\n ) {\n const code = b64.charCodeAt(i)\n if (\n !(code >= 65 && code <= 90) && // A-Z\n !(code >= 97 && code <= 122) && // a-z\n !(code >= 48 && code <= 57) && // 0-9\n code !== 43 && // +\n code !== 47 // /\n ) {\n throw new Error('Invalid base64 string')\n }\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Base64Alphabet } from './uint8array-base64.js';
|
|
1
2
|
declare global {
|
|
2
3
|
interface Uint8Array {
|
|
3
4
|
/**
|
|
@@ -10,7 +11,7 @@ declare global {
|
|
|
10
11
|
}) => string;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
|
-
export declare const toBase64Native: ((bytes: Uint8Array) => string) | null;
|
|
14
|
-
export declare const toBase64Node: ((bytes: Uint8Array) => string) | null;
|
|
15
|
-
export declare function toBase64Ponyfill(bytes: Uint8Array): string;
|
|
14
|
+
export declare const toBase64Native: ((bytes: Uint8Array, alphabet?: Base64Alphabet) => string) | null;
|
|
15
|
+
export declare const toBase64Node: ((bytes: Uint8Array, alphabet?: Base64Alphabet) => string) | null;
|
|
16
|
+
export declare function toBase64Ponyfill(bytes: Uint8Array, alphabet?: Base64Alphabet): string;
|
|
16
17
|
//# sourceMappingURL=uint8array-to-base64.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uint8array-to-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uint8array-to-base64.d.ts","sourceRoot":"","sources":["../src/uint8array-to-base64.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAIvD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;WAEG;QACH,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;YACpB,wBAAwB;YACxB,QAAQ,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;YACjC,WAAW,CAAC,EAAE,OAAO,CAAA;SACtB,KAAK,MAAM,CAAA;KACb;CACF;AAED,eAAO,MAAM,cAAc,WAGZ,UAAU,aACP,cAAc,KACvB,MAAM,QAGL,CAAA;AAEV,eAAO,MAAM,YAAY,WAEZ,UAAU,aACP,cAAc,KACvB,MAAM,QAcL,CAAA;AAER,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,UAAU,EACjB,QAAQ,GAAE,cAAyB,GAClC,MAAM,CAER"}
|
|
@@ -6,13 +6,14 @@ const to_string_1 = require("uint8arrays/to-string");
|
|
|
6
6
|
const nodejs_buffer_js_1 = require("./lib/nodejs-buffer.js");
|
|
7
7
|
const Buffer = nodejs_buffer_js_1.NodeJSBuffer;
|
|
8
8
|
exports.toBase64Native = typeof Uint8Array.prototype.toBase64 === 'function'
|
|
9
|
-
? function toBase64Native(bytes) {
|
|
10
|
-
return bytes.toBase64({ omitPadding: true });
|
|
9
|
+
? function toBase64Native(bytes, alphabet = 'base64') {
|
|
10
|
+
return bytes.toBase64({ alphabet, omitPadding: true });
|
|
11
11
|
}
|
|
12
12
|
: null;
|
|
13
13
|
exports.toBase64Node = Buffer
|
|
14
|
-
? function toBase64Node(bytes) {
|
|
15
|
-
const
|
|
14
|
+
? function toBase64Node(bytes, alphabet = 'base64') {
|
|
15
|
+
const buffer = bytes instanceof Buffer ? bytes : Buffer.from(bytes);
|
|
16
|
+
const b64 = buffer.toString(alphabet);
|
|
16
17
|
// @NOTE We strip padding for strict compatibility with
|
|
17
18
|
// uint8arrays.toString behavior. Tests failing because of the presence of
|
|
18
19
|
// padding are not really synonymous with an actual error and we might
|
|
@@ -24,7 +25,7 @@ exports.toBase64Node = Buffer
|
|
|
24
25
|
: b64;
|
|
25
26
|
}
|
|
26
27
|
: null;
|
|
27
|
-
function toBase64Ponyfill(bytes) {
|
|
28
|
-
return (0, to_string_1.toString)(bytes,
|
|
28
|
+
function toBase64Ponyfill(bytes, alphabet = 'base64') {
|
|
29
|
+
return (0, to_string_1.toString)(bytes, alphabet);
|
|
29
30
|
}
|
|
30
31
|
//# sourceMappingURL=uint8array-to-base64.js.map
|