Deleted fullwidth-check.ts
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
import { actionAddins } from ".";
|
||||
import { IAction,IActionResult, IActionNode, IActionProperty, IField, IContext } from "../types/ActionTypes";
|
||||
|
||||
/**
|
||||
* アクションの属性定義
|
||||
*/
|
||||
interface FullWidthProps{
|
||||
field:IField
|
||||
}
|
||||
/**
|
||||
* 全角チェックアクション
|
||||
*/
|
||||
export class FullWidthAction implements IAction{
|
||||
name: string;
|
||||
actionProps: IActionProperty[];
|
||||
props:FullWidthProps;
|
||||
constructor(){
|
||||
this.name="全角チェック"; /* pgadminのnameと同様 */
|
||||
this.actionProps=[];
|
||||
this.props={
|
||||
field:{code:''}
|
||||
}
|
||||
//アクションを登録する
|
||||
this.register();
|
||||
}
|
||||
/**
|
||||
* アクションの実行を呼び出す
|
||||
* @param actionNode
|
||||
* @param event
|
||||
* @returns
|
||||
*/
|
||||
async process(actionNode:IActionNode,event:any,context:IContext):Promise<IActionResult> {
|
||||
let result={
|
||||
canNext:true,
|
||||
result:false
|
||||
};
|
||||
try{
|
||||
//属性設定を取得する
|
||||
this.actionProps=actionNode.actionProps;
|
||||
if (!('field' in actionNode.ActionValue) ) {
|
||||
return result
|
||||
}
|
||||
this.props = actionNode.ActionValue as FullWidthProps;
|
||||
//条件式の計算結果を取得
|
||||
const record = event.record;
|
||||
const value = record[this.props.field.code]?.value;
|
||||
if(value===undefined || value===''){
|
||||
return result;
|
||||
}
|
||||
if(!this.containsFullWidthChars(value)){
|
||||
record[this.props.field.code].error="半角が含まれています";
|
||||
result.canNext=false;
|
||||
return result;
|
||||
}
|
||||
result= {
|
||||
canNext:true,
|
||||
result:true
|
||||
}
|
||||
return result;
|
||||
}catch(error){
|
||||
event.error=error;
|
||||
console.error(error);
|
||||
result.canNext=false;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
containsFullWidthChars(text: string): boolean {
|
||||
const fullWidthRegex = /[/^[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFFEF\u4E00-\u9FAF\u3400-\u4DBF]+$/g;
|
||||
return fullWidthRegex.test(text);
|
||||
}
|
||||
register(): void {
|
||||
actionAddins[this.name]=this;
|
||||
}
|
||||
}
|
||||
new FullWidthAction();
|
||||
|
||||
/* countCharacters(input: string): [number, number] {
|
||||
|
||||
let fullwidthCount = 0;
|
||||
let halfwidthCount = 0;
|
||||
|
||||
for (let char of input) {
|
||||
// 文字コードを取得
|
||||
const code = char.charCodeAt(0);
|
||||
|
||||
// 半角の範囲
|
||||
if (code >= 33 && code <= 126) {
|
||||
halfwidthCount++;
|
||||
} else {
|
||||
fullwidthCount++;
|
||||
}
|
||||
}
|
||||
return [fullwidthCount, halfwidthCount];
|
||||
}
|
||||
|
||||
const result = countCharacters("こんにちはWorld");
|
||||
console.log(`全角文字数:${result[0]}, 半角文字数:${result[1]}`);
|
||||
*/
|
||||
Reference in New Issue
Block a user