Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New line fixes #35

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions bin/txms
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const args = parseArgs(process.argv.slice(2));

if (process.stdin.isTTY) {
// If the script is run with a TTY, process the command-line arguments
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename);
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename, '\n');
} else {
// If data is being piped into the script, capture it
let content = '';
Expand All @@ -126,16 +126,16 @@ if (process.stdin.isTTY) {
content = content.trim();

if (!content) {
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename);
run(args.kind, args.value, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename, '');
} else {
run(args.kind, content, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename);
run(args.kind, content, args.output, args.countryCodes, args.phoneNumbers, args.download, args.filename, '');
}
});
}

async function run(kind, value, output, countryCodes, phoneNumbers, download, filename) {
async function run(kind, value, output, countryCodes, phoneNumbers, download, filename, newline) {
if (!value && kind !== 'version') {
process.stderr.write('Value is required\n');
process.stderr.write('Value is required' + newline);
process.exit(1);
}

Expand All @@ -148,44 +148,44 @@ async function run(kind, value, output, countryCodes, phoneNumbers, download, fi
const packageJsonPath = path.join(__dirname, '../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
const version = packageJson.version;
process.stdout.write(version);
process.stdout.write(version + newline);
process.exit(0);
} else if (kind === 'encode' || kind === 'e') {
if (download) {
const filenm = await txms.downloadMessage(value, filename ? filename : undefined, output);
process.stdout.write(`TxMS file was downloaded as "${filenm}".\n`);
process.stdout.write(`TxMS file was downloaded as "${filenm}".${newline}`);
} else {
const encoded = txms.encode(value);
process.stdout.write(encoded);
process.stdout.write(encoded + newline);
}
process.exit(0);
} else if (kind === 'decode' || kind === 'd') {
const decoded = txms.decode(value);
process.stdout.write(decoded);
process.stdout.write(decoded + newline);
process.exit(0);
} else if (kind === 'getendpoint' || kind === 'g') {
const endpoint = txms.getEndpoint(value, countryCodes);
let endpointString = Object.keys(endpoint).map(key => {
const numbers = endpoint[key].join(',');
return `${key}:${numbers}`;
}).join(';');
process.stdout.write(endpointString);
process.stdout.write(endpointString + newline);
process.exit(0);
} else if (kind === 'sms') {
const message = txms.encode(value);
const sms = txms.sms(phoneNumbers ? phoneNumbers.split(',') : true, message);
process.stdout.write(sms);
process.stdout.write(sms + newline);
process.exit(0);
} else if (kind === 'mms') {
const message = txms.encode(value);
const mms = txms.mms(phoneNumbers ? phoneNumbers.split(',') : true, message);
process.stdout.write(mms);
process.stdout.write(mms + newline);
process.exit(0);
} else {
throw new Error('Invalid type specified.');
throw new Error('Invalid type specified.' + newline);
}
} catch (err) {
process.stderr.write(`${err.message}\n`);
process.stderr.write(`${err.message}${newline}`);
process.exit(1);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "txms.js",
"version": "1.2.8",
"version": "1.2.9",
"description": "Transaction messaging service protocol",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down