A ponyfill for the ES6
String.raw()
npm install string-raw --save
It behaves just as String.raw.
const stringRaw = require('string-raw');
const arg1 = 'foo';
const arg2 = 'bar';
stringRaw``; // ""
stringRaw`hoge`; // "hoge"
stringRaw`hoge${arg1}`; // "hogefoo"
stringRaw`hoge${arg1}fuga${arg2}`; // hogefoofugabar
stringRaw`hoge${arg1}fuga${arg2}piyo`; // hogefoofugabarpiyo
stringRaw({ raw: [] }, arg1, arg2); // ""
stringRaw({ raw: ['hoge'] }, arg1, arg2); // "hoge"
stringRaw({ raw: ['hoge', 'fuga'] }, arg1, arg2); // "hogefoofuga"
stringRaw({ raw: ['hoge', 'fuga', 'piyo'] }, arg1, arg2); // "hogefoofugabarpiyo"
stringRaw({ raw: {} }, arg1, arg2); // ""
stringRaw({ raw: true }, arg1, arg2); // ""
stringRaw(); // TypeError: Cannot convert undefined or null to object
stringRaw(''); // TypeError: Cannot convert undefined or null to object
stringRaw(null); // TypeError: Cannot convert undefined or null to object
stringRaw({ raw: null }); // TypeError: Cannot convert undefined or null to object
node
> require('string-raw')('error')
# TypeError: Cannot convert undefined or null to object
# at f (/path/to/string-raw/lib/index.js:1:59798)
published code is compressed and the source map is provided. sourcemap isn't supported on NodeJS(current v5.10.0). but this resolved in the node-source-map-support.
npm install source-map-support --save-dev
import 'source-map-support/register';
or...
$ mocha --require source-map-support/register
you can check the line number before compilation.
node
> require('source-map-support/register');
> require('string-raw')('error');
# TypeError: Cannot convert undefined or null to object
# at f (/Users/59naga/Downloads/string-raw/src/index.js:17:11)
Requirement global
- NodeJS v5.10.0
- Npm v3.8.3
git clone https://github.com/59naga/string-raw
cd string-raw
npm install
npm test