@lsby/ts-format 0.0.1
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/dist/cjs/index.cjs +51 -0
- package/dist/cjs/index.d.cts +3 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +26 -0
- package/package.json +42 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
format: () => format
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
function format(formatString, ...args) {
|
|
27
|
+
let i = 0;
|
|
28
|
+
return formatString.replace(/%[sdjifo]/g, (match) => {
|
|
29
|
+
const arg = args[i++];
|
|
30
|
+
switch (match) {
|
|
31
|
+
case "%s":
|
|
32
|
+
return String(arg);
|
|
33
|
+
case "%d":
|
|
34
|
+
return String(Number(arg));
|
|
35
|
+
case "%j":
|
|
36
|
+
return JSON.stringify(arg);
|
|
37
|
+
case "%i":
|
|
38
|
+
return String(Math.floor(Number(arg)));
|
|
39
|
+
case "%f":
|
|
40
|
+
return String(Number(arg));
|
|
41
|
+
case "%o":
|
|
42
|
+
return String(arg);
|
|
43
|
+
default:
|
|
44
|
+
return match;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
format
|
|
51
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function format(formatString, ...args) {
|
|
3
|
+
let i = 0;
|
|
4
|
+
return formatString.replace(/%[sdjifo]/g, (match) => {
|
|
5
|
+
const arg = args[i++];
|
|
6
|
+
switch (match) {
|
|
7
|
+
case "%s":
|
|
8
|
+
return String(arg);
|
|
9
|
+
case "%d":
|
|
10
|
+
return String(Number(arg));
|
|
11
|
+
case "%j":
|
|
12
|
+
return JSON.stringify(arg);
|
|
13
|
+
case "%i":
|
|
14
|
+
return String(Math.floor(Number(arg)));
|
|
15
|
+
case "%f":
|
|
16
|
+
return String(Number(arg));
|
|
17
|
+
case "%o":
|
|
18
|
+
return String(arg);
|
|
19
|
+
default:
|
|
20
|
+
return match;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
format
|
|
26
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lsby/ts-format",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
"require": "./dist/cjs/index.cjs",
|
|
7
|
+
"import": "./dist/esm/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build:all": "npm run build:cjs && npm run build:esm",
|
|
14
|
+
"build:cjs": "tsup src/**/*.ts --format cjs --clean --dts -d dist/cjs",
|
|
15
|
+
"build:esm": "tsup src/**/*.ts --format esm --clean --dts -d dist/esm",
|
|
16
|
+
"check:all": "npm run check:format && npm run check:lint && npm run check:type",
|
|
17
|
+
"check:format": "prettier --write .",
|
|
18
|
+
"check:lint": "eslint . --fix",
|
|
19
|
+
"check:type": "tsc --noEmit",
|
|
20
|
+
"check:type:watch": "tsc --noEmit -w",
|
|
21
|
+
"pub:public": "npm run check:all && npm run test:base && npm run build:all && bumpp && npm publish --access public",
|
|
22
|
+
"test:base": "npm run check:all && vitest run",
|
|
23
|
+
"test:coverage": "npm run check:all && vitest run --coverage && open-cli ./coverage/index.html"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"vitest": "^2.0.2",
|
|
27
|
+
"zod": "^3.23.8"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.2.1",
|
|
31
|
+
"@lsby/eslint-config": "^0.0.2",
|
|
32
|
+
"@types/node": "^20.12.10",
|
|
33
|
+
"@vitest/coverage-v8": "^2.0.2",
|
|
34
|
+
"bumpp": "^9.4.1",
|
|
35
|
+
"open-cli": "^8.0.0",
|
|
36
|
+
"prettier": "3.2.5",
|
|
37
|
+
"prettier-plugin-packagejson": "^2.5.0",
|
|
38
|
+
"tsup": "^8.0.2",
|
|
39
|
+
"tsx": "^4.9.3",
|
|
40
|
+
"typescript": "^5.4.5"
|
|
41
|
+
}
|
|
42
|
+
}
|