0.20.1 • Published 3 years ago
@terra-dev/use-string-bytes-length v0.20.1
@terra-dev/use-string-bytes-length
Validate the bytes length of a string
API
export function countUtf8Bytes(s: string): number {}
export function useStringBytesLength(str: string): number {}
export function useValidateStringBytes(
str: string,
minBytes: number,
maxBytes: number,
): BytesValid | undefined {}
Spec
__tests__/use-string-bytes-length.test.ts
import { renderHook } from '@testing-library/react-hooks';
import {
BytesValid,
countUtf8Bytes,
useStringBytesLength,
useValidateStringBytes,
} from '../';
describe('use-string-bytes-length', () => {
test('should get valid results', () => {
expect(countUtf8Bytes('aaaa')).toBe(4);
const { result: result0 } = renderHook(() => useStringBytesLength('aaaaa'));
expect(result0.current).toBe(5);
const { result: result1 } = renderHook(() =>
useValidateStringBytes('aaaaa', 2, 10),
);
expect(result1.current).toBeUndefined();
const { result: result2 } = renderHook(() =>
useValidateStringBytes('aaaaa', 6, 10),
);
expect(result2.current).toBe(BytesValid.LESS);
const { result: result3 } = renderHook(() =>
useValidateStringBytes('aaaaa', 2, 4),
);
expect(result3.current).toBe(BytesValid.MUCH);
});
});
0.20.1
3 years ago
0.20.0
3 years ago
0.19.0
3 years ago
0.18.0
3 years ago
0.17.0
3 years ago
0.17.1
3 years ago
0.16.0
3 years ago
0.16.0-alpha.4
3 years ago
0.16.0-alpha.1
3 years ago
0.16.0-alpha.3
3 years ago
0.16.0-alpha.2
3 years ago
0.14.0
3 years ago
0.15.0
3 years ago
0.13.0
3 years ago
0.13.1
3 years ago
0.12.2
3 years ago
0.10.0
3 years ago
0.11.0
3 years ago
0.10.1
3 years ago
0.12.0
3 years ago
0.10.2
3 years ago
0.8.0
3 years ago
0.12.1
3 years ago
0.5.0
3 years ago
0.4.0
3 years ago
0.7.0
3 years ago
0.6.0
3 years ago
0.3.0
3 years ago
0.2.0
3 years ago
0.1.0
3 years ago