GithubHelp home page GithubHelp logo

sevensc / typescript-string-operations Goto Github PK

View Code? Open in Web Editor NEW
35.0 5.0 14.0 970 KB

Simple lightweight string operation library for Typescript. No jQuery required! Unit tested, works with Angular.

License: MIT License

TypeScript 99.13% HTML 0.30% JavaScript 0.57%
string-formatter string-builder javascript typescript

typescript-string-operations's People

Contributors

aequi42 avatar dependabot[bot] avatar iwt-svenulrich avatar matt-lethargic avatar renovate[bot] avatar rvramesh avatar sevensc avatar tno2007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

typescript-string-operations's Issues

formatNumber problem

let url = /account/list?name={0}&group={1}&version={2}
url = String.Format(url, “sss”, "", "");

logout is
url = account/list?name=sss&group=000&version=000

I do not want 000, I want 0
what should I do?

private static formatNumber(input: number, formatTemplate: string): string {
let count = formatTemplate.length;
let stringValue = input.toString();
if (count <= stringValue.length)
return stringValue;
let remainingCount = count - stringValue.length;
remainingCount += 1; //Das Array muss einen Eintrag mehr als die benötigten Nullen besitzen
return new Array(remainingCount).join('0') + stringValue;
}

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/node 21.6.2
npm
package.json
  • @types/jest ^29.5.12
  • @types/node ^20.11.25
  • @typescript-eslint/eslint-plugin ^7.1.1
  • @typescript-eslint/parser ^7.1.1
  • eslint ^8.57.0
  • jest ^29.7.0
  • ts-jest ^29.1.2
  • ts-node ^10.9.2
  • typescript ^5.4.2
  • uglify-js ^3.17.4
  • natives 1.1.6

  • Check this box to trigger a request for Renovate to run again on this repository

Module parse failed: Unexpected token (1:607)

I'm getting error in the webpack while building the angular application.

I keep on getting this message on the terminal console

ERROR in ./node_modules/typescript-string-operations/dist/index.js 1:607 Module parse failed: Unexpected token (1:607) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders > "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StringBuilder=exports.String=exports.formatString=exports.joinString=exports.isNullOrWhiteSpace=exports.emptyString=void 0;const EOL="\r\n";function isNullOrWhiteSpace(value){return String.isNullOrWhiteSpace(value)}function joinString(delimiter,...args){return String.join(delimiter,...args)}function formatString(format,...args){return String.format(format,...args)}exports.emptyString="",exports.isNullOrWhiteSpace=isNullOrWhiteSpace,exports.joinString=joinString,exports.formatString=formatString;class String{static regexNumber=/{(\d+(:\w*)?)}/g;static regexObject=/{(\w+(:\w*)?)}/g;static empty="";static Empty="";static IsNullOrWhiteSpace(value){return String.isNullOrWhiteSpace(value)}static Join(delimiter,...args){return String.join(delimiter,...args)}static Format(format,...args){return String.format(format,...args)}static isNullOrWhiteSpace(value){try{return null==value||"undefined"==value?!0:value.toString().replace(/\s/g,"").length<1}catch(e){return console.log(e),!1}}static join(delimiter,...args){try{var firstArg=args[0];if(Array.isArray(firstArg)||firstArg instanceof Array){let tempString=String.empty;for(let i=0;i<firstArg.length;i++){var current=firstArg[i];i<firstArg.length-1?tempString+=current+delimiter:tempString+=current}return tempString}if("object"==typeof firstArg){let tempString=String.empty;const objectArg=firstArg,keys=Object.keys(firstArg);return keys.forEach(element=>{tempString+=objectArg[element]+delimiter}),tempString=tempString.slice(0,tempString.length-delimiter.length)}var stringArray=args;return String.joinString(delimiter,...stringArray)}catch(e){return console.log(e),String.empty}}static format(format,...args){try{return format.match(String.regexNumber)?String.formatString(String.regexNumber,format,args):format.match(String.regexObject)?String.formatString(String.regexObject,format,args,!0):format}catch(e){return console.log(e),String.empty}}static formatString(regex,format,args,parseByObject=!1){return format.replace(regex,function(match,x){const s=match.split(":");1<s.length&&(x=s[0].replace("{",""),match=s[1].replace("}",""));let arg;return null==(arg=(parseByObject?args[0]:args)[x])||null==arg||match.match(/{\d+}/)||void 0!==(arg=String.parsePattern(match,arg))&&null!=arg?arg:String.empty})}static parsePattern(match,arg){switch(match){case"L":return arg=arg.toLocaleLowerCase();case"U":return arg=arg.toLocaleUpperCase();case"d":if("string"==typeof arg)return String.getDisplayDateFromString(arg);if(arg instanceof Date)return String.format("{0:00}.{1:00}.{2:0000}",arg.getDate(),arg.getMonth(),arg.getFullYear());break;case"s":if("string"==typeof arg)return String.getSortableDateFromString(arg);if(arg instanceof Date)return String.format("{0:0000}-{1:00}-{2:00}",arg.getFullYear(),arg.getMonth(),arg.getDate());break;case"n":{const replacedString=(arg="string"!=typeof arg?arg.toString():arg).replace(/,/g,".");if(isNaN(parseFloat(replacedString))||replacedString.length<=3)break;const numberparts=replacedString.split(/\D+/g);let parts=numberparts;const integer=(parts=1<numberparts.length?[String.joinString("",...numberparts.splice(0,numberparts.length-1)),numberparts[numberparts.length-1]]:parts)[0];var mod=integer.length%3,output=0<mod?integer.substring(0,mod):String.empty,mod=integer.substring(mod).match(/.{3}/g);return arg=output+"."+String.join(".",mod)+(1<parts.length?","+parts[1]:"")}case"x":return this.decimalToHexString(arg);case"X":return this.decimalToHexString(arg,!0)}return"number"!=typeof arg&&isNaN(arg)||isNaN(+match)||String.isNullOrWhiteSpace(arg)?arg:String.formatNumber(arg,match)}static decimalToHexString(value,upperCase=!1){const parsed=parseFloat(value),hexNumber=parsed.toString(16);return upperCase?hexNumber.toLocaleUpperCase():hexNumber}static getDisplayDateFromString(input){var splitted=input.split("-");if(splitted.length<=1)return input;let day=splitted[splitted.length-1];input=splitted[splitted.length-2],splitted=splitted[splitted.length-3];return(day=(day=day.split("T")[0]).split(" ")[0])+.${input}.+splitted}static getSortableDateFromString(input){const splitted=input.replace(",","").split(".");if(splitted.length<=1)return input;input=splitted[splitted.length-1].split(" ");let time=String.empty,result=(1<input.length&&(time=input[input.length-1]),splitted[splitted.length-1].split(" ")[0]+-${splitted[splitted.length-2]}-+splitted[splitted.length-3]);return!String.isNullOrWhiteSpace(time)&&1<time.length?result+="T"+time:result+="T00:00:00",result}static formatNumber(input,formatTemplate){var formatTemplate=formatTemplate.length,input=input.toString();return formatTemplate<=input.length?input:(formatTemplate=formatTemplate-input.length,++formatTemplate,new Array(formatTemplate).join("0")+input)}static joinString(delimiter,...args){let temp=String.empty;for(let i=0;i<args.length;i++)if(!("string"==typeof args[i]&&String.isNullOrWhiteSpace(args[i])||"number"!=typeof args[i]&&"string"!=typeof args[i])){var arg=""+args[i];temp+=arg;for(let i2=i+1;i2<args.length;i2++)if(!String.isNullOrWhiteSpace(args[i2])){temp+=delimiter,i=i2-1;break}}return temp}}exports.String=String;class StringBuilder{Values;constructor(value=""){this.Values=[],String.isNullOrWhiteSpace(value)||(this.Values=new Array(value))}toString(){return this.Values.join(String.empty)}ToString(){return this.toString()}append(value){this.Values.push(value)}Append(value){this.append(value)}appendLine(value){this.Values.push(EOL+value)}AppendLine(value){this.appendLine(value)}appendFormat(format,...args){this.Values.push(String.format(format,...args))}AppendFormat(format,...args){this.appendFormat(format,...args)}appendLineFormat(format,...args){this.Values.push(EOL+String.format(format,...args))}AppendLineFormat(format,...args){return this.appendLineFormat(format,...args)}clear(){this.Values=[]}Clear(){this.clear()}}exports.StringBuilder=StringBuilder; npm ERR! code ELIFECYCLE npm ERR! errno 1

I checked the web.config.js and confirmed that the solution mentioned is set there

image

image

How import String module?

Hello,
How is the way I import String module into my TS file?

I have imported in this way into my /src/myLib/ts:

import { String } from "../node_modules/typescript-string-operations/source/source";

Is this correct or I theres a better way?

Thanks

Importing the module creates TS2307 compile errors

I added this to the package.json and added an import { String } from "typescript-string-operations"; to an existing ts file, and it gives the error TS2307 (TS) Cannot find module 'typescript-string-operations' in addition to breaking much of the rest of the module.

Is there some other specific configuration (module type/target/etc) required to use this?

Here is what I had
image

Then I added the import and tried to use the String.Empty;, but as soon as I build it, the rest of the classes in the module cannot be found.
image

This could be something I am not understanding generally about typescript or module loading, but if you can point me in the right direction I would appreciate it.

Improvements

Currently there are no options to pass the string array as argument and get it formatted like below.

string[] args = ['Hello', 'World']
string sayHello = String.Format("{0}, {1}!", args)

Output : Hello, World!

Current output: Hello, World, undefined!

Is this feature will be availble any time soon.

StringBuilder.appendLine

StringBuilder.appendLine puts CRLF before the line, not after. Why would you make this decision? This is contrary to every other package out there.

"n" format specifier does not respect locale

String.Format with "n" specifier does not respect current locale settings.
In our country, there is a thousand separator " ". In your library is hardcoded thousand separator ".".
Please use settings from the current locale.

const formatted: string = String.Format("{0:n}", 10000);
returns "10.000"
whould return "10 000" with cs-CZ locale.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.