GithubHelp home page GithubHelp logo

ff-url-finder's Introduction

ff-url-finder

Экспортирует класс URLFinder.

Конструктор: new URLFinder(tlDomains, localDomains), где tlDomains — массив доменов 1-го уровня, которые должны распознаваться без явного указания протокола, localDomains — массив доменов, ссылки в которых считаются локальными.

Поле: withHashTags = false — нужно ли определять в тексте хэш-теги (по умолчанию false). Синтаксис хэш-тегов см. в файле hashtag-syntax.md.

Поле: withArrows = false — нужно ли определять в тексте стрелки-ссылки (^^^ или ↑↑↑).

Метод: parse(text) — разбивает строку текста на список блоков следующих типов:

{type: "text", text: "aa "} // простой текст
{type: "link", text: "google.com", url: "http://google.com/"} // внешняя ссылка
{type: "atLink", text: "@alice", username: "alice"} // @-ссылка с username
{type: "localLink", text: "freefeed.net/abc", uri: "/abc"} // локальная ссылка (в одном из доменов localDomains)
{type: "email", text: "[email protected]", address: "[email protected]"} // адрес e-mail
{type: "hashTag", text: "#3pm", hashTag: "3pm"} // хэш-тег
{type: "arrow", text: "^^^", count: 3} // стрелка-ссылка

Везде: type — тип блока, text — текст, который должен показываться пользователю (текст внутри тега A для ссылок). Остальные поля типо-специфичны.

Статический метод URLFinder.shorten(url, max_length) — возвращает url, укороченный до длины не большей max_length (без учёта протокола).

Фичи

  • Понимает ссылки без явно указанного протокола (для заданного набора TLD);
  • В тексте для пользователя делает urldecode, а также преобразует IDN к человекопонятному виду;
  • Правильно обрабатывает концевые скобки в URL;
  • Распознаёт стрелки-ссылки, при этом знает, что такое 10^6 или (=^・^=).

ff-url-finder's People

Contributors

clbn avatar davidmz avatar thebits avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.