mzm-id-code-converter 1.0.0 → 1.1.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.
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { default as IdCodeConverter } from './utils/IdCodeConverter/index';
2
+ /** 默认导出功能类 */
3
+ export default IdCodeConverter;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,+BAA+B,CAAC;AAE5D,cAAc;AACd,eAAe,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ "use strict";const n=class n{encode(t){if("string"!=typeof t||!/^\d+$/.test(t))throw new Error('ID必须是纯数字字符串,例如:"1967761684512030722"');const e=BigInt(t),r=(e>>48n)%64n;let o="",E=e&n.MAX_48BIT;for(let H=0;H<7;H++){const t=Number(E%n.CHARSET_LENGTH);o=n.CHARSET[t]+o,E/=n.CHARSET_LENGTH}const T=Number(E<<0n|r);return o=n.CHARSET[T]+o,8!==o.length&&(o=o.padStart(8,n.CHARSET[0]).slice(-8)),o}decode(t){if("string"!=typeof t||8!==t.length)throw new Error("输入必须是8位固定长度字符串");for(const E of t)if(-1===n.CHARSET.indexOf(E))throw new Error(`包含非法字符:${E},仅允许${n.CHARSET}中的字符(无-)`);let e=0n,r=0n;for(let E=0;E<7;E++){const r=BigInt(n.CHARSET.indexOf(t[E]));e=e*n.CHARSET_LENGTH+r}const o=BigInt(n.CHARSET.indexOf(t[7]));r=o>>0n,e=e<<6n|0x3fn&o;return(r<<48n|e).toString()}};n.CHARSET="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@",n.CHARSET_LENGTH=BigInt(n.CHARSET.length),n.MAX_48BIT=(1n<<48n)-1n;let t=n;module.exports=t;
@@ -0,0 +1 @@
1
+ const n=class n{encode(t){if("string"!=typeof t||!/^\d+$/.test(t))throw new Error('ID必须是纯数字字符串,例如:"1967761684512030722"');const e=BigInt(t),r=(e>>48n)%64n;let o="",E=e&n.MAX_48BIT;for(let H=0;H<7;H++){const t=Number(E%n.CHARSET_LENGTH);o=n.CHARSET[t]+o,E/=n.CHARSET_LENGTH}const T=Number(E<<0n|r);return o=n.CHARSET[T]+o,8!==o.length&&(o=o.padStart(8,n.CHARSET[0]).slice(-8)),o}decode(t){if("string"!=typeof t||8!==t.length)throw new Error("输入必须是8位固定长度字符串");for(const E of t)if(-1===n.CHARSET.indexOf(E))throw new Error(`包含非法字符:${E},仅允许${n.CHARSET}中的字符(无-)`);let e=0n,r=0n;for(let E=0;E<7;E++){const r=BigInt(n.CHARSET.indexOf(t[E]));e=e*n.CHARSET_LENGTH+r}const o=BigInt(n.CHARSET.indexOf(t[7]));r=o>>0n,e=e<<6n|0x3fn&o;return(r<<48n|e).toString()}};n.CHARSET="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@",n.CHARSET_LENGTH=BigInt(n.CHARSET.length),n.MAX_48BIT=(1n<<48n)-1n;let t=n;export{t as default};
@@ -0,0 +1 @@
1
+ !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self).mzmIdCodeConverter=e()}(this,function(){"use strict";const n=class n{encode(e){if("string"!=typeof e||!/^\d+$/.test(e))throw new Error('ID必须是纯数字字符串,例如:"1967761684512030722"');const t=BigInt(e),o=(t>>48n)%64n;let r="",f=t&n.MAX_48BIT;for(let s=0;s<7;s++){const e=Number(f%n.CHARSET_LENGTH);r=n.CHARSET[e]+r,f/=n.CHARSET_LENGTH}const i=Number(f<<0n|o);return r=n.CHARSET[i]+r,8!==r.length&&(r=r.padStart(8,n.CHARSET[0]).slice(-8)),r}decode(e){if("string"!=typeof e||8!==e.length)throw new Error("输入必须是8位固定长度字符串");for(const f of e)if(-1===n.CHARSET.indexOf(f))throw new Error(`包含非法字符:${f},仅允许${n.CHARSET}中的字符(无-)`);let t=0n,o=0n;for(let f=0;f<7;f++){const o=BigInt(n.CHARSET.indexOf(e[f]));t=t*n.CHARSET_LENGTH+o}const r=BigInt(n.CHARSET.indexOf(e[7]));o=r>>0n,t=t<<6n|0x3fn&r;return(o<<48n|t).toString()}};return n.CHARSET="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_@",n.CHARSET_LENGTH=BigInt(n.CHARSET.length),n.MAX_48BIT=(1n<<48n)-1n,n});
@@ -0,0 +1,18 @@
1
+ export default class IdCodeConverter {
2
+ private static readonly CHARSET;
3
+ private static readonly CHARSET_LENGTH;
4
+ private static readonly MAX_48BIT;
5
+ /**
6
+ * 编码:超长数字ID → 8位固定长度字符串(无-字符,纯可逆)
7
+ * @param idStr 纯数字字符串ID(支持任意长度,如"1967761684512030722")
8
+ * @returns 8位固定长度字符串(仅含0-9a-zA-Z_@)
9
+ */
10
+ encode(idStr: string): string;
11
+ /**
12
+ * 解码:8位字符串 → 原始超长数字ID(无需原始列表,纯可逆)
13
+ * @param code 8位字符串(仅含0-9a-zA-Z_@,无-)
14
+ * @returns 原始数字字符串ID
15
+ */
16
+ decode(code: string): string;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/IdCodeConverter/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,eAAe;IAEnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAsE;IACrG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAA+B;IACrE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAErD;;;;OAIG;IACI,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAkCpC;;;;OAIG;IACI,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CA+BnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mzm-id-code-converter",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "id code转换器",
5
5
  "type": "module",
6
6
  "main": "./lib/mzm-id-code-converter.cjs.js",