Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@texting/charset-halfwidth

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@texting/charset-halfwidth - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

58

dist/index.cjs.js

@@ -5,9 +5,57 @@ 'use strict';

var regexCharset = require('@texting/regex-charset');
var charsetAnsi = require('@texting/charset-ansi');
var enumCharsFullwidth = require('@texting/enum-chars-fullwidth');
require('@texting/regex-charset');
const hasAnsi = tx => regexCharset.ANSI.test(tx);
const DELTA_FULL = 0xfee0; // export const REG_NUM_FULL = /^\s*[-+]?(?:,*[0-9]+)*.?[0-9]+\s*$/
const hasAstral = tx => regexCharset.ASTRAL.test(tx);
const LEAN_REG = /(\W)\s+/g;
/**
* Half-angle string -> Full-angle string
* 半角转化为全角
* a.全角空格为12288,半角空格为32
* b.其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
* @param {string} text
* @returns {string}
* @constructor
*/
exports.hasAnsi = hasAnsi;
exports.hasAstral = hasAstral;
const _halfToFullCore = text => {
let l = text === null || text === void 0 ? void 0 : text.length,
i = 0,
t = '',
n;
while (i < l && (n = text.charCodeAt(i))) {
t += n === 0x20 ? enumCharsFullwidth.SP : 0x20 < n && n < 0x7f ? String.fromCharCode(n + DELTA_FULL) : text[i];
i++;
}
return t;
};
const _halfToFull = function (tx) {
const {
ansi,
lean
} = this;
if (ansi && charsetAnsi.hasAnsi(tx)) tx = charsetAnsi.clearAnsi(tx);
if (lean) tx = tx.replace(LEAN_REG, (_, x) => x);
return _halfToFullCore(tx);
};
const halfToFull = (text, {
ansi = true,
lean = true
} = {}) => _halfToFull.call({
ansi,
lean
}, text);
const HalfToFull = ({
ansi = true,
lean = true
} = {}) => _halfToFull.bind({
ansi,
lean
});
exports.HalfToFull = HalfToFull;
exports.halfToFull = halfToFull;

@@ -1,7 +0,55 @@

import { ANSI, ASTRAL } from '@texting/regex-charset';
import { hasAnsi, clearAnsi } from '@texting/charset-ansi';
import { SP } from '@texting/enum-chars-fullwidth';
import '@texting/regex-charset';
const hasAnsi = tx => ANSI.test(tx);
const DELTA_FULL = 0xfee0; // export const REG_NUM_FULL = /^\s*[-+]?(?:,*[0-9]+)*.?[0-9]+\s*$/
const hasAstral = tx => ASTRAL.test(tx);
const LEAN_REG = /(\W)\s+/g;
/**
* Half-angle string -> Full-angle string
* 半角转化为全角
* a.全角空格为12288,半角空格为32
* b.其他字符半角(33-126)与全角(65281-65374)的对应关系是:均相差65248
* @param {string} text
* @returns {string}
* @constructor
*/
export { hasAnsi, hasAstral };
const _halfToFullCore = text => {
let l = text === null || text === void 0 ? void 0 : text.length,
i = 0,
t = '',
n;
while (i < l && (n = text.charCodeAt(i))) {
t += n === 0x20 ? SP : 0x20 < n && n < 0x7f ? String.fromCharCode(n + DELTA_FULL) : text[i];
i++;
}
return t;
};
const _halfToFull = function (tx) {
const {
ansi,
lean
} = this;
if (ansi && hasAnsi(tx)) tx = clearAnsi(tx);
if (lean) tx = tx.replace(LEAN_REG, (_, x) => x);
return _halfToFullCore(tx);
};
const halfToFull = (text, {
ansi = true,
lean = true
} = {}) => _halfToFull.call({
ansi,
lean
}, text);
const HalfToFull = ({
ansi = true,
lean = true
} = {}) => _halfToFull.bind({
ansi,
lean
});
export { HalfToFull, halfToFull };

8

package.json
{
"name": "@texting/charset-halfwidth",
"version": "0.0.1",
"version": "0.0.2",
"description": "Regex sets",

@@ -18,3 +18,5 @@ "main": "dist/index.cjs.js",

"dependencies": {
"@texting/regex-charset": "^0.0.1"
"@texting/charset-ansi": "^0.0.2",
"@texting/enum-chars-fullwidth": "^0.0.2",
"@texting/regex-charset": "^0.0.2"
},

@@ -37,3 +39,3 @@ "repository": {

"homepage": "https://github.com/gadge/spare#readme",
"gitHead": "59f3247c566b34b21cac95100e4802ff6e046299"
"gitHead": "fe8ad527c1de5be3a998d3a398f8638c65f3734b"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc