How to use zero-lang - 10 common examples

To help you get started, we’ve selected a few zero-lang 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 leungwensen / svg-icon / lib / separator / font-awesome.js View on Github external
co(function *() {
      // get font data from `fonts/fontawesome-webfont.svg`
      const fontPath = path.resolve(source, './fonts/fontawesome-webfont.svg');
      const svgContent = yield readFile(fontPath, 'utf8');
      const parsedSvg = yield parseXml(svgContent);
      const glyphs = parsedSvg.svg.defs[0].font[0].glyph;
      const fontData = {};
      lang.each(glyphs, glyph => {
        fontData[glyph.$.unicode.charCodeAt(0)] = glyph.$;
      });
      //console.log(fontData);

      // get font list from `./less/variables.less`
      const lessPath = path.resolve(source, './less/variables.less');
      const lessContent = yield readFile(lessPath, 'utf8');
      const iconList = [];
      const matchedHexes = [];
      lang.each(lessContent.split(/\n/), line => {
        if (!line) return;

        const match = /@fa-var-([^:]+):\s*"\\([0-9a-f]+)";/.exec(line);
        if (match) {
          const unicodeHex = match[2];
          const unicodeDec = parseInt(unicodeHex, 16);
github leungwensen / svg-icon / lib / separator / ant-design.js View on Github external
co(function *() {
      // get font data
      const themeLessPath = path.resolve(source, './components/style/themes/default.less');
      const themeLessContent = yield readFile(themeLessPath, 'utf8');
      const iconUrl = themeLessContent.match(/@icon\-url\s*:\s*"(\S+)"/)[1];
      const svgResponse = yield request(`${iconUrl}.svg`);
      const svgContent = svgResponse.body;
      const parsedSvg = yield parseXml(svgContent);
      const glyphs = parsedSvg.svg.defs[0].font[0].glyph;
      const fontData = {};
      lang.each(glyphs, glyph => {
        if (glyph.$.unicode) {
          fontData[glyph.$.unicode.charCodeAt(0)] = glyph.$;
        }
      });
      //console.log(fontData);

      // get font list from `./components/style/core/iconfont.less`
      const lessPath = path.resolve(source, './components/style/core/iconfont.less');
      const lessContent = yield readFile(lessPath, 'utf8');
      const iconList = [];
      lang.each(lessContent.split(/\n/), line => {
        if (!line) return;

        const match = /.@\{iconfont-css-prefix\}-([^:]+):before\s*\{content:"\\([0-9a-f]+)";\}/.exec(line);
        if (match) {
          const unicodeHex = match[2];
github leungwensen / svg-icon / lib / separator / font-awesome.js View on Github external
const fontPath = path.resolve(source, './fonts/fontawesome-webfont.svg');
      const svgContent = yield readFile(fontPath, 'utf8');
      const parsedSvg = yield parseXml(svgContent);
      const glyphs = parsedSvg.svg.defs[0].font[0].glyph;
      const fontData = {};
      lang.each(glyphs, glyph => {
        fontData[glyph.$.unicode.charCodeAt(0)] = glyph.$;
      });
      //console.log(fontData);

      // get font list from `./less/variables.less`
      const lessPath = path.resolve(source, './less/variables.less');
      const lessContent = yield readFile(lessPath, 'utf8');
      const iconList = [];
      const matchedHexes = [];
      lang.each(lessContent.split(/\n/), line => {
        if (!line) return;

        const match = /@fa-var-([^:]+):\s*"\\([0-9a-f]+)";/.exec(line);
        if (match) {
          const unicodeHex = match[2];
          const unicodeDec = parseInt(unicodeHex, 16);
          if (!lang.contains(matchedHexes, unicodeHex)) {
            matchedHexes.push(unicodeHex);
            iconList.push(lang.extend({
                id: match[1],
                unicodeDec,
                unicodeHex,
              }, fontData[unicodeDec])
            );
          }
        } else {
github leungwensen / d2recharts / lib / source / from-csv.js View on Github external
function parse(str, delimiter) {
  delimiter = delimiter || ',';
  const result = [];
  const csvArray = str.split('\n');

  const firstRow = csvArray.shift();
  const columnKeys = firstRow.split(delimiter);

  lang.each(csvArray, (row) => {
    const csvRowArray = row.split(delimiter);
    const jsonRow = {};
    if (csvRowArray.length === columnKeys.length) {
      lang.each(csvRowArray, (part, index) => {
        // fixing numeric values
        jsonRow[columnKeys[index]] = isNaN(part) ? part : parseFloat(part, 10);
      });
      result.push(jsonRow);
    }
  });
  return result;
}
github leungwensen / d2recharts / lib / source / from-csv.js View on Github external
lang.each(csvArray, (row) => {
    const csvRowArray = row.split(delimiter);
    const jsonRow = {};
    if (csvRowArray.length === columnKeys.length) {
      lang.each(csvRowArray, (part, index) => {
        // fixing numeric values
        jsonRow[columnKeys[index]] = isNaN(part) ? part : parseFloat(part, 10);
      });
      result.push(jsonRow);
    }
  });
  return result;
github leungwensen / svg-icon / bin / extract / font-awesome.js View on Github external
request(URL_ICON_LESS, (iconLessErr, iconLessRes, iconLessBody) => {
    if (!iconLessErr && iconLessRes.statusCode === 200) {
      // icon list
      const iconNameByDec = {};
      lang.each(iconLessBody.split(/\n/), (line) => {
        line = lang.trim(line);
        if (!line) {
          return;
        }
        // icon font pattern
        // @fa-var-500px: "\f26e";
        const match = /@fa-var-([^\s:]+)\s*:\s*"\\([0-9a-f]+)"\s*;/.exec(line);
        if (match) {
          const name = match[1];
          const unicodeHex = match[2];
          const unicodeDec = parseInt(unicodeHex, 16);
          iconNameByDec[unicodeDec] = name;
        }
      });

      // svg fonts file
github leungwensen / svg-icon / bin / extract / bootstrap.js View on Github external
request(URL_ICON_LESS, (iconLessErr, iconLessRes, iconLessBody) => {
    if (!iconLessErr && iconLessRes.statusCode === 200) {
      // icon list
      const iconNameByDec = {};
      lang.each(iconLessBody.split(/\n/), (line) => {
        line = lang.trim(line);
        if (!line) {
          return;
        }
        // icon font pattern
        // .glyphicon-asterisk { &:before { content: "\002a"; } }
        const match = /\.glyphicon-([^{\s]+)\s*\{\s*&:before\s*\{\s*content:\s*"\\([0-9a-f]+)"\s*;/.exec(line);
        if (match) {
          const name = match[1];
          const unicodeHex = match[2];
          const unicodeDec = parseInt(unicodeHex, 16);
          iconNameByDec[unicodeDec] = name;
        }
      });

      // svg fonts file
github leungwensen / svg-icon / bin / generate-demo-data.js View on Github external
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const lang = require('zero-lang');
const mapStream = require('map-stream');
const path = require('path');
const vfs = require('vinyl-fs');
const iconsMeta = require('../lib/const/icons-meta');

const icons = {};

lang.each(iconsMeta, meta => {
  icons[meta.prefix.replace(/\-$/, '')] = meta;
});

icons.zero = {
  name: 'zero',
  prefix: 'zero-'
};

function reduceIcons(file, cb) { // removing prefix in filename
  const arr = file.path.split(path.sep);
  const len = arr.length;
  const type = arr[len - 2];
  const name = arr[len - 1].replace(/\.svg$/, '');
  icons[type] = icons[type] || {};
  icons[type].icons = icons[type].icons || [];
  icons[type].icons.push(name);
github leungwensen / svg-icon / lib / filter-icons.js View on Github external
module.exports = (icons) => {
  const resultIcons = [];

  lang.each(icons, (icon) => {
    if (icon.name && icon.body) { // removing invalid ones
      delete icon.unicode;
      icon.name = fixName(icon.name); // fixing invalid names
      resultIcons.push(icon);
    }
  });
  return resultIcons;
};
github leungwensen / svg-icon / bin / extract / font-awesome.js View on Github external
extractSvgFonts(svgFontsBody, {}, (icons) => {
            lang.each(icons, (icon) => {
              if (icon.unicode) {
                const dec = icon.unicode.charCodeAt(0);
                icon.name = iconNameByDec[dec] || '';
              }
            });
            fs.writeFile(
              options.output,
              JSON.stringify(filterIcons(icons), null, '\t'),
              'utf8',
              (err) => {
                if (err) {
                  console.error(err);
                }
              }
            );
          });

zero-lang

zero-lang ====================

MIT
Latest version published 8 years ago

Package Health Score

40 / 100
Full package analysis

Popular zero-lang functions