-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增upperFirst, random, getGlobalThis, isArrayBuffer 等方法
- Loading branch information
Showing
13 changed files
with
346 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
{ | ||
"docwriter.style": "JSDoc" | ||
"docwriter.style": "JSDoc", | ||
"cSpell.words": [ | ||
"vhooks" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { random } from '../../src' | ||
|
||
describe('number', () => { | ||
test('should return random number between min and max', () => { | ||
const min = 1 | ||
const max = 10 | ||
for (let i = 0; i < max; i++) { | ||
const result = random(min, max) | ||
expect(result).toBeGreaterThanOrEqual(min) | ||
expect(result).toBeLessThanOrEqual(max) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { upperFirst } from '../../src' | ||
|
||
describe('string', () => { | ||
test('should upperCase first letter', () => { | ||
expect(upperFirst('hello world')).toBe('Hello world') | ||
expect(upperFirst('HELLO WORLD')).toBe('HELLO WORLD') | ||
expect(upperFirst(String({}))).toBe('[object Object]') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./dist/utils.prod.cjs.js') | ||
module.exports = require('./dist/utils.cjs.prod.js') | ||
} else { | ||
module.exports = require('./dist/utils.cjs.js') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* @Author: vyron | ||
* @Date: 2022-06-01 16:26:31 | ||
* @LastEditTime: 2022-06-01 17:08:12 | ||
* @LastEditors: vyron | ||
* @Description: number utils | ||
* @FilePath: /utils/packages/utils/src/number/index.ts | ||
*/ | ||
|
||
/** | ||
* Returns a random number between the minimum and maximum values. | ||
* Configure floating to true to specify decimals and false by default | ||
* @param {number} [min=0] - The minimum value | ||
* @param {number} [max=1] - The maximum value | ||
* @param {boolean} [floating=false] - If true, the number will be a float | ||
* @returns {number} - The random number between the minimum and maximum values. | ||
*/ | ||
export function random( | ||
min: number = 0, | ||
max: number = 1, | ||
floating: boolean = false | ||
): number { | ||
const number = Math.random() * (max - min + 1) + min | ||
return floating ? number : Math.floor(number) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* @Author: vyron | ||
* @Date: 2022-06-02 14:13:16 | ||
* @LastEditTime: 2022-06-02 14:17:35 | ||
* @LastEditors: vyron | ||
* @Description: 获取全局对象 | ||
* @FilePath: /utils/packages/utils/src/object/global.ts | ||
*/ | ||
|
||
const _globalThis = | ||
typeof globalThis === 'object' && | ||
globalThis !== null && | ||
globalThis.Object === Object && | ||
globalThis | ||
|
||
const _self = | ||
typeof self === 'object' && self !== null && self.Object === Object && self | ||
|
||
const _global = | ||
typeof global === 'object' && | ||
global !== null && | ||
global.Object === Object && | ||
global | ||
|
||
export function getGlobalThis(): typeof globalThis { | ||
return _globalThis || _global || _self || Function('return this')() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* @Author: vyron | ||
* @Date: 2022-06-01 16:03:12 | ||
* @LastEditTime: 2022-06-01 17:09:47 | ||
* @LastEditors: vyron | ||
* @Description: string utils | ||
* @FilePath: /utils/packages/utils/src/string/index.ts | ||
*/ | ||
|
||
/** | ||
* Converts the first character of a string to uppercase and returns the string | ||
* @param {string} str - The string to convert | ||
* @returns {string} - The converted string | ||
*/ | ||
export function upperFirst(str: string): string { | ||
if (!str) return str | ||
return str.charAt(0).toUpperCase() + str.slice(1) | ||
} |
Oops, something went wrong.