+58
-78
@@ -1,24 +0,19 @@ | ||
| /*! | ||
| * reflinks <https://github.com/jonschlinkert/reflinks> | ||
| * | ||
| * Copyright (c) 2015-2018, Jon Schlinkert. | ||
| * Released under the MIT License. | ||
| */ | ||
| 'use strict'; | ||
| var ora = require('ora'); | ||
| var utils = require('./utils'); | ||
| const ora = require('ora'); | ||
| const util = require('util'); | ||
| const utils = require('./utils'); | ||
| /** | ||
| * Generate a list of reflinks for a `glob` of files, | ||
| * relative to the specified `dest` file. | ||
| * Generate a list of reflinks for a `glob` of files, relative | ||
| * to the specified `dest` file. | ||
| * | ||
| * @param {String|Array} `glob` Glob patterns to pass to [matched][]. | ||
| * @param {String} `dest` | ||
| * @param {String} `opts` Options to pass to [matched][]. | ||
| * @param {String|Array} `glob` Glob patterns to pass to [matched][]. | ||
| * @param {String} `dest` | ||
| * @param {String} `opts` Options to pass to [matched][]. | ||
| * @param {Function} `callback` (optional) Returns a promise if a callback is not passed. | ||
| * @return {String} List of reflinks. | ||
| */ | ||
| module.exports = function reflinks(names, options, cb) { | ||
| module.exports = async(name, options, cb) => { | ||
| if (typeof options === 'function') { | ||
@@ -29,78 +24,63 @@ cb = options; | ||
| var dates = new utils.Dates('reflinks-dates-cache'); | ||
| var store = new utils.Store('reflinks-names-cache'); | ||
| const promise = reflinks(name, options); | ||
| if (typeof cb === 'function') { | ||
| promise.then(res => cb(null, res)).catch(cb); | ||
| return; | ||
| } | ||
| var opts = utils.extend({}, options); | ||
| if (opts.reflinksCache === false) { | ||
| opts.cache = false; | ||
| return promise; | ||
| }; | ||
| async function reflinks(names, options = {}) { | ||
| const dates = new utils.Dates('reflinks-dates-cache'); | ||
| const store = new utils.Store('reflinks-names-cache'); | ||
| if (options.reflinksCache === false) { | ||
| options.cache = false; | ||
| } | ||
| if (opts.clearCache === true) { | ||
| dates.del({force: true}); | ||
| store.del({force: true}); | ||
| if (options.clearCache === true) { | ||
| dates.clear(); | ||
| store.clear(); | ||
| } | ||
| var color = opts.color || 'green'; | ||
| var start = opts.starting || 'creating reference links from npm data'; | ||
| var stop = opts.finished || 'created reference links from npm data'; | ||
| var timespan = opts.timespan || '1 week ago'; | ||
| const color = options.color || 'green'; | ||
| const start = options.starting || 'creating reference links from npm data'; | ||
| const stop = options.finished || 'created reference links from npm data'; | ||
| const timespan = options.timespan || '1 week ago'; | ||
| const spinner = ora(start).start(); | ||
| const pkgs = []; | ||
| var spinner = ora(start).start(); | ||
| var pkgs = []; | ||
| for (const name of [].concat(names || [])) { | ||
| if (utils.isCached(dates, name, timespan) && options.cache !== false) { | ||
| utils.each(utils.arrayify(names), function(name, next) { | ||
| if (utils.isCached(dates, name, timespan) && opts.cache !== false) { | ||
| var val = store.get(name); | ||
| if (val) { | ||
| pkgs.push(val); | ||
| next(); | ||
| return; | ||
| let cached = store.get(name); | ||
| if (cached) { | ||
| pkgs.push(cached); | ||
| continue; | ||
| } | ||
| } | ||
| utils.pkg(name, function(err, pkg) { | ||
| if (err) { | ||
| if (err.message === 'document not found') { | ||
| dates.set(name, {}); | ||
| next(); | ||
| return; | ||
| } | ||
| next(err); | ||
| return; | ||
| } | ||
| try { | ||
| const pkg = await utils.pkg(name); | ||
| dates.set(name, pkg); | ||
| store.set(name, pkg); | ||
| pkgs.push(pkg); | ||
| next(); | ||
| }); | ||
| }, function(err) { | ||
| if (err) { | ||
| cb(err); | ||
| return; | ||
| } | ||
| spinner.color = color; | ||
| spinner.text = stop; | ||
| spinner.stop(); | ||
| if (err) { | ||
| // let the implementor decide what to do when a package doesn't exist | ||
| cb(err, pkgs); | ||
| return; | ||
| } | ||
| try { | ||
| var res = linkify(pkgs, opts); | ||
| } catch (err) { | ||
| cb(err); | ||
| return; | ||
| if (err.message === 'document not found') { | ||
| dates.set(name, {}); | ||
| continue; | ||
| } | ||
| throw err; | ||
| } | ||
| } | ||
| res.links.sort(function(a, b) { | ||
| return a.localeCompare(b); | ||
| }); | ||
| spinner.color = color; | ||
| spinner.text = stop; | ||
| spinner.stop(); | ||
| cb(null, res); | ||
| }); | ||
| }; | ||
| const res = linkify(pkgs, options); | ||
| res.links.sort((a, b) => a.localeCompare(b)); | ||
| return res; | ||
| } | ||
@@ -112,4 +92,4 @@ /** | ||
| function linkify(arr, options) { | ||
| var obj = {links: [], cache: {}, pkgs: {}}; | ||
| return utils.arrayify(arr).reduce(function(acc, pkg) { | ||
| const obj = { links: [], cache: {}, pkgs: {} }; | ||
| return [].concat(arr || []).reduce(function(acc, pkg) { | ||
| if (!pkg.name) return acc; | ||
@@ -122,3 +102,3 @@ | ||
| var link = typeof options.template !== 'function' | ||
| const link = typeof options.template !== 'function' | ||
| ? utils.reference(pkg.name, pkg.homepage) | ||
@@ -125,0 +105,0 @@ : options.template(pkg, options); |
+2
-4
| { | ||
| "name": "reflinks", | ||
| "description": "Generate (relative) reference links for a glob of markdown files, allowing you to more easily create references from one file to another.", | ||
| "version": "0.3.6", | ||
| "version": "1.0.0", | ||
| "homepage": "https://github.com/jonschlinkert/reflinks", | ||
@@ -24,6 +24,4 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
| "dependencies": { | ||
| "async-each": "^1.0.1", | ||
| "data-store": "^3.0.0", | ||
| "date-store": "^0.1.2", | ||
| "extend-shallow": "^3.0.2", | ||
| "get-pkg": "^1.0.0", | ||
@@ -36,3 +34,3 @@ "markdown-reference": "^0.1.0", | ||
| "gulp-format-md": "^1.0.0", | ||
| "mocha": "^3.5.3" | ||
| "mocha": "^5.2.0" | ||
| }, | ||
@@ -39,0 +37,0 @@ "keywords": [ |
+15
-5
@@ -22,7 +22,17 @@ # reflinks [](https://www.npmjs.com/package/reflinks) [](https://npmjs.org/package/reflinks) [](https://npmjs.org/package/reflinks) [](https://travis-ci.org/jonschlinkert/reflinks) | ||
| ```js | ||
| var reflinks = require('reflinks'); | ||
| const reflinks = require('reflinks'); | ||
| reflinks(['base', 'verb', 'generate'], function(err, links) { | ||
| if (err) return console.log(err); | ||
| console.log(links); | ||
| // returns a promise by default | ||
| reflinks(['micromatch', 'generate']) | ||
| .then(res => { | ||
| console.log(res.links); | ||
| // results in: | ||
| // [ '[generate]: https://github.com/generate/generate', | ||
| // '[micromatch]: https://github.com/micromatch/micromatch' ] | ||
| }) | ||
| .catch(console.error); | ||
| // or takes a callback | ||
| reflinks(['base', 'verb', 'generate'], function(err, res) { | ||
| console.log(res.links); | ||
| // results in: | ||
@@ -113,3 +123,3 @@ // [ '[generate]: https://github.com/generate/generate', | ||
| | --- | --- | | ||
| | 50 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| | 53 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| | 4 | [stefanwalther](https://github.com/stefanwalther) | | ||
@@ -116,0 +126,0 @@ | 2 | [charlike-old](https://github.com/charlike-old) | |
+0
-6
| 'use strict'; | ||
| define(exports, 'each', () => require('async-each')); | ||
| define(exports, 'pkg', () => require('get-pkg')); | ||
| define(exports, 'extend', () => require('extend-shallow')); | ||
| define(exports, 'homepage', () => require('pkg-homepage')); | ||
@@ -15,8 +13,4 @@ define(exports, 'reference', () => require('markdown-reference')); | ||
| exports.arrayify = function(val) { | ||
| return val ? (Array.isArray(val) ? val : [val]) : []; | ||
| }; | ||
| exports.isCached = function(store, name, timespan) { | ||
| return store.has(name) && store.lastSaved(name).lessThan(timespan); | ||
| }; |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6
-25%0
-100%141
7.63%10387
-1.93%105
-17.97%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed