@douglasneuroinformatics/libjs 0.6.0 → 0.7.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.
|
Binary file
|
package/dist/string.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { CamelCase, SnakeCase } from 'type-fest';
|
|
1
|
+
import type { CamelCase, Primitive, SnakeCase } from 'type-fest';
|
|
2
2
|
export declare function camelToSnakeCase<T extends string>(s: T): SnakeCase<T>;
|
|
3
3
|
export declare function snakeToCamelCase<T extends string>(s: T): CamelCase<T>;
|
|
4
4
|
export declare function uncapitalize<T extends string>(s: T): Uncapitalize<T>;
|
|
5
5
|
export declare function capitalize<T extends string>(s: T): Capitalize<T>;
|
|
6
6
|
export declare function toLowerCase<T extends string>(s: T): Lowercase<T>;
|
|
7
7
|
export declare function toUpperCase<T extends string>(s: T): Uppercase<T>;
|
|
8
|
+
export declare function format(s: string, ...args: Exclude<Primitive, symbol>[]): string;
|
|
8
9
|
//# sourceMappingURL=string.d.ts.map
|
package/dist/string.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEjE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAEtD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAItD;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,mBAElD;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,iBAEhD;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAEjD;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,gBAEjD;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,UAKtE"}
|
package/dist/string.js
CHANGED
|
@@ -18,3 +18,10 @@ export function toLowerCase(s) {
|
|
|
18
18
|
export function toUpperCase(s) {
|
|
19
19
|
return s.toUpperCase();
|
|
20
20
|
}
|
|
21
|
+
export function format(s, ...args) {
|
|
22
|
+
for (const arg of args) {
|
|
23
|
+
s = s.replace('{}', String(arg));
|
|
24
|
+
}
|
|
25
|
+
return s;
|
|
26
|
+
}
|
|
27
|
+
console.log(format('Hello {}', 'World'));
|
package/dist/string.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { camelToSnakeCase, capitalize, snakeToCamelCase, toLowerCase, toUpperCase, uncapitalize } from './string.js';
|
|
2
|
+
import { camelToSnakeCase, capitalize, format, snakeToCamelCase, toLowerCase, toUpperCase, uncapitalize } from './string.js';
|
|
3
3
|
describe('camelToSnakeCase', () => {
|
|
4
4
|
it('should convert from camel to snake case ', () => {
|
|
5
5
|
expect(camelToSnakeCase('toSnakeCase')).toBe('to_snake_case');
|
|
@@ -38,3 +38,16 @@ describe('toUpperCase', () => {
|
|
|
38
38
|
expect(toUpperCase('foo')).toBe('FOO');
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
|
+
describe('format', () => {
|
|
42
|
+
it('should return the same string if no positional args are given', () => {
|
|
43
|
+
expect(format('Hello')).toBe('Hello');
|
|
44
|
+
expect(format('Hello {}')).toBe('Hello {}');
|
|
45
|
+
});
|
|
46
|
+
it('should insert positional arguments', () => {
|
|
47
|
+
expect(format('Hello {}', 'World')).toBe('Hello World');
|
|
48
|
+
expect(format('Hello {}. {}.', 'World', 'This function works')).toBe('Hello World. This function works.');
|
|
49
|
+
});
|
|
50
|
+
it('should ignore additional indices', () => {
|
|
51
|
+
expect(format('Hello {}{}.', 'World')).toBe('Hello World{}.');
|
|
52
|
+
});
|
|
53
|
+
});
|
package/package.json
CHANGED
|
Binary file
|