@eik/common 5.1.2 → 5.1.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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [5.1.4](https://github.com/eik-lib/common/compare/v5.1.3...v5.1.4) (2025-06-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * refactor to use native JSON module for import ([#365](https://github.com/eik-lib/common/issues/365)) ([53fc469](https://github.com/eik-lib/common/commit/53fc46995d25a992345c5152e9ee4260acb3424a))
7
+
8
+ ## [5.1.3](https://github.com/eik-lib/common/compare/v5.1.2...v5.1.3) (2025-06-11)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * internal refactoring to reduce file size when bundled ([#363](https://github.com/eik-lib/common/issues/363)) ([5e06159](https://github.com/eik-lib/common/commit/5e061594f92ccb9c2c137faa35410aa192782207))
14
+
1
15
  ## [5.1.2](https://github.com/eik-lib/common/compare/v5.1.1...v5.1.2) (2025-06-07)
2
16
 
3
17
 
@@ -1,15 +1,6 @@
1
- import { readFileSync } from "node:fs";
2
- import { join, dirname } from "node:path";
1
+ import schema from "./schema.js";
3
2
  import * as validate from "./validate.js";
4
3
  import assert from "./assert.js";
5
4
  import ValidationError from "./validation-error.js";
6
- import { fileURLToPath } from "node:url";
7
-
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = dirname(__filename);
10
-
11
- const schema = JSON.parse(
12
- readFileSync(join(__dirname, "./eikjson.schema.json"), "utf8"),
13
- );
14
5
 
15
6
  export default { schema, validate, assert, ValidationError };
@@ -0,0 +1,3 @@
1
+ import schema from "./eikjson.schema.json" with { type: "json" };
2
+
3
+ export default schema;
@@ -1,17 +1,8 @@
1
- import { readFileSync } from "node:fs";
2
- import { join, dirname } from "node:path";
3
1
  import formats from "ajv-formats";
4
- import semver from "semver";
2
+ import validSemver from "semver/functions/valid.js";
5
3
  import npmPkg from "validate-npm-package-name";
6
4
  import Ajv from "ajv";
7
- import { fileURLToPath } from "node:url";
8
-
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = dirname(__filename);
11
-
12
- const eikJSONSchema = JSON.parse(
13
- readFileSync(join(__dirname, "./eikjson.schema.json"), "utf8"),
14
- );
5
+ import eikJSONSchema from "./schema.js";
15
6
 
16
7
  /**
17
8
  * @typedef {import('ajv').ErrorObject & { dataPath?: string }} ErrorObject
@@ -88,7 +79,7 @@ const createNameValidator = (jsonSchemaValidator) => (value) => {
88
79
  const createVersionValidator = (jsonSchemaValidator) => (value) => {
89
80
  const result = jsonSchemaValidator(value);
90
81
  if (!result.error) {
91
- const version = semver.valid(value);
82
+ const version = validSemver(value);
92
83
  /** @type {ErrorObject[]} */
93
84
  const errors = [];
94
85
  if (!version) {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Checks that a value is a valid alias value.
3
+ * @param {string} value
4
+ * @returns {string} the value in lowercase
5
+ * @throws {Error} if the value is not a valid alias value
6
+ */
7
+ export const alias = (value) => {
8
+ if (/^[0-9]+$/.test(value)) {
9
+ return value;
10
+ }
11
+ throw new Error(`Parameter "alias" is not valid - Value: ${value}`);
12
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * No-op, returning its value.
3
+ * @param {string} value
4
+ * @returns {string} the value
5
+ * @todo https://github.com/asset-pipe/core/issues/12
6
+ * @todo Can we remove this?
7
+ */
8
+ export const extra = (value) => value;
@@ -1,111 +1,8 @@
1
- import semver from "semver";
2
- import npmPkg from "validate-npm-package-name";
3
-
4
- const urlIsh = /^https?:\/\/[a-zA-Z0-9-_./]+(:[0-9]+)?/;
5
-
6
- /**
7
- * Check that a value looks like an HTTP origin.
8
- * @param {string} value
9
- * @returns {string} the value in lowercase
10
- * @throws {Error} if the parameter does not match a URL pattern
11
- */
12
- export const origin = (value) => {
13
- if (urlIsh.test(value)) {
14
- return value.toLowerCase();
15
- }
16
- throw new Error('Parameter "origin" is not valid');
17
- };
18
-
19
- /**
20
- * Checks that a value is a valid organisation name.
21
- * @param {string} value
22
- * @returns {string} the value in lowercase
23
- * @throws {Error} if the value is not a valid organisation name
24
- */
25
- export const org = (value) => {
26
- if (/^[a-zA-Z0-9_-]+$/.test(value)) {
27
- return value.toLowerCase();
28
- }
29
- throw new Error(`Parameter "org" is not valid - Value: ${value}`);
30
- };
31
-
32
- /**
33
- * Checks that a value is a valid package name.
34
- * @param {string} value
35
- * @returns {string} the value in lowercase
36
- * @throws {Error} if the value is not a valid package name
37
- */
38
- export const name = (value) => {
39
- const result = npmPkg(value);
40
- if (result.validForNewPackages || result.validForOldPackages) {
41
- return value.toLowerCase();
42
- }
43
- throw new Error(`Parameter "name" is not valid - Value: ${value}`);
44
- };
45
-
46
- /**
47
- * Checks that a value is a valid semver version.
48
- * @param {string} value
49
- * @returns {string} the value in lowercase
50
- * @throws {Error} if the value is not a valid semver version
51
- */
52
- export const version = (value) => {
53
- const result = semver.valid(value);
54
- if (result) {
55
- return result;
56
- }
57
- throw new Error(`Parameter "version" is not valid - Value: ${value}`);
58
- };
59
-
60
- /**
61
- * Checks that a value is a valid alias value.
62
- * @param {string} value
63
- * @returns {string} the value in lowercase
64
- * @throws {Error} if the value is not a valid alias value
65
- */
66
- export const alias = (value) => {
67
- if (/^[0-9]+$/.test(value)) {
68
- return value;
69
- }
70
- throw new Error(`Parameter "alias" is not valid - Value: ${value}`);
71
- };
72
-
73
- /**
74
- * Checks that a value is a valid Eik package type.
75
- * @param {string} value
76
- * @returns {string} the value in lowercase
77
- * @throws {Error} if the value is not a valid Eik package type
78
- */
79
- export const type = (value) => {
80
- if (
81
- value === "pkg" ||
82
- value === "map" ||
83
- value === "npm" ||
84
- value === "img"
85
- ) {
86
- return value;
87
- }
88
- throw new Error(`Parameter "type" is not valid - Value: ${value}`);
89
- };
90
-
91
- /**
92
- * No-op, returning its value.
93
- * @param {string} value
94
- * @returns {string} the value
95
- * @todo https://github.com/asset-pipe/core/issues/12
96
- * @todo Can we remove this?
97
- */
98
- export const extra = (value) => value;
99
-
100
- /**
101
- * Checks that a value is a valid semver type (major, minor, patch).
102
- * @param {string} value
103
- * @returns {string} the value
104
- * @throws {Error} if the value is not a valid semver type
105
- */
106
- export const semverType = (value) => {
107
- if (value === "major" || value === "minor" || value === "patch") {
108
- return value;
109
- }
110
- throw new Error(`Parameter "semverType" is not valid - Value: ${value}`);
111
- };
1
+ export { alias } from "./alias.js";
2
+ export { extra } from "./extra.js";
3
+ export { name } from "./name.js";
4
+ export { org } from "./org.js";
5
+ export { origin } from "./origin.js";
6
+ export { semverType } from "./semver-type.js";
7
+ export { type } from "./type.js";
8
+ export { version } from "./version.js";
@@ -0,0 +1,15 @@
1
+ import npmPkg from "validate-npm-package-name";
2
+
3
+ /**
4
+ * Checks that a value is a valid package name.
5
+ * @param {string} value
6
+ * @returns {string} the value in lowercase
7
+ * @throws {Error} if the value is not a valid package name
8
+ */
9
+ export const name = (value) => {
10
+ const result = npmPkg(value);
11
+ if (result.validForNewPackages || result.validForOldPackages) {
12
+ return value.toLowerCase();
13
+ }
14
+ throw new Error(`Parameter "name" is not valid - Value: ${value}`);
15
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Checks that a value is a valid organisation name.
3
+ * @param {string} value
4
+ * @returns {string} the value in lowercase
5
+ * @throws {Error} if the value is not a valid organisation name
6
+ */
7
+ export const org = (value) => {
8
+ if (/^[a-zA-Z0-9_-]+$/.test(value)) {
9
+ return value.toLowerCase();
10
+ }
11
+ throw new Error(`Parameter "org" is not valid - Value: ${value}`);
12
+ };
@@ -0,0 +1,14 @@
1
+ const urlIsh = /^https?:\/\/[a-zA-Z0-9-_./]+(:[0-9]+)?/;
2
+
3
+ /**
4
+ * Check that a value looks like an HTTP origin.
5
+ * @param {string} value
6
+ * @returns {string} the value in lowercase
7
+ * @throws {Error} if the parameter does not match a URL pattern
8
+ */
9
+ export const origin = (value) => {
10
+ if (urlIsh.test(value)) {
11
+ return value.toLowerCase();
12
+ }
13
+ throw new Error('Parameter "origin" is not valid');
14
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Checks that a value is a valid semver type (major, minor, patch).
3
+ * @param {string} value
4
+ * @returns {string} the value
5
+ * @throws {Error} if the value is not a valid semver type
6
+ */
7
+ export const semverType = (value) => {
8
+ if (value === "major" || value === "minor" || value === "patch") {
9
+ return value;
10
+ }
11
+ throw new Error(`Parameter "semverType" is not valid - Value: ${value}`);
12
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Checks that a value is a valid Eik package type.
3
+ * @param {string} value
4
+ * @returns {string} the value in lowercase
5
+ * @throws {Error} if the value is not a valid Eik package type
6
+ */
7
+ export const type = (value) => {
8
+ if (
9
+ value === "pkg" ||
10
+ value === "map" ||
11
+ value === "npm" ||
12
+ value === "img"
13
+ ) {
14
+ return value;
15
+ }
16
+ throw new Error(`Parameter "type" is not valid - Value: ${value}`);
17
+ };
@@ -0,0 +1,15 @@
1
+ import valid from "semver/functions/valid.js";
2
+
3
+ /**
4
+ * Checks that a value is a valid semver version.
5
+ * @param {string} value
6
+ * @returns {string} the value in lowercase
7
+ * @throws {Error} if the value is not a valid semver version
8
+ */
9
+ export const version = (value) => {
10
+ const result = valid(value);
11
+ if (result) {
12
+ return result;
13
+ }
14
+ throw new Error(`Parameter "version" is not valid - Value: ${value}`);
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eik/common",
3
- "version": "5.1.2",
3
+ "version": "5.1.4",
4
4
  "description": "Common utilities for Eik modules",
5
5
  "main": "lib/index.js",
6
6
  "types": "types/index.d.ts",
@@ -5,7 +5,7 @@ declare namespace _default {
5
5
  export { ValidationError };
6
6
  }
7
7
  export default _default;
8
- declare const schema: any;
8
+ import schema from "./schema.js";
9
9
  import * as validate from "./validate.js";
10
10
  import assert from "./assert.js";
11
11
  import ValidationError from "./validation-error.js";
@@ -0,0 +1,2 @@
1
+ export default schema;
2
+ import schema from "./eikjson.schema.json" with { type: "json" };
@@ -0,0 +1 @@
1
+ export function alias(value: string): string;
@@ -0,0 +1 @@
1
+ export function extra(value: string): string;
@@ -1,8 +1,8 @@
1
- export function origin(value: string): string;
2
- export function org(value: string): string;
3
- export function name(value: string): string;
4
- export function version(value: string): string;
5
- export function alias(value: string): string;
6
- export function type(value: string): string;
7
- export function extra(value: string): string;
8
- export function semverType(value: string): string;
1
+ export { alias } from "./alias.js";
2
+ export { extra } from "./extra.js";
3
+ export { name } from "./name.js";
4
+ export { org } from "./org.js";
5
+ export { origin } from "./origin.js";
6
+ export { semverType } from "./semver-type.js";
7
+ export { type } from "./type.js";
8
+ export { version } from "./version.js";
@@ -0,0 +1 @@
1
+ export function name(value: string): string;
@@ -0,0 +1 @@
1
+ export function org(value: string): string;
@@ -0,0 +1 @@
1
+ export function origin(value: string): string;
@@ -0,0 +1 @@
1
+ export function semverType(value: string): string;
@@ -0,0 +1 @@
1
+ export function type(value: string): string;
@@ -0,0 +1 @@
1
+ export function version(value: string): string;