@khanacademy/perseus-utils 0.0.2 → 1.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/dist/index.js CHANGED
@@ -1,47 +1,27 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- /**
6
- * Adds the given perseus library version information to the __perseus_debug__
7
- * object and ensures that the object is attached to `globalThis` (`window` in
8
- * browser environments).
9
- *
10
- * This allows each library to provide runtime version information to assist in
11
- * debugging in production environments.
12
- */
13
1
  const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
14
- // If the library version is the default value, then we don't want to
15
- // prefix it with a "v" to indicate that it is a version number.
16
2
  let prefix = "v";
17
3
  if (libraryVersion === "__lib_version__") {
18
4
  prefix = "";
19
5
  }
20
6
  const formattedVersion = `${prefix}${libraryVersion}`;
21
7
  if (typeof globalThis !== "undefined") {
22
- globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};
8
+ var _globalThis$__perseus;
9
+ globalThis.__perseus_debug__ = (_globalThis$__perseus = globalThis.__perseus_debug__) != null ? _globalThis$__perseus : {};
23
10
  const existingVersionEntry = globalThis.__perseus_debug__[libraryName];
24
11
  if (existingVersionEntry) {
25
- // If we already have an entry and it doesn't match the registered
26
- // version, we morph the entry into an array and log a warning.
27
12
  if (existingVersionEntry !== formattedVersion) {
28
- // Existing entry might be an array already (oops, at least 2
29
- // versions of the library already loaded!).
30
13
  const allVersions = Array.isArray(existingVersionEntry) ? existingVersionEntry : [existingVersionEntry];
31
14
  allVersions.push(formattedVersion);
32
15
  globalThis.__perseus_debug__[libraryName] = allVersions;
33
-
34
- // eslint-disable-next-line no-console
35
16
  console.warn(`Multiple versions of ${libraryName} loaded on this page: ${allVersions.sort().join(", ")}`);
36
17
  }
37
18
  } else {
38
19
  globalThis.__perseus_debug__[libraryName] = formattedVersion;
39
20
  }
40
21
  } else {
41
- // eslint-disable-next-line no-console
42
22
  console.warn(`globalThis not found found (${formattedVersion})`);
43
23
  }
44
24
  };
45
25
 
46
- exports.addLibraryVersionToPerseusDebug = addLibraryVersionToPerseusDebug;
26
+ export { addLibraryVersionToPerseusDebug };
47
27
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/add-library-version-to-perseus-debug.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","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+BT,4BAAAA,EAAAA,gBAAgB,GAAG,CAAC,CAAA;AACpE,GAAA;AACJ;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/add-library-version-to-perseus-debug.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","_globalThis$__perseus","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","warn","sort","join"],"mappings":"MAQaA,+BAA+B,GAAGA,CAC3CC,WAAmB,EACnBC,cAAsB,KACrB;EAGD,IAAIC,MAAM,GAAG,GAAG;EAChB,IAAID,cAAc,KAAK,iBAAiB,EAAE;AACtCC,IAAAA,MAAM,GAAG,EAAE;AACf;AACA,EAAA,MAAMC,gBAAgB,GAAG,CAAA,EAAGD,MAAM,CAAA,EAAGD,cAAc,CAAE,CAAA;AAErD,EAAA,IAAI,OAAOG,UAAU,KAAK,WAAW,EAAE;AAAA,IAAA,IAAAC,qBAAA;AACnCD,IAAAA,UAAU,CAACE,iBAAiB,GAAAD,CAAAA,qBAAA,GAAGD,UAAU,CAACE,iBAAiB,KAAAD,IAAAA,GAAAA,qBAAA,GAAI,EAAE;AAEjE,IAAA,MAAME,oBAAoB,GAAGH,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC;AACtE,IAAA,IAAIO,oBAAoB,EAAE;MAGtB,IAAIA,oBAAoB,KAAKJ,gBAAgB,EAAE;AAG3C,QAAA,MAAMK,WAAW,GAAGC,KAAK,CAACC,OAAO,CAACH,oBAAoB,CAAC,GACjDA,oBAAoB,GACpB,CAACA,oBAAoB,CAAC;AAC5BC,QAAAA,WAAW,CAACG,IAAI,CAACR,gBAAgB,CAAC;AAElCC,QAAAA,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,GAAGQ,WAAW;AAGvDI,QAAAA,OAAO,CAACC,IAAI,CACR,CAAwBb,qBAAAA,EAAAA,WAAW,yBAAyBQ,WAAW,CAClEM,IAAI,EAAE,CACNC,IAAI,CAAC,IAAI,CAAC,EACnB,CAAC;AACL;AACJ,KAAC,MAAM;AACHX,MAAAA,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,GAAGG,gBAAgB;AAChE;AACJ,GAAC,MAAM;AAEHS,IAAAA,OAAO,CAACC,IAAI,CAAC,CAA+BV,4BAAAA,EAAAA,gBAAgB,GAAG,CAAC;AACpE;AACJ;;;;"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Miscellaneous utilities used by the Khan Academy Perseus ecosystem",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "0.0.2",
6
+ "version": "1.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -15,16 +15,22 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/Khan/perseus/issues"
17
17
  },
18
- "module": "dist/es/index.js",
19
- "main": "dist/index.js",
20
- "source": "src/index.ts",
21
- "types": "dist/index.d.ts",
18
+ "engines": {
19
+ "node": ">=18"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "source": "./src/index.ts",
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
27
+ },
22
28
  "files": [
23
29
  "dist"
24
30
  ],
25
31
  "dependencies": {},
26
32
  "devDependencies": {
27
- "perseus-build-settings": "0.5.1"
33
+ "perseus-build-settings": "0.6.0"
28
34
  },
29
35
  "scripts": {}
30
36
  }
package/dist/es/index.js DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * Adds the given perseus library version information to the __perseus_debug__
3
- * object and ensures that the object is attached to `globalThis` (`window` in
4
- * browser environments).
5
- *
6
- * This allows each library to provide runtime version information to assist in
7
- * debugging in production environments.
8
- */
9
- const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
10
- // If the library version is the default value, then we don't want to
11
- // prefix it with a "v" to indicate that it is a version number.
12
- let prefix = "v";
13
- if (libraryVersion === "__lib_version__") {
14
- prefix = "";
15
- }
16
- const formattedVersion = `${prefix}${libraryVersion}`;
17
- if (typeof globalThis !== "undefined") {
18
- var _globalThis$__perseus;
19
- globalThis.__perseus_debug__ = (_globalThis$__perseus = globalThis.__perseus_debug__) != null ? _globalThis$__perseus : {};
20
- const existingVersionEntry = globalThis.__perseus_debug__[libraryName];
21
- if (existingVersionEntry) {
22
- // If we already have an entry and it doesn't match the registered
23
- // version, we morph the entry into an array and log a warning.
24
- if (existingVersionEntry !== formattedVersion) {
25
- // Existing entry might be an array already (oops, at least 2
26
- // versions of the library already loaded!).
27
- const allVersions = Array.isArray(existingVersionEntry) ? existingVersionEntry : [existingVersionEntry];
28
- allVersions.push(formattedVersion);
29
- globalThis.__perseus_debug__[libraryName] = allVersions;
30
-
31
- // eslint-disable-next-line no-console
32
- console.warn(`Multiple versions of ${libraryName} loaded on this page: ${allVersions.sort().join(", ")}`);
33
- }
34
- } else {
35
- globalThis.__perseus_debug__[libraryName] = formattedVersion;
36
- }
37
- } else {
38
- // eslint-disable-next-line no-console
39
- console.warn(`globalThis not found found (${formattedVersion})`);
40
- }
41
- };
42
-
43
- export { addLibraryVersionToPerseusDebug };
44
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/add-library-version-to-perseus-debug.ts"],"sourcesContent":["/**\n * Adds the given perseus library version information to the __perseus_debug__\n * object and ensures that the object is attached to `globalThis` (`window` in\n * browser environments).\n *\n * This allows each library to provide runtime version information to assist in\n * debugging in production environments.\n */\nexport const addLibraryVersionToPerseusDebug = (\n libraryName: string,\n libraryVersion: string,\n) => {\n // If the library version is the default value, then we don't want to\n // prefix it with a \"v\" to indicate that it is a version number.\n let prefix = \"v\";\n if (libraryVersion === \"__lib_version__\") {\n prefix = \"\";\n }\n const formattedVersion = `${prefix}${libraryVersion}`;\n\n if (typeof globalThis !== \"undefined\") {\n globalThis.__perseus_debug__ = globalThis.__perseus_debug__ ?? {};\n\n const existingVersionEntry = globalThis.__perseus_debug__[libraryName];\n if (existingVersionEntry) {\n // If we already have an entry and it doesn't match the registered\n // version, we morph the entry into an array and log a warning.\n if (existingVersionEntry !== formattedVersion) {\n // Existing entry might be an array already (oops, at least 2\n // versions of the library already loaded!).\n const allVersions = Array.isArray(existingVersionEntry)\n ? existingVersionEntry\n : [existingVersionEntry];\n allVersions.push(formattedVersion);\n\n globalThis.__perseus_debug__[libraryName] = allVersions;\n\n // eslint-disable-next-line no-console\n console.warn(\n `Multiple versions of ${libraryName} loaded on this page: ${allVersions\n .sort()\n .join(\", \")}`,\n );\n }\n } else {\n globalThis.__perseus_debug__[libraryName] = formattedVersion;\n }\n } else {\n // eslint-disable-next-line no-console\n console.warn(`globalThis not found found (${formattedVersion})`);\n }\n};\n"],"names":["addLibraryVersionToPerseusDebug","libraryName","libraryVersion","prefix","formattedVersion","globalThis","_globalThis$__perseus","__perseus_debug__","existingVersionEntry","allVersions","Array","isArray","push","console","warn","sort","join"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACaA,+BAA+B,GAAGA,CAC3CC,WAAmB,EACnBC,cAAsB,KACrB;AACD;AACA;EACA,IAAIC,MAAM,GAAG,GAAG,CAAA;EAChB,IAAID,cAAc,KAAK,iBAAiB,EAAE;AACtCC,IAAAA,MAAM,GAAG,EAAE,CAAA;AACf,GAAA;AACA,EAAA,MAAMC,gBAAgB,GAAG,CAAA,EAAGD,MAAM,CAAA,EAAGD,cAAc,CAAE,CAAA,CAAA;AAErD,EAAA,IAAI,OAAOG,UAAU,KAAK,WAAW,EAAE;AAAA,IAAA,IAAAC,qBAAA,CAAA;AACnCD,IAAAA,UAAU,CAACE,iBAAiB,GAAAD,CAAAA,qBAAA,GAAGD,UAAU,CAACE,iBAAiB,KAAAD,IAAAA,GAAAA,qBAAA,GAAI,EAAE,CAAA;AAEjE,IAAA,MAAME,oBAAoB,GAAGH,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,CAAA;AACtE,IAAA,IAAIO,oBAAoB,EAAE;AACtB;AACA;MACA,IAAIA,oBAAoB,KAAKJ,gBAAgB,EAAE;AAC3C;AACA;AACA,QAAA,MAAMK,WAAW,GAAGC,KAAK,CAACC,OAAO,CAACH,oBAAoB,CAAC,GACjDA,oBAAoB,GACpB,CAACA,oBAAoB,CAAC,CAAA;AAC5BC,QAAAA,WAAW,CAACG,IAAI,CAACR,gBAAgB,CAAC,CAAA;AAElCC,QAAAA,UAAU,CAACE,iBAAiB,CAACN,WAAW,CAAC,GAAGQ,WAAW,CAAA;;AAEvD;AACAI,QAAAA,OAAO,CAACC,IAAI,CACR,CAAwBb,qBAAAA,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