rattail 0.0.2 → 0.0.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/README.md CHANGED
@@ -8,6 +8,13 @@
8
8
  <a href="https://rattail.pages.dev">Documentation</a> |
9
9
  <a href="https://github.com/varletjs/rattail/blob/main/README.zh-CN.md">中文介绍</a>
10
10
  </p>
11
+ <p>
12
+ <img src="https://img.shields.io/npm/v/rattail?style=flat-square" alt="version">
13
+ <img src="https://img.shields.io/github/stars/varletjs/rattail" alt="stars">
14
+ <img src="https://img.shields.io/npm/l/rattail.svg" alt="license">
15
+ <img src="https://img.shields.io/codecov/c/github/varletjs/rattail" alt="coverage">
16
+ <img src="https://github.com/varletjs/varlet/workflows/CI/badge.svg" alt="ci">
17
+ </p>
11
18
  </div>
12
19
 
13
20
  ---
@@ -17,6 +24,7 @@
17
24
  - 🛠️ &nbsp; Provide utilities frequently used in daily development
18
25
  - 🛠️ &nbsp; Utilities implementation is very lightweight
19
26
  - 🛠️ &nbsp; Written based on ts, providing complete ts types
27
+ - 💪 &nbsp; Make sure more than 90% unit test coverage, providing stability assurance
20
28
 
21
29
  ### Installation
22
30
 
package/README.zh-CN.md CHANGED
@@ -8,6 +8,13 @@
8
8
  <a href="https://rattail.pages.dev/zh">文档</a> |
9
9
  <a href="https://github.com/varletjs/rattail/blob/main/README.md">ENGLISH README</a>
10
10
  </p>
11
+ <p>
12
+ <img src="https://img.shields.io/npm/v/rattail?style=flat-square" alt="version">
13
+ <img src="https://img.shields.io/github/stars/varletjs/rattail" alt="stars">
14
+ <img src="https://img.shields.io/npm/l/rattail.svg" alt="license">
15
+ <img src="https://img.shields.io/codecov/c/github/varletjs/rattail" alt="coverage">
16
+ <img src="https://github.com/varletjs/varlet/workflows/CI/badge.svg" alt="ci">
17
+ </p>
11
18
  </div>
12
19
 
13
20
  ---
@@ -17,6 +24,7 @@
17
24
  - 🛠️ &nbsp; 提供日常开发中经常使用的实用工具
18
25
  - 🛠️ &nbsp; 工具实现非常轻量
19
26
  - 🛠️ &nbsp; 使用 ts 编写,提供完善的类型支持
27
+ - 💪 &nbsp; 确保 90% 以上单元测试覆盖率,提供稳定性保证
20
28
 
21
29
  ### 安装
22
30
 
package/lib/index.cjs CHANGED
@@ -276,7 +276,8 @@ function pascalCase(s) {
276
276
  return camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
277
277
  }
278
278
  function camelize(s) {
279
- return s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
279
+ s = s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
280
+ return s.replace(s.charAt(0), s.charAt(0).toLowerCase());
280
281
  }
281
282
  function kebabCase(s) {
282
283
  const ret = s.replace(/([A-Z])/g, " $1").trim();
@@ -291,7 +292,7 @@ function slash(path) {
291
292
  }
292
293
  var key = 0;
293
294
  function genStringKey() {
294
- return `${key++}`;
295
+ return `generated-key-${key++}`;
295
296
  }
296
297
  function capitalizeFirstLetter(s) {
297
298
  return s.charAt(0).toUpperCase() + s.slice(1);
@@ -436,7 +437,7 @@ function throttle(fn, delay = 200) {
436
437
  let timer;
437
438
  let start = 0;
438
439
  return function loop(...args) {
439
- const now = Date.now();
440
+ const now = performance.now();
440
441
  const elapsed = now - start;
441
442
  if (!start) {
442
443
  start = now;
@@ -488,23 +489,22 @@ var key2 = 0;
488
489
  function genNumberKey() {
489
490
  return key2++;
490
491
  }
491
- function randomNumber(min = 0, max = 1) {
492
+ function randomNumber(min = 0, max = 100) {
492
493
  return Math.floor(Math.random() * (max - min + 1)) + min;
493
494
  }
494
495
 
495
496
  // src/collection.ts
496
497
  function mergeWith(object, source, callback) {
497
- const isObject2 = (obj) => obj !== null && typeof obj === "object";
498
498
  function baseMerge(target, src) {
499
499
  for (const key3 in src) {
500
- if (Object.prototype.hasOwnProperty.call(src, key3)) {
500
+ if (hasOwn(src, key3)) {
501
501
  const srcValue = src[key3];
502
502
  const targetValue = target[key3];
503
- const customResult = callback(targetValue, srcValue, key3, object, source);
503
+ const customResult = callback == null ? void 0 : callback(targetValue, srcValue, key3, object, source);
504
504
  if (customResult !== void 0) {
505
505
  target[key3] = customResult;
506
- } else if (isObject2(srcValue)) {
507
- if (isObject2(targetValue)) {
506
+ } else if (isObject(srcValue)) {
507
+ if (isObject(targetValue)) {
508
508
  target[key3] = baseMerge(targetValue, srcValue);
509
509
  } else {
510
510
  target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
package/lib/index.d.cts CHANGED
@@ -79,7 +79,7 @@ declare function slash(path: string): string;
79
79
  declare function genStringKey(): string;
80
80
  declare function capitalizeFirstLetter(s: string): string;
81
81
 
82
- declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, callback: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any | void): TObject & TSource;
82
+ declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, callback?: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any | void): TObject & TSource;
83
83
 
84
84
  declare function tryParseJSON<T>(json: string): T | undefined;
85
85
  declare function prettyJSONObject(jsonObject: Record<string, any>): string;
package/lib/index.d.ts CHANGED
@@ -79,7 +79,7 @@ declare function slash(path: string): string;
79
79
  declare function genStringKey(): string;
80
80
  declare function capitalizeFirstLetter(s: string): string;
81
81
 
82
- declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, callback: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any | void): TObject & TSource;
82
+ declare function mergeWith<TObject extends Record<string, any>, TSource extends Record<string, any>>(object: TObject, source: TSource, callback?: (objValue: any, srcValue: any, key: string | number | symbol, object?: TObject, source?: TSource) => any | void): TObject & TSource;
83
83
 
84
84
  declare function tryParseJSON<T>(json: string): T | undefined;
85
85
  declare function prettyJSONObject(jsonObject: Record<string, any>): string;
package/lib/index.js CHANGED
@@ -177,7 +177,8 @@ function pascalCase(s) {
177
177
  return camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
178
178
  }
179
179
  function camelize(s) {
180
- return s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
180
+ s = s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
181
+ return s.replace(s.charAt(0), s.charAt(0).toLowerCase());
181
182
  }
182
183
  function kebabCase(s) {
183
184
  const ret = s.replace(/([A-Z])/g, " $1").trim();
@@ -192,7 +193,7 @@ function slash(path) {
192
193
  }
193
194
  var key = 0;
194
195
  function genStringKey() {
195
- return `${key++}`;
196
+ return `generated-key-${key++}`;
196
197
  }
197
198
  function capitalizeFirstLetter(s) {
198
199
  return s.charAt(0).toUpperCase() + s.slice(1);
@@ -337,7 +338,7 @@ function throttle(fn, delay = 200) {
337
338
  let timer;
338
339
  let start = 0;
339
340
  return function loop(...args) {
340
- const now = Date.now();
341
+ const now = performance.now();
341
342
  const elapsed = now - start;
342
343
  if (!start) {
343
344
  start = now;
@@ -389,23 +390,22 @@ var key2 = 0;
389
390
  function genNumberKey() {
390
391
  return key2++;
391
392
  }
392
- function randomNumber(min = 0, max = 1) {
393
+ function randomNumber(min = 0, max = 100) {
393
394
  return Math.floor(Math.random() * (max - min + 1)) + min;
394
395
  }
395
396
 
396
397
  // src/collection.ts
397
398
  function mergeWith(object, source, callback) {
398
- const isObject2 = (obj) => obj !== null && typeof obj === "object";
399
399
  function baseMerge(target, src) {
400
400
  for (const key3 in src) {
401
- if (Object.prototype.hasOwnProperty.call(src, key3)) {
401
+ if (hasOwn(src, key3)) {
402
402
  const srcValue = src[key3];
403
403
  const targetValue = target[key3];
404
- const customResult = callback(targetValue, srcValue, key3, object, source);
404
+ const customResult = callback == null ? void 0 : callback(targetValue, srcValue, key3, object, source);
405
405
  if (customResult !== void 0) {
406
406
  target[key3] = customResult;
407
- } else if (isObject2(srcValue)) {
408
- if (isObject2(targetValue)) {
407
+ } else if (isObject(srcValue)) {
408
+ if (isObject(targetValue)) {
409
409
  target[key3] = baseMerge(targetValue, srcValue);
410
410
  } else {
411
411
  target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rattail",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.js",