@bouko/ts 0.1.8 → 0.1.9

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/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { JsonMap, JsonValue } from "./types/generic";
2
2
  export * from "./types/generic";
3
3
  export * from "./utils/checkers";
4
+ export * from "./utils/formatters";
4
5
  export * from "./utils/parsers";
5
6
  export declare const safely: <T>(action: () => T) => T | undefined;
6
7
  export declare const safelyThru: <T>(arr: T[], action: (item: T) => void) => void;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./types/generic";
2
2
  export * from "./utils/checkers";
3
+ export * from "./utils/formatters";
3
4
  export * from "./utils/parsers";
4
5
  export const safely = (action) => {
5
6
  try {
@@ -12,4 +12,4 @@ export type StringMap = Record<string, string>;
12
12
  export type JsonMap = {
13
13
  [key: string]: JsonValue | JsonValue[];
14
14
  };
15
- export type JsonValue = string | number | boolean | null | undefined | JsonMap;
15
+ export type JsonValue = string | string[] | number | number[] | boolean | boolean[] | null | null[] | undefined | undefined[] | JsonMap | JsonMap[];
@@ -0,0 +1 @@
1
+ export declare const shortenStr: (str: string) => string;
@@ -0,0 +1,5 @@
1
+ export const shortenStr = (str) => {
2
+ if (str.length <= 6)
3
+ return str;
4
+ return `${str.slice(0, 3)}...${str.slice(-3)}`;
5
+ };
@@ -1,2 +1,4 @@
1
+ import { JsonValue } from "../types/generic";
2
+ export declare const parseStr: <T extends JsonValue>(input: string) => T;
1
3
  export declare const parseNum: (input: string) => number | undefined;
2
4
  export declare const parseBool: (input: string) => boolean;
@@ -1,3 +1,15 @@
1
+ import { isNum, isBool } from "./checkers";
2
+ export const parseStr = (input) => {
3
+ if (isNum(input))
4
+ return parseNum(input);
5
+ else if (isBool(input))
6
+ return parseBool(input);
7
+ try {
8
+ return JSON.parse(input);
9
+ }
10
+ catch { }
11
+ return input.trim();
12
+ };
1
13
  export const parseNum = (input) => {
2
14
  const num = Number(input.trim());
3
15
  if (!isNaN(num))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/ts",
4
- "version": "0.1.8",
4
+ "version": "0.1.9",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "MIT",