Skip to content

Commit b360481

Browse files
committed
release v3.74.0
1 parent 17d1658 commit b360481

File tree

8 files changed

+42
-37
lines changed

8 files changed

+42
-37
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ npm install @vbarbarosh/node-helpers
2020
A subset of `@vbarbarosh/node-helpers` is available for browser:
2121

2222
```html
23-
<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.73.0/dist/browser.js"></script>
23+
<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.74.0/dist/browser.js"></script>
2424
```
2525

2626
⚠️ All browser functions are exposed globally.

dist/browser.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function serializer(replacer, cycleReplacer) {
8080

8181
var map = {
8282
"./array_chunk.js": "./src/array_chunk.js",
83-
"./array_chunk_jobs.js": "./src/array_chunk_jobs.js",
83+
"./array_chunk_balanced.js": "./src/array_chunk_balanced.js",
8484
"./array_fps.js": "./src/array_fps.js",
8585
"./array_gcd.js": "./src/array_gcd.js",
8686
"./array_group.js": "./src/array_group.js",
@@ -205,39 +205,44 @@ module.exports = array_chunk;
205205

206206
/***/ }),
207207

208-
/***/ "./src/array_chunk_jobs.js":
209-
/*!*********************************!*\
210-
!*** ./src/array_chunk_jobs.js ***!
211-
\*********************************/
208+
/***/ "./src/array_chunk_balanced.js":
209+
/*!*************************************!*\
210+
!*** ./src/array_chunk_balanced.js ***!
211+
\*************************************/
212212
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
213213

214214
const clamp = __webpack_require__(/*! ./clamp */ "./src/clamp.js");
215215

216216
/**
217-
* Split an array of jobs between up to `max_threads`, while trying to put at least
218-
* `min_jobs_per_thread` items into each chunk.
217+
* Split an array into up to `max_chunks` balanced chunks, while ensuring that
218+
* each chunk contains at least `min_items_per_chunk` items (when possible).
219219
*
220-
* - If an array is empty → returns [].
221-
* - If there are too few items to satisfy `min_items_per_chunk`, even for 1 chunk,
222-
* everything goes into a single chunk.
220+
* The function distributes items as evenly as possible:
221+
* - Chunk sizes differ by at most 1 item.
222+
* - The number of chunks never exceeds `max_chunks`.
223223
*
224-
* Alternative names:
225-
* - array_chunk_balanced
224+
* Originally designed for distributing workload across threads
225+
* (e.g. `array_chunk_balanced(jobs, max_threads, min_jobs_per_thread)`).
226226
*
227-
* @param array
228-
* @param max_threads
229-
* @param min_jobs_per_thread
230-
* @returns {*[]}
227+
* Edge cases:
228+
* - If the input array is empty → returns [].
229+
* - If there are too few items to satisfy `min_items_per_chunk`, even for a single
230+
* chunk, all items are placed into one chunk.
231+
*
232+
* @param {Array} array
233+
* @param {number} max_chunks
234+
* @param {number} min_items_per_chunk
235+
* @returns {Array<Array>}
231236
*/
232-
function array_chunk_jobs(array = [], max_threads = 1, min_jobs_per_thread = 1)
237+
function array_chunk_balanced(array = [], max_chunks = 1, min_items_per_chunk = 1)
233238
{
234-
const total_threads = clamp(1, max_threads, Math.floor(array.length / min_jobs_per_thread));
235-
const jobs_per_thread = Math.floor(array.length / total_threads);
236-
let extra = array.length % total_threads;
239+
const total_chunks = clamp(1, max_chunks, Math.floor(array.length / min_items_per_chunk));
240+
const items_per_chunk = Math.floor(array.length / total_chunks);
241+
let extra = array.length % total_chunks;
237242

238243
const out = [];
239244
for (let i = 0; i < array.length; ) {
240-
const size = jobs_per_thread + (extra ? 1 : 0);
245+
const size = items_per_chunk + (extra ? 1 : 0);
241246
out.push(array.slice(i, i + size));
242247
i += size;
243248
if (extra) {
@@ -247,7 +252,7 @@ function array_chunk_jobs(array = [], max_threads = 1, min_jobs_per_thread = 1)
247252
return out;
248253
}
249254

250-
module.exports = array_chunk_jobs;
255+
module.exports = array_chunk_balanced;
251256

252257

253258
/***/ }),
@@ -2479,10 +2484,10 @@ var __webpack_exports__ = {};
24792484
\******************************/
24802485
const ns = new URL(document.currentScript.src).searchParams.get('var') ?? 'h';
24812486
if (typeof window[ns] !== 'undefined') {
2482-
console.log(`❌ @vbarbarosh/node-helpers@${"3.73.0"} was not injected — window.${ns} is already in use`);
2487+
console.log(`❌ @vbarbarosh/node-helpers@${"3.74.0"} was not injected — window.${ns} is already in use`);
24832488
}
24842489
else {
2485-
console.log(`🎉 @vbarbarosh/node-helpers@${"3.73.0"} successfully exposed as window.${ns}`);
2490+
console.log(`🎉 @vbarbarosh/node-helpers@${"3.74.0"} successfully exposed as window.${ns}`);
24862491
window[ns] = {};
24872492
// https://github.com/webpack/webpack/issues/625
24882493
// https://webpack.js.org/guides/dependency-management/#require-context

docs/data.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@
331331
"markdown": null
332332
},
333333
{
334-
"id": "array_chunk_jobs",
335-
"name": "array_chunk_jobs",
336-
"file": "src/array_chunk_jobs.js",
337-
"require": "const array_chunk_jobs = require('@vbarbarosh/node-helpers/src/array_chunk_jobs');",
338-
"source_code": "const clamp = require('./clamp');\n\n/**\n * Split an array of jobs between up to `max_threads`, while trying to put at least\n * `min_jobs_per_thread` items into each chunk.\n *\n * - If an array is empty → returns [].\n * - If there are too few items to satisfy `min_items_per_chunk`, even for 1 chunk,\n * everything goes into a single chunk.\n *\n * Alternative names:\n * - array_chunk_balanced\n *\n * @param array\n * @param max_threads\n * @param min_jobs_per_thread\n * @returns {*[]}\n */\nfunction array_chunk_jobs(array = [], max_threads = 1, min_jobs_per_thread = 1)\n{\n const total_threads = clamp(1, max_threads, Math.floor(array.length / min_jobs_per_thread));\n const jobs_per_thread = Math.floor(array.length / total_threads);\n let extra = array.length % total_threads;\n\n const out = [];\n for (let i = 0; i < array.length; ) {\n const size = jobs_per_thread + (extra ? 1 : 0);\n out.push(array.slice(i, i + size));\n i += size;\n if (extra) {\n extra--;\n }\n }\n return out;\n}\n\nmodule.exports = array_chunk_jobs;\n",
334+
"id": "array_chunk_balanced",
335+
"name": "array_chunk_balanced",
336+
"file": "src/array_chunk_balanced.js",
337+
"require": "const array_chunk_balanced = require('@vbarbarosh/node-helpers/src/array_chunk_balanced');",
338+
"source_code": "const clamp = require('./clamp');\n\n/**\n * Split an array into up to `max_chunks` balanced chunks, while ensuring that\n * each chunk contains at least `min_items_per_chunk` items (when possible).\n *\n * The function distributes items as evenly as possible:\n * - Chunk sizes differ by at most 1 item.\n * - The number of chunks never exceeds `max_chunks`.\n *\n * Originally designed for distributing workload across threads\n * (e.g. `array_chunk_balanced(jobs, max_threads, min_jobs_per_thread)`).\n *\n * Edge cases:\n * - If the input array is empty → returns [].\n * - If there are too few items to satisfy `min_items_per_chunk`, even for a single\n * chunk, all items are placed into one chunk.\n *\n * @param {Array} array\n * @param {number} max_chunks\n * @param {number} min_items_per_chunk\n * @returns {Array<Array>}\n */\nfunction array_chunk_balanced(array = [], max_chunks = 1, min_items_per_chunk = 1)\n{\n const total_chunks = clamp(1, max_chunks, Math.floor(array.length / min_items_per_chunk));\n const items_per_chunk = Math.floor(array.length / total_chunks);\n let extra = array.length % total_chunks;\n\n const out = [];\n for (let i = 0; i < array.length; ) {\n const size = items_per_chunk + (extra ? 1 : 0);\n out.push(array.slice(i, i + size));\n i += size;\n if (extra) {\n extra--;\n }\n }\n return out;\n}\n\nmodule.exports = array_chunk_balanced;\n",
339339
"markdown": null
340340
},
341341
{

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<script src="https://unpkg.com/axios@1.11.0/dist/axios.min.js"></script>
1313
<script src="https://unpkg.com/@vbarbarosh/ui-helpers@0.4.0/src/static/js/bundle.js"></script>
14-
<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.73.0/dist/browser.js?var=h"></script>
14+
<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.74.0/dist/browser.js?var=h"></script>
1515
<script src="js/components/main-demos.js"></script>
1616
<script src="js/components/main-header.js"></script>
1717
<script src="js/components/main-helpers.js"></script>

docs/js/components/main-demos.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ vue_component('main-demos', {
1414
demos: function () {
1515
const package_json = `{
1616
"dependencies": {
17-
"@vbarbarosh/node-helpers": "^3.73.0"
17+
"@vbarbarosh/node-helpers": "^3.74.0"
1818
}
1919
}`;
2020
const tmp = {};

docs/js/components/main-header.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ vue_component('main-header', {
2121
2222
<p>A subset of <b>@vbarbarosh/node-helpers</b> is also available for browser:</p>
2323
<div>
24-
<div class="rel"><copy-to-clipboard value='<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.73.0/dist/browser.js?var=h">&lt;/script>"' /></div>
25-
<prism-html value='<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.73.0/dist/browser.js?var=h">&lt;/script>' />
24+
<div class="rel"><copy-to-clipboard value='<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.74.0/dist/browser.js?var=h">&lt;/script>"' /></div>
25+
<prism-html value='<script src="https://unpkg.com/@vbarbarosh/node-helpers@3.74.0/dist/browser.js?var=h">&lt;/script>' />
2626
</div>
2727
<p>⚠️ All browser functions are exposed as <strong>window.h</strong>. This could be changed by <strong>?var=new_name</strong> query parameter.</p>
2828
</div>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
33
"license": "MIT",
44
"name": "@vbarbarosh/node-helpers",
5-
"version": "3.73.0",
5+
"version": "3.74.0",
66
"description": "A set of helpers for JavaScript/Node.js",
77
"unpkg": "dist/browser.js",
88
"jsdelivr": "dist/browser.js",

0 commit comments

Comments
 (0)