@naturalcycles/js-lib 14.267.1 → 14.268.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.
@@ -173,8 +173,8 @@ export declare function _difference<T>(a1: T[], a2: T[] | Set<T>): T[];
173
173
  /**
174
174
  * Returns the sum of items, or 0 for empty array.
175
175
  */
176
- export declare function _sum(items: Iterable<number>): number;
177
- export declare function _sumBy<T>(items: Iterable<T>, mapper: Mapper<T, number | undefined>): number;
176
+ export declare function _sum<N extends number>(items: Iterable<N>): N;
177
+ export declare function _sumBy<T, N extends number>(items: Iterable<T>, mapper: Mapper<T, N | undefined>): N;
178
178
  /**
179
179
  * Map an array of T to a StringMap<V>,
180
180
  * by returning a tuple of [key, value] from a mapper function.
@@ -336,7 +336,7 @@ function _difference(a1, a2) {
336
336
  function _sum(items) {
337
337
  let sum = 0;
338
338
  for (const n of items) {
339
- sum += n;
339
+ sum = (sum + n);
340
340
  }
341
341
  return sum;
342
342
  }
@@ -347,7 +347,7 @@ function _sumBy(items, mapper) {
347
347
  const v = mapper(n, i++);
348
348
  if (typeof v === 'number') {
349
349
  // count only numbers, nothing else
350
- sum += v;
350
+ sum = (sum + v);
351
351
  }
352
352
  }
353
353
  return sum;
package/dist/bot.js CHANGED
@@ -4,7 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.BotReason = exports.BotDetectionService = void 0;
6
6
  const env_1 = require("./env");
7
- const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview|ahrefs|preview|lighthouse|facebookexternal|pinterest|screaming|apis-google|duplexweb-google|feedfetcher-google|google-read-aloud|googleweblight|mediapartners-google/i;
7
+ const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|slurp|MicrosoftPreview|ahrefs|preview|lighthouse|facebookexternal|pinterest|screaming|apis-google|duplexweb-google|feedfetcher-google|google-read-aloud|googleweblight|mediapartners-google/i;
8
8
  /**
9
9
  * Service to detect bots and CDP (Chrome DevTools Protocol).
10
10
  *
@@ -295,7 +295,7 @@ export function _difference(a1, a2) {
295
295
  export function _sum(items) {
296
296
  let sum = 0;
297
297
  for (const n of items) {
298
- sum += n;
298
+ sum = (sum + n);
299
299
  }
300
300
  return sum;
301
301
  }
@@ -306,7 +306,7 @@ export function _sumBy(items, mapper) {
306
306
  const v = mapper(n, i++);
307
307
  if (typeof v === 'number') {
308
308
  // count only numbers, nothing else
309
- sum += v;
309
+ sum = (sum + v);
310
310
  }
311
311
  }
312
312
  return sum;
package/dist-esm/bot.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // Relevant material:
2
2
  // https://deviceandbrowserinfo.com/learning_zone/articles/detecting-headless-chrome-puppeteer-2024
3
3
  import { isServerSide } from './env';
4
- const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview|ahrefs|preview|lighthouse|facebookexternal|pinterest|screaming|apis-google|duplexweb-google|feedfetcher-google|google-read-aloud|googleweblight|mediapartners-google/i;
4
+ const botRegex = /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|slurp|MicrosoftPreview|ahrefs|preview|lighthouse|facebookexternal|pinterest|screaming|apis-google|duplexweb-google|feedfetcher-google|google-read-aloud|googleweblight|mediapartners-google/i;
5
5
  /**
6
6
  * Service to detect bots and CDP (Chrome DevTools Protocol).
7
7
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.267.1",
3
+ "version": "14.268.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build": "dev-lib build-esm-cjs",
@@ -347,23 +347,26 @@ export function _difference<T>(a1: T[], a2: T[] | Set<T>): T[] {
347
347
  /**
348
348
  * Returns the sum of items, or 0 for empty array.
349
349
  */
350
- export function _sum(items: Iterable<number>): number {
351
- let sum = 0
350
+ export function _sum<N extends number>(items: Iterable<N>): N {
351
+ let sum = 0 as N
352
352
  for (const n of items) {
353
- sum += n
353
+ sum = (sum + n) as N
354
354
  }
355
355
  return sum
356
356
  }
357
357
 
358
- export function _sumBy<T>(items: Iterable<T>, mapper: Mapper<T, number | undefined>): number {
359
- let sum = 0
358
+ export function _sumBy<T, N extends number>(
359
+ items: Iterable<T>,
360
+ mapper: Mapper<T, N | undefined>,
361
+ ): N {
362
+ let sum = 0 as N
360
363
  let i = 0
361
364
 
362
365
  for (const n of items) {
363
366
  const v = mapper(n, i++)
364
367
  if (typeof v === 'number') {
365
368
  // count only numbers, nothing else
366
- sum += v
369
+ sum = (sum + v) as N
367
370
  }
368
371
  }
369
372
 
package/src/bot.ts CHANGED
@@ -26,7 +26,7 @@ export interface BotDetectionServiceCfg {
26
26
  }
27
27
 
28
28
  const botRegex =
29
- /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|snapchat|slurp|MicrosoftPreview|ahrefs|preview|lighthouse|facebookexternal|pinterest|screaming|apis-google|duplexweb-google|feedfetcher-google|google-read-aloud|googleweblight|mediapartners-google/i
29
+ /bot|spider|crawl|headless|electron|phantom|slimer|proximic|cincraw|slurp|MicrosoftPreview|ahrefs|preview|lighthouse|facebookexternal|pinterest|screaming|apis-google|duplexweb-google|feedfetcher-google|google-read-aloud|googleweblight|mediapartners-google/i
30
30
 
31
31
  /**
32
32
  * Service to detect bots and CDP (Chrome DevTools Protocol).