@readme/data-urls 2.0.0 → 3.0.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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2022, ReadMe
1
+ Copyright (c) 2023, ReadMe
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any purpose
4
4
  with or without fee is hereby granted, provided that the above copyright notice
@@ -1,3 +1,5 @@
1
+ 'use strict';
2
+
1
3
  // src/index.ts
2
4
  var DATA_URL_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s<>]*?)$/i;
3
5
  function validate(str) {
@@ -32,6 +34,7 @@ function parse(str) {
32
34
  return parsed;
33
35
  }
34
36
 
35
- export { parse, validate };
37
+ exports.parse = parse;
38
+ exports.validate = validate;
36
39
  //# sourceMappingURL=out.js.map
37
- //# sourceMappingURL=index.mjs.map
40
+ //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- 'use strict';
2
-
3
1
  // src/index.ts
4
2
  var DATA_URL_REGEX = /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s<>]*?)$/i;
5
3
  function validate(str) {
@@ -34,7 +32,6 @@ function parse(str) {
34
32
  return parsed;
35
33
  }
36
34
 
37
- exports.parse = parse;
38
- exports.validate = validate;
35
+ export { parse, validate };
39
36
  //# sourceMappingURL=out.js.map
40
37
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,8 +1,26 @@
1
1
  {
2
2
  "name": "@readme/data-urls",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "A utility for parsing and validating data URLs.",
5
5
  "license": "ISC",
6
+ "sideEffects": false,
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "require": "./dist/index.cjs",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "main": "dist/index.cjs",
16
+ "module": "dist/index.js",
17
+ "types": "dist/index.d.cts",
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
6
24
  "repository": {
7
25
  "type": "git",
8
26
  "url": "git@github.com:readmeio/data-urls.git"
@@ -11,21 +29,6 @@
11
29
  "url": "https://github.com/readmeio/data-urls/issues"
12
30
  },
13
31
  "homepage": "https://github.com/readmeio/data-urls#readme",
14
- "exports": {
15
- ".": {
16
- "types": "./dist/index.d.ts",
17
- "require": "./dist/index.js",
18
- "import": "./dist/index.mjs"
19
- },
20
- "./package.json": "./package.json"
21
- },
22
- "main": "dist/index.js",
23
- "module": "dist/index.mjs",
24
- "types": "dist/index.d.ts",
25
- "sideEffects": false,
26
- "engines": {
27
- "node": ">=14"
28
- },
29
32
  "scripts": {
30
33
  "build": "tsup",
31
34
  "lint": "eslint . --ext .js,.ts",
package/src/index.ts DELETED
@@ -1,71 +0,0 @@
1
- const DATA_URL_REGEX =
2
- /^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@/?%\s<>]*?)$/i;
3
-
4
- /**
5
- * Determine if a given data URL is valid or not.
6
- *
7
- * @see {@link https://developer.mozilla.org/en-US/docs/data_URIs}
8
- * @see {@link http://tools.ietf.org/html/rfc2397}
9
- * @see {@link http://tools.ietf.org/html/rfc2396#section2}
10
- */
11
- function validate(str: string) {
12
- return DATA_URL_REGEX.test((str || '').trim());
13
- }
14
-
15
- export interface DataURL {
16
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- [k: string]: any;
18
- base64: boolean;
19
- contentType?: string;
20
- data: string;
21
- mediaType?: string;
22
- name?: string;
23
- toBuffer: () => Buffer;
24
- }
25
-
26
- /**
27
- * Parse a given data URL into its individual parts.
28
- *
29
- */
30
- function parse(str: string) {
31
- if (!validate(str)) {
32
- return false;
33
- }
34
-
35
- const parts = str.trim().match(DATA_URL_REGEX);
36
- const parsed = {} as DataURL;
37
-
38
- if (parts[1]) {
39
- parsed.mediaType = parts[1].toLowerCase();
40
-
41
- const mediaTypeParts = parts[1].split(';').map(x => {
42
- // `name` attributes are for filenames so we shouldn't lowercase them as some filesystems are
43
- // case-sensitive.
44
- if (x.startsWith('name=')) {
45
- return x;
46
- }
47
-
48
- return x.toLowerCase();
49
- });
50
-
51
- parsed.contentType = mediaTypeParts[0];
52
-
53
- mediaTypeParts.slice(1).forEach(attribute => {
54
- const p = attribute.split('=');
55
- parsed[p[0]] = p[1];
56
- });
57
- }
58
-
59
- parsed.base64 = !!parts[parts.length - 2];
60
- parsed.data = parts[parts.length - 1] || '';
61
-
62
- parsed.toBuffer = () => {
63
- const encoding = parsed.base64 ? 'base64' : 'utf8';
64
-
65
- return Buffer.from(parsed.data, encoding);
66
- };
67
-
68
- return parsed;
69
- }
70
-
71
- export { parse, validate };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "baseUrl": "./src",
5
- "declaration": true,
6
- "esModuleInterop": true,
7
- "lib": ["DOM", "ES2020"],
8
- "moduleResolution": "node",
9
- "noImplicitAny": true,
10
- "outDir": "dist/",
11
- "target": "ES2020"
12
- },
13
- "include": ["./src/**/*"]
14
- }
package/tsup.config.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { Options } from 'tsup';
2
-
3
- // eslint-disable-next-line import/no-extraneous-dependencies
4
- import { defineConfig } from 'tsup';
5
-
6
- export default defineConfig((options: Options) => ({
7
- ...options,
8
-
9
- cjsInterop: true,
10
- clean: true,
11
- dts: true,
12
- entry: ['src/index.ts'],
13
- format: ['esm', 'cjs'],
14
- minify: false,
15
- shims: true,
16
- silent: !options.watch,
17
- sourcemap: true,
18
- splitting: true,
19
- treeshake: true,
20
- }));
File without changes
File without changes