@yuenu/utils-collection
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "@yuenu/utils-collection", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "utils collection", | ||
@@ -12,3 +12,3 @@ "main": "src/index.js", | ||
"author": "yuenu", | ||
"license": "ISC", | ||
"license": "MIT", | ||
"devDependencies": { | ||
@@ -23,3 +23,6 @@ "jest": "^29.5.0", | ||
}, | ||
"keywords": ["performance", "utils"], | ||
"keywords": [ | ||
"performance", | ||
"utils" | ||
], | ||
"engines": { | ||
@@ -26,0 +29,0 @@ "node": ">=8", |
function getMoneyNumbersFromString(str) { | ||
// make sure the input is a string | ||
if (typeof str !== 'string') { | ||
return ''; | ||
if (typeof str !== "string") { | ||
return ""; | ||
} | ||
// remove all non-digit characters from the string | ||
let digitsOnly = str.replace(/\D/g, ''); | ||
let digitsOnly = str.replace(/\D/g, ""); | ||
// if the first character is 0, remove it | ||
if (digitsOnly.charAt(0) === '0' && digitsOnly.length > 1) { | ||
if (digitsOnly.charAt(0) === "0" && digitsOnly.length > 1) { | ||
digitsOnly = digitsOnly.slice(1); | ||
} | ||
return digitsOnly; | ||
@@ -19,3 +19,3 @@ } | ||
module.exports = { | ||
getMoneyNumbersFromString | ||
} | ||
getMoneyNumbersFromString, | ||
}; |
@@ -0,18 +1,23 @@ | ||
const { getMoneyNumbersFromString } = require("./index"); | ||
import {getMoneyNumbersFromString} from './index' | ||
describe("test function-getMoneyNumbersFromString", () => { | ||
it("Only accpet string type, if not the string type return empty string", () => { | ||
const output = getMoneyNumbersFromString(123123); | ||
expect(output).toEqual(""); | ||
}); | ||
// console.log(getMoneyNumbersFromString('euwqio12391203')) | ||
// console.log(getNumbersFromString('0123781290')) | ||
// console.log(getNumbersFromString('0')) | ||
// console.log(getNumbersFromString('01')) | ||
// console.log(getNumbersFromString('10231')) | ||
it("If input is a 0, the output still 0", () => { | ||
const output = getMoneyNumbersFromString("0"); | ||
expect(output).toEqual("0"); | ||
}); | ||
it("If input's first char is 0, will slice 0", () => { | ||
const output = getMoneyNumbersFromString("0123"); | ||
expect(output).toEqual("123"); | ||
}); | ||
describe('test function-getMoneyNumbersFromString', () => { | ||
it('only accpet string type', () => { | ||
const output = getMoneyNumbersFromString(123123) | ||
expect(output).toEqual('') | ||
}) | ||
}) | ||
it("If input is mix letter(contain number 0~9 , and letter or symbol), the output only has number 0~9", () => { | ||
const output = getMoneyNumbersFromString("218209r82dfdsf789@1"); | ||
expect(output).toEqual("218209827891"); | ||
}); | ||
}); |
2557
59