How to use tosource - 6 common examples

To help you get started, we’ve selected a few tosource examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rollup / plugins / packages / yaml / src / index.js View on Github external
transform(content, id) {
      if (!ext.test(id)) return null;
      if (!filter(id)) return null;

      let data = loadMethod(content);

      if (typeof options.transform === 'function') {
        const result = options.transform(data);
        // eslint-disable-next-line no-undefined
        if (result !== undefined) {
          data = result;
        }
      }

      const keys = Object.keys(data).filter((key) => key === makeLegalIdentifier(key));
      const code = `var data = ${toSource(data)};\n\n`;
      const exports = ['export default data;']
        .concat(keys.map((key) => `export var ${key} = data.${key};`))
        .join('\n');

      return {
        code: code + exports,
        map: { mappings: '' }
      };
    }
  };
github rollup / rollup-plugin-yaml / src / index.js View on Github external
transform (yaml, id) {
			if (!ext.test(id)) return null;
			if (!filter(id)) return null;

			let data = YAML.load(yaml);

			if (typeof options.transform === 'function') {
				const result = options.transform(data);
				if (result !== undefined) data = result;
			}

			const keys = Object.keys(data).filter(
				key => key === makeLegalIdentifier(key)
			);

			const code = `var data = ${toSource(data)};\n\n`;

			const exports = ['export default data;']
				.concat(keys.map(key => `export var ${key} = data.${key};`))
				.join('\n');

			return {
				code: code + exports,
				map: { mappings: '' }
			};
		}
	};
github rollup / plugins / packages / dsv / src / index.js View on Github external
transform(code, id) {
      if (!filter(id)) return null;

      const ext = extname(id);
      if (!(ext in parsers)) return null;

      let rows = parsers[ext](code);

      if (options.processRow) {
        rows = rows.map((row) => options.processRow(row, id) || row);
      }

      return {
        code: `export default ${toSource(rows)};`,
        map: { mappings: '' }
      };
    }
  };
github blueberryapps / react-bluekit / src / createBlueKit.js View on Github external
function objectToString(object) {
  return toSource(object || {}, null, 0)
}
github blueberryapps / react-bluekit / example_app / lib / createGenerator.js View on Github external
function objectToString(object) {
  return toSource(object || {}, null, 0)
}
github paularmstrong / build-tracker / src / app / src / server / index.tsx View on Github external
const css = ReactDOMServer.renderToStaticMarkup(getStyleElement({ nonce }));

  return `



<title>${name === 'Build Tracker' ? name : `${name} : Build Tracker`}</title>

<style nonce="${nonce}">html,body{height:100%;overflow-y:hidden;}#root{display:flex;height:100%;}</style>
${css}

<div id="root">${html}</div>
<div id="menuPortal"></div>
<div id="tooltipPortal"></div>
<div id="snackbarPortal"></div>

${scripts.map(script =&gt; ``).join('')}
  `;
}

tosource

toSource converts JavaScript objects back to source

Zlib
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular tosource functions