How to use the parse-numeric-range.parse function in parse-numeric-range

To help you get started, we’ve selected a few parse-numeric-range 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 wobscale / EuIrcBot / modules / scrollback / index.js View on Github external
function parseLines(str, idx) {
  let ret = '';

  while (idx < str.length && /[0-9\-.,]/.test(str[idx])) {
    ret += str[idx];
    idx++;
  }

  if (str[idx - 1] === ',') { // Put back trailing commas
    idx--;
    ret = ret.slice(0, -1);
  }

  const range = rangeParser.parse(ret);
  if (range === undefined || range.length == 0) {
    return { result: range, index: idx, error: `Could not parse ${ret}` };
  }
  if (_.every(range, num => num > 0)) {
    return { result: range, index: idx };
  }

  return { result: range, index: idx, error: 'Negative line index' };
}
github cyralinc / approzium / docs / src / theme / CodeBlock / index.js View on Github external
// styles seen using this current approach but that's probably ok. Fixing
  // the flash will require changing the theming approach and is not worth it
  // at this point.
  useEffect(() => {
    setMounted(true);
  }, []);

  const button = useRef(null);
  let highlightLines = [];
  let codeBlockTitle = '';

  const prismTheme = usePrismTheme();

  if (metastring && highlightLinesRangeRegex.test(metastring)) {
    const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
    highlightLines = rangeParser
      .parse(highlightLinesRange)
      .filter((n) => n > 0);
  }

  if (metastring && codeBlockTitleRegex.test(metastring)) {
    codeBlockTitle = metastring
      .match(codeBlockTitleRegex)[0]
      .split('title=')[1]
      .replace(/"+/g, '');
  }

  let language =
    languageClassName && languageClassName.replace(/language-/, '');

  if (!language && prism.defaultLanguage) {
    language = prism.defaultLanguage;
github webtorrent / webtorrent / lib / torrent.js View on Github external
},
        files: this.files.map(file => ({
          path: path.join(this.path, file.path),
          length: file.length,
          offset: file.offset
        })),
        length: this.length,
        name: this.infoHash
      })
    )

    this.files = this.files.map(file => new File(this, file))

    // Select only specified files (BEP53) http://www.bittorrent.org/beps/bep_0053.html
    if (this.so) {
      const selectOnlyFiles = parseRange.parse(this.so)

      this.files.forEach((v, i) => {
        if (selectOnlyFiles.includes(i)) this.files[i].select(true)
      })
    } else {
      // start off selecting the entire torrent with low priority
      if (this.pieces.length !== 0) {
        this.select(0, this.pieces.length - 1, false)
      }
    }

    this._hashes = this.pieces

    this.pieces = this.pieces.map((hash, i) => {
      const pieceLength = (i === this.pieces.length - 1)
        ? this.lastPieceLength
github checktheroads / hyperglass / docs / src / theme / CodeBlock / index.js View on Github external
break;

          case "highlight-end":
            range += `${blockStart}-${lineNumber - 1},`;
            break;

          default:
            break;
        }
        lines.splice(index, 1);
      } else {
        // lines without directives are unchanged
        index += 1;
      }
    }
    highlightLines = rangeParser.parse(range);
    code = lines.join("\n");
  }

  const handleCopyCode = () => {
    window.getSelection().empty();
    setShowCopied(true);

    setTimeout(() => setShowCopied(false), 2000);
  };

  return (
github cyralinc / approzium / docs / src / theme / CodeBlock / index.js View on Github external
break;

          case 'highlight-end':
            range += `${blockStart}-${lineNumber - 1},`;
            break;

          default:
            break;
        }
        lines.splice(index, 1);
      } else {
        // lines without directives are unchanged
        index += 1;
      }
    }
    highlightLines = rangeParser.parse(range);
    code = lines.join('\n');
  }

  const handleCopyCode = () => {
    copy(code);
    setShowCopied(true);

    setTimeout(() => setShowCopied(false), 2000);
  };

  return (
github skidding / react-testing-examples / ui / components / File / shared.js View on Github external
function getHighlightLines(code) {
  const res = code.match(/highlight\{(.+?)\}/);

  return res ? rangeParser.parse(res[1]) : [];
}
github panjf2000 / gnet / src / theme / CodeBlock / index.js View on Github external
setMounted(true);
  }, []);

  const target = useRef(null);
  const button = useRef(null);
  let highlightLines = [];
  let codeBlockTitle = '';

  const {isDarkTheme} = useThemeContext();
  const lightModeTheme = prism.theme || defaultTheme;
  const darkModeTheme = prism.darkTheme || lightModeTheme;
  const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;

  if (metastring && highlightLinesRangeRegex.test(metastring)) {
    const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
    highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
  }

  if (metastring && codeBlockTitleRegex.test(metastring)) {
    codeBlockTitle = metastring
      .match(codeBlockTitleRegex)[0]
      .split('title=')[1]
      .replace(/"+/g, '');
  }

  useEffect(() => {
    let clipboard;

    if (button.current) {
      clipboard = new Clipboard(button.current, {
        target: () => target.current,
      });
github VNG-Realisatie / nlx / docs / website / src / theme / CodeBlock / index.js View on Github external
export default ({children, className: languageClassName, metastring}) => {
  const {
    siteConfig: {
      themeConfig: {prism = {}},
    },
  } = useDocusaurusContext();
  const [showCopied, setShowCopied] = useState(false);
  const target = useRef(null);
  const button = useRef(null);
  let highlightLines = [];

  if (metastring && highlightLinesRangeRegex.test(metastring)) {
    const highlightLinesRange = metastring.match(highlightLinesRangeRegex)[1];
    highlightLines = rangeParser.parse(highlightLinesRange).filter(n => n > 0);
  }

  useEffect(() => {
    let clipboard;

    if (button.current) {
      clipboard = new Clipboard(button.current, {
        target: () => target.current,
      });
    }

    return () => {
      if (clipboard) {
        clipboard.destroy();
      }
    };
github j0lv3r4 / jolvera.dev / mdx-prism / index.js View on Github external
options.forEach(option => {
      option = option.slice(0, -1);
      if (rangeParser.parse(option).length > 0) {
        highlightLines = rangeParser.parse(option).filter(n => n > 0);
      }
    });

parse-numeric-range

Takes a string, such as "1,2,3-10,5-8" and turns it into an array of numbers

ISC
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular parse-numeric-range functions