Skip to content

Instantly share code, notes, and snippets.

@acomito
Last active October 11, 2019 12:14
Show Gist options
  • Save acomito/7095b82bc3e183fe6a872c7fecd75ebd to your computer and use it in GitHub Desktop.
Save acomito/7095b82bc3e183fe6a872c7fecd75ebd to your computer and use it in GitHub Desktop.
import { typeCheck } from 'type-check';
export default ({ name }) => {
// setup a variable called programName that we'll eventually return
let programName = name;
// if no program exists, return null
if (!name) {
console.log('You need to pass a name');
return null;
}
// if it is not a string,
if (!typeCheck('String', name)) {
console.log('You need to pass a name');
return null;
}
if (typeCheck('Number', name)) {
console.log('This number should be a string, but we can make it a string for you');
programName = name.toString();
}
// setup an array of what values we want to look for. Our goal is to show only the portion of the string AFTER the WHEN_TO_CLEAN values.
const WHEN_TO_CLEAN = ['/', '\\'];
WHEN_TO_CLEAN.forEach(item => {
if (name.includes(item)) {
// if the incoming name string includes one of the When to clean values, run this code
programName = programName.substr(programName.lastIndexOf(item) + 1, programName.length);
}
});
return programName;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment