@spscommerce/utils 5.0.0-rc1 → 5.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.
Files changed (76) hide show
  1. package/lib/array/flatten.d.ts +1 -1
  2. package/lib/array/flatten.spec.d.ts +1 -1
  3. package/lib/array/index.d.ts +3 -3
  4. package/lib/array/is-subset.d.ts +4 -4
  5. package/lib/array/is-subset.spec.d.ts +1 -1
  6. package/lib/array/range.d.ts +5 -5
  7. package/lib/array/range.spec.d.ts +1 -1
  8. package/lib/classes/custom-event.d.ts +4 -4
  9. package/lib/classes/index.d.ts +1 -1
  10. package/lib/data/doctypes.d.ts +4 -6
  11. package/lib/data/index.d.ts +1 -1
  12. package/lib/decorators/cast-to-number.d.ts +5 -4
  13. package/lib/decorators/debounced.broken_spec.d.ts +0 -0
  14. package/lib/decorators/debounced.d.ts +11 -11
  15. package/lib/decorators/index.d.ts +5 -5
  16. package/lib/decorators/locked-to-animation-frames.d.ts +4 -11
  17. package/lib/decorators/locked-to-animation-frames.spec.d.ts +0 -1
  18. package/lib/decorators/simple-metadata-decorator-applicator.d.ts +11 -12
  19. package/lib/decorators/tick-delay.d.ts +6 -6
  20. package/lib/function/debounce.d.ts +9 -9
  21. package/lib/function/debounce.spec.d.ts +1 -1
  22. package/lib/function/debounced-function.interface.d.ts +10 -10
  23. package/lib/function/delayed-function.interface.d.ts +10 -9
  24. package/lib/function/index.d.ts +6 -6
  25. package/lib/function/lock-to-animation-frames.d.ts +7 -7
  26. package/lib/function/lock-to-animation-frames.spec.d.ts +0 -1
  27. package/lib/function/on-next-tick.d.ts +8 -8
  28. package/lib/function/on-next-tick.spec.d.ts +1 -1
  29. package/lib/function/op.d.ts +32 -31
  30. package/lib/function/op.spec.d.ts +1 -1
  31. package/lib/index.cjs.js +1 -1400
  32. package/lib/index.d.ts +9 -9
  33. package/lib/index.es.js +1024 -0
  34. package/lib/number/constrain.d.ts +7 -6
  35. package/lib/number/decimal-round.d.ts +7 -7
  36. package/lib/number/decimal-round.spec.d.ts +1 -1
  37. package/lib/number/index.d.ts +3 -3
  38. package/lib/number/to-file-size-string.d.ts +5 -4
  39. package/lib/object/copy-property.d.ts +6 -6
  40. package/lib/object/copy-property.spec.d.ts +1 -1
  41. package/lib/object/crumble-path.d.ts +6 -5
  42. package/lib/object/crumble-path.spec.d.ts +1 -1
  43. package/lib/object/deep-freeze.d.ts +1 -1
  44. package/lib/object/deep-freeze.spec.d.ts +1 -1
  45. package/lib/object/diff.d.ts +12 -12
  46. package/lib/object/diff.spec.d.ts +1 -1
  47. package/lib/object/for-each-entry-deep.d.ts +4 -4
  48. package/lib/object/for-each-entry-deep.spec.d.ts +1 -1
  49. package/lib/object/for-each-nested-object.d.ts +4 -4
  50. package/lib/object/for-each-nested-object.spec.d.ts +1 -1
  51. package/lib/object/get-path.d.ts +5 -4
  52. package/lib/object/get-path.spec.d.ts +1 -1
  53. package/lib/object/index.d.ts +13 -13
  54. package/lib/object/merge-deep.d.ts +4 -4
  55. package/lib/object/merge-deep.spec.d.ts +1 -1
  56. package/lib/object/merge-properties-deep.d.ts +4 -4
  57. package/lib/object/merge-properties-deep.spec.d.ts +1 -1
  58. package/lib/object/omit.d.ts +1 -1
  59. package/lib/object/omit.spec.d.ts +1 -1
  60. package/lib/object/set-path.d.ts +2 -2
  61. package/lib/object/set-path.spec.d.ts +1 -1
  62. package/lib/object/traverse-path.d.ts +2 -2
  63. package/lib/object/values.d.ts +2 -2
  64. package/lib/object/values.spec.d.ts +1 -1
  65. package/lib/string/code.template-tag.d.ts +2 -2
  66. package/lib/string/index.d.ts +3 -3
  67. package/lib/string/parse-file-size.d.ts +5 -4
  68. package/lib/string/template.d.ts +15 -13
  69. package/lib/string/template.spec.d.ts +1 -1
  70. package/lib/typings.d.ts +1 -1
  71. package/package.json +15 -16
  72. package/tsconfig.json +1 -1
  73. package/vite.config.js +20 -0
  74. package/lib/decorators/debounced.spec.d.ts +0 -1
  75. package/lib/index.esm.js +0 -1336
  76. package/rollup.config.js +0 -24
@@ -1,6 +1,7 @@
1
- /** Constrains a number to the given range. If the number is below the
2
- * low end of the range, the low end will be returned. If the number is
3
- * above the top end of the range, the top end will be returned. Otherwise
4
- * the number itself will be returned.
5
- */
6
- export declare function constrain(n: number, range: [number, number]): number;
1
+ /**
2
+ * Constrains a number to the given range. If the number is below the
3
+ * low end of the range, the low end will be returned. If the number is
4
+ * above the top end of the range, the top end will be returned. Otherwise
5
+ * the number itself will be returned.
6
+ */
7
+ export declare function constrain(n: number, range: [number, number]): number;
@@ -1,7 +1,7 @@
1
- /**
2
- * Progressively rounds `num` to `decimalPlaces` places. This differs from other
3
- * rounding methods out there such as lodash's, which are not progressive. For example,
4
- * `(0.149).toFixed(1)` and lodash `_.round(0.149, 1)` both return `0.1`, but this
5
- * function rounds `0.149` to `0.15` and then `0.15` to `0.2` and returns `0.2`.
6
- */
7
- export declare function decimalRound(num: number, decimalPlaces?: number): number;
1
+ /**
2
+ * Progressively rounds `num` to `decimalPlaces` places. This differs from other
3
+ * rounding methods out there such as lodash's, which are not progressive. For example,
4
+ * `(0.149).toFixed(1)` and lodash `_.round(0.149, 1)` both return `0.1`, but this
5
+ * function rounds `0.149` to `0.15` and then `0.15` to `0.2` and returns `0.2`.
6
+ */
7
+ export declare function decimalRound(num: number, decimalPlaces?: number): number;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,3 +1,3 @@
1
- export * from './constrain';
2
- export * from './decimal-round';
3
- export * from './to-file-size-string';
1
+ export * from "./constrain";
2
+ export * from "./decimal-round";
3
+ export * from "./to-file-size-string";
@@ -1,4 +1,5 @@
1
- /** Converts a file size in bytes to a human-friendly string. For example,
2
- * `toFileSizeString(2048)` will return `"2.00KB"`.
3
- */
4
- export declare function toFileSizeString(n: number, precision?: number): string;
1
+ /**
2
+ * Converts a file size in bytes to a human-friendly string. For example,
3
+ * `toFileSizeString(2048)` will return `"2.00KB"`.
4
+ */
5
+ export declare function toFileSizeString(n: number, precision?: number): string;
@@ -1,6 +1,6 @@
1
- /**
2
- * Copy a property from one object to another using its property descriptor.
3
- * In other words, if it's a getter/setter on `sourceObject` it'll be the same
4
- * getter/setter on `destObject`. If it's just a value it'll be just a value.
5
- */
6
- export declare function copyProperty(propName: PropertyKey, sourceObject: any, destObject: any): void;
1
+ /**
2
+ * Copy a property from one object to another using its property descriptor.
3
+ * In other words, if it's a getter/setter on `sourceObject` it'll be the same
4
+ * getter/setter on `destObject`. If it's just a value it'll be just a value.
5
+ */
6
+ export declare function copyProperty(propName: PropertyKey, sourceObject: any, destObject: any): void;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,5 +1,6 @@
1
- /** Converts a path to crumbs.
2
- * For example:
3
- * "a.b[0].c" -> ["a", "b", "0", "c"]
4
- */
5
- export declare function crumblePath(path: string | PropertyKey | PropertyKey[]): PropertyKey[];
1
+ /**
2
+ * Converts a path to crumbs.
3
+ * For example:
4
+ * "a.b[0].c" -> ["a", "b", "0", "c"]
5
+ */
6
+ export declare function crumblePath(path: string | PropertyKey | PropertyKey[]): PropertyKey[];
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- export declare function deepFreeze(obj: any): void;
1
+ export declare function deepFreeze(obj: any): void;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,12 +1,12 @@
1
- export declare enum DiffChange {
2
- ADDITION = 0,
3
- DELETION = 1,
4
- ALTERATION = 2
5
- }
6
- export interface DiffEntry {
7
- type: DiffChange;
8
- key: PropertyKey;
9
- parentPath: Array<PropertyKey>;
10
- objects: [object, object];
11
- }
12
- export declare function diff(o1: object, o2: object, parentPath?: Array<PropertyKey>): Array<DiffEntry>;
1
+ export declare enum DiffChange {
2
+ ADDITION = 0,
3
+ DELETION = 1,
4
+ ALTERATION = 2
5
+ }
6
+ export interface DiffEntry {
7
+ type: DiffChange;
8
+ key: PropertyKey;
9
+ parentPath: PropertyKey[];
10
+ objects: [Record<PropertyKey, unknown>, Record<PropertyKey, unknown>];
11
+ }
12
+ export declare function diff(o1: Record<PropertyKey, unknown>, o2: Record<PropertyKey, unknown>, parentPath?: PropertyKey[]): DiffEntry[];
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,4 +1,4 @@
1
- /**
2
- * Recursively navigate a nested object & call `fn` for each key/value pair
3
- */
4
- export declare function forEachEntryDeep(object: any, fn: (key: string, value: any, object: any) => any): any;
1
+ /**
2
+ * Recursively navigate a nested object & call `fn` for each key/value pair
3
+ */
4
+ export declare function forEachEntryDeep(object: any, fn: (key: string, value: any, object: any) => any): any;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,4 +1,4 @@
1
- /**
2
- * Recursively navigate a nested object & call `fn` for each subobject
3
- */
4
- export declare function forEachNestedObject(object: any, fn: (path: PropertyKey[], object: any) => any, path?: PropertyKey[]): any;
1
+ /**
2
+ * Recursively navigate a nested object & call `fn` for each subobject
3
+ */
4
+ export declare function forEachNestedObject(object: any, fn: (path: PropertyKey[], object: any) => any, path?: PropertyKey[]): any;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,4 +1,5 @@
1
- /** Get the value at `path` starting from `object`.
2
- * Allows optional chaining, e.g. `get(obj, 'a.b?.c')`
3
- */
4
- export declare function getPath<T>(object: any, path: string | PropertyKey | PropertyKey[], defaultValue?: T, allOptional?: boolean): T;
1
+ /**
2
+ * Get the value at `path` starting from `object`.
3
+ * Allows optional chaining, e.g. `get(obj, 'a.b?.c')`
4
+ */
5
+ export declare function getPath<T>(object: any, path: string | PropertyKey | PropertyKey[], defaultValue?: T, allOptional?: boolean): T;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,13 +1,13 @@
1
- export * from './crumble-path';
2
- export * from './copy-property';
3
- export * from './deep-freeze';
4
- export * from './diff';
5
- export * from './for-each-entry-deep';
6
- export * from './for-each-nested-object';
7
- export * from './get-path';
8
- export * from './omit';
9
- export * from './set-path';
10
- export * from './traverse-path';
11
- export * from './merge-deep';
12
- export * from './merge-properties-deep';
13
- export * from './values';
1
+ export * from "./crumble-path";
2
+ export * from "./copy-property";
3
+ export * from "./deep-freeze";
4
+ export * from "./diff";
5
+ export * from "./for-each-entry-deep";
6
+ export * from "./for-each-nested-object";
7
+ export * from "./get-path";
8
+ export * from "./omit";
9
+ export * from "./set-path";
10
+ export * from "./traverse-path";
11
+ export * from "./merge-deep";
12
+ export * from "./merge-properties-deep";
13
+ export * from "./values";
@@ -1,4 +1,4 @@
1
- /**
2
- * Recursive merge of any number of objects
3
- */
4
- export declare function mergeDeep(...objectsToMerge: any[]): any;
1
+ /**
2
+ * Recursive merge of any number of objects
3
+ */
4
+ export declare function mergeDeep(...objectsToMerge: any[]): any;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,4 +1,4 @@
1
- /**
2
- * Recursive merge of any number of objects using `copyProperty()` rather than assignment
3
- */
4
- export declare function mergePropertiesDeep(...objectsToMerge: any[]): any;
1
+ /**
2
+ * Recursive merge of any number of objects using `copyProperty()` rather than assignment
3
+ */
4
+ export declare function mergePropertiesDeep(...objectsToMerge: any[]): any;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1 +1 @@
1
- export declare function omit(obj: any, ...keys: Array<PropertyKey>): {};
1
+ export declare function omit(obj: any, ...keys: PropertyKey[]): {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,2 +1,2 @@
1
- /** Set the value at `path` on `object`. */
2
- export declare function setPath(object: any, path: PropertyKey | PropertyKey[], newValue: any): void;
1
+ /** Set the value at `path` on `object`. */
2
+ export declare function setPath(object: any, path: PropertyKey | PropertyKey[], newValue: any): void;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,2 +1,2 @@
1
- /** Generator for iterating down a path on an object. */
2
- export declare function traversePath(object: any, path: any): Generator<any, void, unknown>;
1
+ /** Generator for iterating down a path on an object. */
2
+ export declare function traversePath(object: any, path: any): Generator<any, void, unknown>;
@@ -1,2 +1,2 @@
1
- /** Returns the values of an object. */
2
- export declare function values(object: any): any[];
1
+ /** Returns the values of an object. */
2
+ export declare function values(object: any): any[];
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,2 +1,2 @@
1
- /** Template tag function for making strings containing code blocks easier to deal with. */
2
- export declare function code(strings: TemplateStringsArray, ...interpolations: any[]): string;
1
+ /** Template tag function for making strings containing code blocks easier to deal with. */
2
+ export declare function code(strings: TemplateStringsArray, ...interpolations: unknown[]): string;
@@ -1,3 +1,3 @@
1
- export * from './code.template-tag';
2
- export * from './parse-file-size';
3
- export * from './template';
1
+ export * from "./code.template-tag";
2
+ export * from "./parse-file-size";
3
+ export * from "./template";
@@ -1,4 +1,5 @@
1
- /** Parses a string as a file size and returns the size in bytes. For example,
2
- * `parseFileSize("2KB")` will return `2048`.
3
- */
4
- export declare function parseFileSize(fileSize: string): number;
1
+ /**
2
+ * Parses a string as a file size and returns the size in bytes. For example,
3
+ * `parseFileSize("2KB")` will return `2048`.
4
+ */
5
+ export declare function parseFileSize(fileSize: string): number;
@@ -1,13 +1,15 @@
1
- /**
2
- * Every string templating thing out there whether lodash, doT, handlebars, etc
3
- * is extremely complicated to cover a variety of use cases. This just has two
4
- * very simple features and great caution should be exercised in making it any more
5
- * complex than that. A value can be interpolated like so:
6
- * `<%= foo.bar %>`
7
- * And a basic "if" conditional can be used like so:
8
- * `<%? a?.b?.c %>This part will only appear if a.b.c is truthy!</%>`
9
- * You can put interpolations inside a conditional, as you'd expect. That's it.
10
- */
11
- export declare function template(string: string): (data: any) => string;
12
- export declare function isTemplate(x: any): x is string;
13
- export declare function isTemplateFn(x: any): x is Function;
1
+ declare type TemplateFn = (data: any) => string;
2
+ /**
3
+ * Every string templating thing out there whether lodash, doT, handlebars, etc
4
+ * is extremely complicated to cover a variety of use cases. This just has two
5
+ * very simple features and great caution should be exercised in making it any more
6
+ * complex than that. A value can be interpolated like so:
7
+ * `<%= foo.bar %>`
8
+ * And a basic "if" conditional can be used like so:
9
+ * `<%? a?.b?.c %>This part will only appear if a.b.c is truthy!</%>`
10
+ * You can put interpolations inside a conditional, as you'd expect. That's it.
11
+ */
12
+ export declare function template(string: string): TemplateFn;
13
+ export declare function isTemplate(x: any): x is string;
14
+ export declare function isTemplateFn(x: any): x is TemplateFn;
15
+ export {};
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/lib/typings.d.ts CHANGED
@@ -1 +1 @@
1
- export declare type Eventually<T> = T | Promise<T>;
1
+ export declare type Eventually<T> = T | Promise<T>;
package/package.json CHANGED
@@ -1,34 +1,33 @@
1
1
  {
2
2
  "name": "@spscommerce/utils",
3
3
  "description": "Utility items for frontend projects.",
4
- "version": "5.0.0-rc1",
4
+ "version": "5.0.0",
5
5
  "author": "SPS Commerce",
6
6
  "license": "UNLICENSED",
7
7
  "repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/utils",
8
8
  "homepage": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/utils#readme",
9
- "scripts": {
10
- "build": "yarn run build:rollup",
11
- "build:rollup": "npx rollup -c rollup.config.js",
12
- "clean": "git clean -fdX",
13
- "pub": "node ../../../scripts/publish-package.js"
14
- },
15
9
  "main": "./lib/index.cjs.js",
16
- "module": "./lib/index.esm.js",
10
+ "module": "./lib/index.es.js",
17
11
  "types": "./lib/index.d.ts",
18
12
  "publishConfig": {
19
13
  "access": "public"
20
14
  },
21
- "peerDependencies": {
15
+ "devDependencies": {
16
+ "raf-stub": "^2.0.2"
17
+ },
18
+ "dependencies": {
22
19
  "lodash.isempty": "^4.4.0",
23
20
  "lodash.isnil": "^4.0.0",
24
21
  "lodash.isplainobject": "^4.0.6",
25
22
  "lodash.padstart": "^4.6.1"
26
23
  },
27
- "devDependencies": {
28
- "lodash.isempty": "^4.4.0",
29
- "lodash.isnil": "^4.0.0",
30
- "lodash.isplainobject": "^4.0.6",
31
- "lodash.padstart": "^4.6.1",
32
- "raf-stub": "^2.0.2"
33
- }
24
+ "scripts": {
25
+ "build": "pnpm run build:js && pnpm run build:types",
26
+ "build:js": "vite build",
27
+ "build:types": "tsc --emitDeclarationOnly --declaration --declarationDir lib",
28
+ "watch": "vite build --watch",
29
+ "clean": "git clean -fdX",
30
+ "pub": "pnpm pack && node ../../scripts/publish-package.js"
31
+ },
32
+ "readme": "[//]: # \"START_AUTOGENERATED\"\n\n## [@spscommerce/utils](https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/utils#readme)\n\n![release: 1.1.0](https://img.shields.io/badge/release-1.1.0-blue.svg?style=flat-square)\n![build: passing](https://img.shields.io/badge/build-passing-green.svg?style=flat-square)\n![tests: failing](https://img.shields.io/badge/tests-failing-red.svg?style=flat-square)\n\nUtility items for frontend projects. \n \n ### Installation \n \n ```shell\nnpm install --save @spscommerce/utils\n```\n\n#### Peer Dependencies\n\n<div class=\"row\">\n <div class=\"col-5\"> \n <table class=\"sps-table\">\n <thead class=\"sps-table__head\">\n <tr class=\"sps-table__row\">\n <th class=\"sps-table__header\">\n <span class=\"sps-table__header-cell-body\"> \n Package\n </span>\n </th>\n <th class=\"sps-table__header text-right\">\n <span class=\"sps-table__header-cell-body\"> \n Version\n </span>\n </th>\n </tr>\n </thead>\n <tbody class=\"sps-table__body\">\n <tr class=\"sps-table__row\"><td class=\"sps-table__cell\"><a href=\"https://lodash.com/\">lodash.isempty</a></td><td class=\"sps-table__cell text-right\">^4.4.0</td></tr>\n<tr class=\"sps-table__row\"><td class=\"sps-table__cell\"><a href=\"https://lodash.com/\">lodash.isnil</a></td><td class=\"sps-table__cell text-right\">^4.0.0</td></tr>\n<tr class=\"sps-table__row\"><td class=\"sps-table__cell\"><a href=\"https://lodash.com/\">lodash.isplainobject</a></td><td class=\"sps-table__cell text-right\">^4.0.6</td></tr>\n<tr class=\"sps-table__row\"><td class=\"sps-table__cell\"><a href=\"https://lodash.com/\">lodash.padstart</a></td><td class=\"sps-table__cell text-right\">^4.6.1</td></tr>\n </tbody>\n </table>\n </div>\n <div class=\"col-7\">\n &nbsp;\n </div>\n</div>\n\n[//]: # \"END_AUTOGENERATED\"\n"
34
33
  }
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "../../../tsconfig.json",
2
+ "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "baseUrl": "tsconfig",
5
5
  "rootDir": "src/",
package/vite.config.js ADDED
@@ -0,0 +1,20 @@
1
+ import path from 'path';
2
+
3
+ import { defineConfig } from 'vite';
4
+
5
+ import pkg from './package.json';
6
+
7
+ export default defineConfig({
8
+ build: {
9
+ lib: {
10
+ entry: path.resolve(__dirname, 'src/index.ts'),
11
+ formats: ['es', 'cjs'],
12
+ fileName: (format) => `index.${format}.js`,
13
+ },
14
+ outDir: path.resolve(__dirname, './lib'),
15
+ emptyOutDir: false,
16
+ rollupOptions: {
17
+ external: pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
18
+ },
19
+ },
20
+ });
@@ -1 +0,0 @@
1
- export {};