inversify string mapper utility
npm install
npm run build
npm test
npm run test:coverage
npm run test:mutation
npm run format
npm install inversify-string-mapper
Load the module.
...
import { StringMapperModule } from "inversify-string-mapper";
...
export const container = (): Container => {
const container = new Container();
container.load(new StringMapperModule());
return container;
};
Inject the interface by type.
...
import { STRING_MAPPER_TYPE, StringMapperInterface } from "inversify-string-mapper";
...
@inject(STRING_MAPPER_TYPE.StringMapper)
private readonly stringMapper: StringMapperInterface
Use the mapper.
...
stringMapper.mapper('value'); // return 'value'
stringMapper.mapper(null); // return ''
stringMapper.mapper(null, 'default'); // return 'default'
stringMapper.mapper(' value '); // return 'value'
stringMapper.mapper(5); // return '5'
...